问题描述: 在使用AutoKeras图像分类器时,发现生成器不起作用,导致plt.show()显示空白图像。
解决方法: 以下是一些可能的解决方法:
import os
import autokeras as ak
train_path = 'path/to/train_data'
test_path = 'path/to/test_data'
# 检查路径下的文件数量
print(len(os.listdir(train_path)))
print(len(os.listdir(test_path)))
# 使用AutoKeras加载数据
train_data = ak.image_dataset_from_directory(train_path, image_size=(100, 100))
test_data = ak.image_dataset_from_directory(test_path, image_size=(100, 100))
# 检查加载的数据
for data in train_data:
images, labels = data
print(images.shape)
print(labels.shape)
for data in train_data:
images, labels = data
print(images.shape)
print(labels.shape)
import matplotlib.pyplot as plt
# 显示第一张图像
plt.imshow(images[0])
plt.show()
model = ak.ImageClassifier(max_trials=10)
model.fit(train_data)
如果上述解决方法仍然无法解决问题,你可以尝试重新安装AutoKeras或者查看AutoKeras的文档,以获取更多关于使用AutoKeras的示例和建议。