I've been tasked with creating a training model which will produce and .h5 file at the end. I've been having a lot of trouble with this however and was hoping I could get some guidance. At the moment I'm trying to get it to basically just start training and then create the .h5 file, I will work on normalising the images and such later.
A few things to note, I have more than two categories and my images aren't all the same size. I also don't have a GPU. I was hoping to get some guidance or answers. Thanks for any help you guys can give
######################################################
# Imports
######################################################
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import RMSprop
from tensorflow.keras import layers
######################################################
# Settings and Parameters
######################################################
train_pics = ImageDataGenerator(rescale=1/255) # setting the value of which we multiply before any other processing
test_pics = ImageDataGenerator(rescale=1/255) # setting the value of which we multiply before any other processing
trainSet = train_pics.flow_from_directory('Pictures/train/', target_size=(100, 100), batch_size=11,
class_mode='categorical') # path and data
testSet = train_pics.flow_from_directory('Pictures/test/', target_size=(100, 100), batch_size=20,
class_mode='categorical') # path and data
######################################################
# Model Creation
######################################################
model = keras.Sequential(
[
tf.keras.layers.Conv2D(16, (3, 3), activation='relu', input_shape=(250, 250, 3)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(32, (3, 3), activation="relu"),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(64, (3, 3), activation="relu"),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(64, (3, 3), activation="relu"),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Conv2D(64, (3, 3), activation="relu"),
tf.keras.layers.MaxPooling2D(2, 2),
layers.Flatten(),
layers.Dropout(0.5),
layers.Dense(8, activation="softmax"),
]
)
model.compile(loss='categorical_crossentropy', # compile the model
optimizer='adam',
metrics=['accuracy'])
train = model.fit( # train the model
train_pics,
steps_per_epoch=200,
epochs=100,
validation_data=testSet
)
model.save('charactersPics.h5')
This is the output:
question from:
https://stackoverflow.com/questions/65833214/keras-image-identification-training-model