我正在使用 tensorflow 进行测试。我将数据集放入两个文件夹中。我配置了batch_size
,height
和width
,train_data
但是我看不到它们matplotlib
或在模型中使用它。
#Import dataset
import pathlib
import os
data_dir = pathlib.Path(r'C:\Users\vion1\Ele\Engie\Exercices\DL\Pikachu\dataset')
image_count = len(list(data_dir.glob('*/*')))
print(image_count)
#374
batch_size = 32
img_height = 256
img_width = 256
train_data = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=42,
image_size=(img_height, img_width),
batch_size=batch_size,
)
class_names = train_data.class_names
print(train_data)
#Found 374 files belonging to 2 classes.
#Using 300 files for training.
#<BatchDataset shapes: ((None, 256, 256, 3), (None,)), types: (tf.float32, tf.int32)>
plt.figure(figsize=(10, 10))
for images, labels in train_data.take(1):
for i in range(3):
ax = plt.subplot(1, 3, i + 1)
plt.imshow(images[i].numpy().astype("uint8"))
plt.axis("off")
错误是:
InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required.
[[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]
我认为这train_date.take(1)
不会占用文件,但我不明白为什么以及如何修复它,知道吗?