【问题标题】:I'm getting an error in plt.imshow while classifying with Tensorflow使用 Tensorflow 进行分类时,我在 plt.imshow 中遇到错误
【发布时间】:2022-06-16 21:52:49
【问题描述】:

我正在尝试使用 tensorflow 进行分类。我收到此错误

enter image description here

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。
  • 错误的最后一行说你有 28 张图片。但是,您正在尝试使用以下行获取 30 张图像:for n in range(30)。

标签: python tensorflow keras


【解决方案1】:

使用下面的代码不会产生错误

plt.figure(figsize=(10,9))
plt.subplots_adjust(hspace=0.5)
for n in range(30):
  plt.subplot(5,6,1+n)
  plt.imshow(test_images[n])
  if np.argmax(predictions[n]) == test_labels[n]:
    plt.title(class_names[np.argmax(predictions[n])],color='green')
  else:
    plt.title(class_names[np.argmax(predictions[n])],color='red')

以上代码的输出:

这里我使用了 test_images,通过将 test_images 替换为验证图像将满足您的要求。

更多详情请参考此gist

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-14
    • 2021-11-10
    • 2016-08-18
    • 1970-01-01
    • 2021-09-01
    • 2021-06-23
    • 1970-01-01
    • 2019-03-01
    相关资源
    最近更新 更多