我有以下代码:
import tensorflow as tf
from tensorflow.keras import models, layers
import matplotlib.pyplot as plt
IMAGE_SIZE = 256
BATCH_SIZE = 32
dataset = tf.keras.preprocessing.image_dataset_from_directory(
"Plantvillage",
shuffle= True,
image_size = (IMAGE_SIZE,IMAGE_SIZE),
batch_size = BATCH_SIZE
)
class_names = dataset.class_names
class_names我搞错了:
1 class_names = dataset.class_names 2 class_names "NameError: name 'dataset' is not defined "发布于 2022-10-11 14:58:20
请提供image_dataset_from_directory内这个特定文件夹(Plantvillage)的完整路径,以访问数据集,根据其class_names,所有图像都驻留在不同的文件夹中。
例如,:假设我在"Data\dataset“文件夹中有一个猫和一个狗两个文件夹,每个文件夹都有20个猫图像和20个狗图像,那么您可以通过如下指定根路径来访问这两个文件夹:
dataset = tf.keras.preprocessing.image_dataset_from_directory(
"D:\Data\Dataset", # This will show the inside folder names along with each folder images count
shuffle= True,
image_size = (IMAGE_SIZE,IMAGE_SIZE),
batch_size = BATCH_SIZE
)
class_names = dataset.class_names
class_names输出:
Found 40 files belonging to 2 classes.
Out[3]: ['Cat', 'Dog']https://stackoverflow.com/questions/73590949
复制相似问题