【问题标题】:Displaying an Image with Matplotlib in deeplearning在深度学习中使用 Matplotlib 显示图像
【发布时间】:2022-09-24 20:45:21
【问题描述】:

运行这段代码:

#loading test images
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
test_path,image_size=(img_height,img_width), label_mode=\'int\', 
batch_size=batch_size)
                                                       
import matplotlib.pyplot as plt

plt.figure(figsize=(12,12))
for img ,label in val_ds.take(1):
    for i in range(12):
        ax = plt.subplot(4,3,i + 1)
        plt.imshow(img[i].numpy().astype(\'uint8\'))
        plt.title(class_name[label[i]])
        plt.axis(\'off\')

我收到了这个错误:

NotFoundError:NewRandomAccessFile 无法创建/打开:D:\\Machine Learning\\DPL\\使用 TensorFlow 进行计算机视觉深度学习 2[TutsNode.com] - 使用 TensorFlow 进行计算机视觉深度学习 2\\3。卷积神经网络\\15.1 covid19\\covid19\\test\\Covid\\auntminnie-a-2020_01_28_23_51_6665_2020_01_28_Vietnam_coronavirus.jpeg : 该系统找不到指定的路径。 ;没有这个过程
[[{{node ReadFile}}]] [Op:IteratorGetNext]

有什么帮助吗??

    标签: python tensorflow keras deep-learning


    【解决方案1】:

    根据官方文档

    image_dataset_from_directory 函数:

    tf.keras.preprocessing.image_dataset_from_directory(
    directory,
    labels="inferred",
    label_mode="int",
    class_names=None,
    color_mode="rgb",
    batch_size=32,
    image_size=(256, 256),
    shuffle=True,
    seed=None,
    validation_split=None,
    subset=None,
    interpolation="bilinear",
    follow_links=False,
    crop_to_aspect_ratio=False,
    **kwargs
    )
    

    没有像 test_path 这样的参数,但是您在代码中提到了这一点。

    要加载图像,您必须使用此功能:

    tf.keras.preprocessing.image.load_img(
    path, grayscale=False, color_mode="rgb", target_size=None, 
    interpolation="nearest"
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-19
      • 2019-12-30
      • 2021-06-22
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 2020-02-11
      • 2021-12-06
      相关资源
      最近更新 更多