我尝试在我的图像数据集中使用 to_categorical() 进行单热编码,但由于 FileNotFoundError: [Errno 2] No such file or directory
错误而失败,代码如下,
import os
import numpy as np
from PIL import Image
from keras.utils import to_categorical
# Define the classes in the dataset
classes = ['BL_Healthy']
# Initialize the arrays to store the image data and labels
X = []
y = []
# Loop through the dataset and load each image
for class_id, class_name in enumerate(classes):
for image_file in os.listdir('/content/imdadulhaque/' + class_name):
image_path = os.path.join(class_name, image_file)
image = Image.open(image_path)
X.append(np.array(image))
y.append(class_id)
# Convert the labels to one-hot encoded labels
num_classes = len(classes)
y = to_categorical(y, num_classes)
虽然有图像,但不幸的是,它显示错误文件未找到。附件中提到了所需的错误屏幕截图。有想法的请帮忙