I'm trying to create a model to classify images. there are 21 different classes they each have around 800 images. images are in different sizes and aspect ratios and they are resized to (64,64) pixels. I use PIL
to store RGB
values. then the RGB
values are normalized
y_train.append(class)
input_path = os.path.join(image_path)
im = Image.open(input_path)
im = im.resize((64 ,64))
rgb_im = im.convert('RGB')
im = np.asarray(rgb_im,dtype="int")
X_train.append(im)
X_train = X_train / 255
I used AlexNet
for architecture like below:
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(filters=96, kernel_size=(11,11), strides=(4,4), activation='relu', input_shape=(64,64,3)),
tf.keras.layers.Lambda(tf.nn.local_response_normalization),
tf.keras.layers.MaxPool2D(pool_size=(3,3), strides=(2,2), padding="same"),
tf.keras.layers.Conv2D(filters=256, kernel_size=(5,5), strides=(1,1), activation='relu', padding="same"),
tf.keras.layers.Lambda(tf.nn.local_response_normalization),
tf.keras.layers.MaxPool2D(pool_size=(3,3), strides=(2,2), padding="same"),
tf.keras.layers.Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), activation='relu', padding="same"),
tf.keras.layers.Lambda(tf.nn.local_response_normalization),
tf.keras.layers.Conv2D(filters=384, kernel_size=(3,3), strides=(1,1), activation='relu', padding="same"),
tf.keras.layers.Lambda(tf.nn.local_response_normalization),
tf.keras.layers.Conv2D(filters=256, kernel_size=(3,3), strides=(1,1), activation='relu', padding="same"),
tf.keras.layers.Lambda(tf.nn.local_response_normalization),
tf.keras.layers.MaxPool2D(pool_size=(3,3), strides=(2,2), padding="same"),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(4096, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(4096, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(21, activation='softmax')])
model.compile(loss = "sparse_categorical_crossentropy", optimizer = keras.optimizers.Adam(0.001),metrics=['accuracy'])
model.fit(X_train_np,y_train_np,epochs=10,validation_split=0.2,batch_size = 8)
when I run the model the loss
isn't changing that much and the validation accuracy
is always zero.
Epoch 1/10
1675/1675 [==============================] - 622s 366ms/step - loss: 2.8486 - accuracy: 0.0606 - val_loss: 8.4990 - val_accuracy: 0.0000e+00
Epoch 2/10
1675/1675 [==============================] - 610s 364ms/step - loss: 2.8381 - accuracy: 0.0569 - val_loss: 8.9872 - val_accuracy: 0.0000e+00
Epoch 3/10
1675/1675 [==============================] - 609s 363ms/step - loss: 2.8356 - accuracy: 0.0597 - val_loss: 9.6850 - val_accuracy: 0.0000e+00
Epoch 4/10
1675/1675 [==============================] - 609s 363ms/step - loss: 2.8347 - accuracy: 0.0585 - val_loss: 10.3163 - val_accuracy: 0.0000e+00
Epoch 5/10
1675/1675 [==============================] - 640s 382ms/step - loss: 2.8344 - accuracy: 0.0547 - val_loss: 10.5695 - val_accuracy: 0.0000e+00
I'm fairly new in this field so I don't know if the problem is from my data processing or model.
NOTE
this is kind of an assignment so the problem isn't the data itself.