在深度学习中显示带有matplotlib的图像

发布于 2025-02-11 11:03:19 字数 917 浏览 2 评论 0原文

运行此代码:

#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 学习\ dpl \ tensorflow的计算机视觉深度学习 2 [tutsnode.com] - 用张量的深度学习计算机视觉 2 \ 3。卷积神经网络\ 15.1 covid19 \ covid19 \ test \ covid \ auntminnie-a-2020_01_28_28_23_23_51_6665_2020_01_28_vietnam_coronavirus.jpeg :该系统找不到指定的路径。 ;没有这样的过程
[[{{node readfile}}]] [op:iteratorGetNext]

任何帮助?

Running this piece of code:

#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')

I got this error :

NotFoundError: NewRandomAccessFile failed to Create/Open: D:\Machine
Learning\DPL\Deep Learning for Computer Vision with TensorFlow
2[TutsNode.com] - Deep Learning for Computer Vision with TensorFlow
2\3. Convolutional Neural Networks\15.1
covid19\covid19\test\Covid\auntminnie-a-2020_01_28_23_51_6665_2020_01_28_Vietnam_coronavirus.jpeg
: The system cannot find the path specified. ; No such process
[[{{node ReadFile}}]] [Op:IteratorGetNext]

Any help ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

油饼 2025-02-18 11:03:19

根据官方文档的

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"
)

As per official documentation

image_dataset_from_directory function:

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
)

there is no argument like test_path but you mention this in your code.

And for loading image you have to use this function:

tf.keras.preprocessing.image.load_img(
path, grayscale=False, color_mode="rgb", target_size=None, 
interpolation="nearest"
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文