在pytorch上绘制CIFAR10数据集类别的频率

问题描述

我想在图表上可视化cifar10数据集的每个类的图像数据数量,我尝试在pytorch上实现此功能,但无法获得令人满意的结果。 谁能帮我在pytorch上绘制CIFAR10数据集类的频率。

这是我尝试过的一种实现方式,但是在将标签与类索引进行比较时,我总是遇到错误,并且plot函数似乎运行得很好

def classes_freq():
    for images,labels in trainloader:
          #print(labels.shape)
      
          images = images.to(device)
          labels = labels.to(device)
          count = [0]*10
          for i,e in enumerate(classes):
            if (labels.item() == i):
              count[i]+=1
    return count

classes_freq()

import matplotlib.pyplot as plt

def plot(y_units):

  x_units = ['plane','car','bird','cat','deer','dog','frog','horse','ship','truck']

  plt.bar(x_units,y_units,width=0.8,color=['red','blue'])

  plt.xlabel('x - axis')
  plt.ylabel('y - axis')
  plt.title('classes frequency')

  plt.show()

#plot([10,20,23,50,60,70,80,90,10,45])

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...