Hello, I have a question. My image format is completely fine, but I keep getting an error saying “Unknown image file format. One of JPEG, PNG, GIF, BMP required.” Can someone tell me where I went wrong with my code? Here is my code:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.optimizers import Adam #优化器
data_dir='Flug'
img_height=224
img_width=224
train_ds=tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=10,
)
#验证集
val_ds = tf.keras.utils.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=10,
)
model = tf.keras.Sequential([
tf.keras.layers.Rescaling(1./255), #数据在进入层序列时就已经通过这行代码归一化了
tf.keras.layers.Conv2D(32, 3, activation='relu',input_shape=(224,224,3)),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(1)
])
#model.build(input_shape=(None, img_height, img_width, 3))
#print(model.summary())
model.compile(loss='binary_crossentropy',optimizer=Adam(learning_rate=1e-4),metrics=['acc'])
model.fit(
train_ds,
validation_data=val_ds,
epochs=10
)