I wrote a face classifier program with Tensorflow
. In this project, first I just had 2 faces so I used binary_crossentropy
as loss function. When I decided to add more faces I switched from binary_crossentropy
to categorical_crossentropy
.
My code:
import tensorflow as tf
from tensorflow.keras.datasets import cifar10
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D
import pickle
pickle_in = open("/content/gdrive/My Drive/Deep Learning/Yüz Tan?ma/X.pickle","rb")
X = pickle.load(pickle_in)
pickle_in = open("/content/gdrive/My Drive/Deep Learning/Yüz Tan?ma/y.pickle","rb")
y = pickle.load(pickle_in)
X = X/255.0
model = Sequential()
model.add(Conv2D(128, (4, 4), input_shape=X.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(128, (4, 4)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Flatten())
model.add(Dropout(0.4))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
model.fit(X, y, batch_size=32, epochs=20,validation_split=0.3)
model.save("/content/gdrive/My Drive/Deep Learning/Yüz Tan?ma/model.h5")
And here is my training log:
Epoch 1/20
1728/1728 [==============================] - 30s 13ms/step - loss: 0.0000e+00 - accuracy: 0.4833 - val_loss: 0.0000e+00 - val_accuracy: 0.4826
Epoch 2/20
1728/1728 [==============================] - 22s 13ms/step - loss: 0.0000e+00 - accuracy: 0.4847 - val_loss: 0.0000e+00 - val_accuracy: 0.4826
Epoch 3/20
1728/1728 [==============================] - 22s 13ms/step - loss: 0.0000e+00 - accuracy: 0.4827 - val_loss: 0.0000e+00 - val_accuracy: 0.4826
As you can see my val_loss
and val_accuracy
don't change. What's wrong with my code and how can I fix that?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…