Hi I'm trying to teach Mobilenet from scratch on Stanford dogs dataset.
My accuracy gets to 0.9 but Val_accuracy to 0.14 what should I do to fix it.
I'm not sure if I can use Mobilenet on such dataset
mobilenet(input_shape, n_classes):
def mobilenet_block(x, f, s=1):
x = DepthwiseConv2D(3, strides=s, padding='same')(x)
x = BatchNormalization()(x)
x = ReLU()(x)
x = Conv2D(f, 1, strides=1, padding='same')(x)
x = BatchNormalization()(x)
x = ReLU()(x)
return x
input = Input(input_shape)
x = Conv2D(32, 3, strides=2, padding='same')(input)
x = BatchNormalization()(x)
x = ReLU()(x)
x = mobilenet_block(x, 64)
x = mobilenet_block(x, 128, 2)
x = mobilenet_block(x, 128)
x = mobilenet_block(x, 256, 2)
x = mobilenet_block(x, 256)
x = mobilenet_block(x, 512, 2)
for _ in range(5):
x = mobilenet_block(x, 512)
x = mobilenet_block(x, 1024, 2)
x = mobilenet_block(x, 1024)
x = GlobalAvgPool2D()(x)
output = Dense(n_classes, activation='softmax')(x)
model = Model(input, output)
return model
now here is how I'm training the model
enter code here dataset, info = tfds.load(name="stanford_dogs", with_info=True)
get_name = info.features['label'].int2str
IMG_LEN = 224
IMG_SHAPE = (IMG_LEN, IMG_LEN, 3)
N_BREEDS = 120
training_data = dataset['train']
test_data = dataset['test']
model = mobilenet(IMG_SHAPE, 120)
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
train_batches = prepare(training_data, batch_size=32)
test_batches = prepare(test_data, batch_size=32)
trainedModel = model.fit(train_batches,epochs=30,validation_data=test_batches)
model.save(filename)
predictions = model.predict(prepare_image("images.jpg"))
top_components = tf.reshape(tf.math.top_k(predictions, k=5).indices, shape=[-1])
top_matches = [get_name(i) for i in top_components]
plt.title(top_matches[0])
print(top_matches)
is the way I'm compiling wrong? what am I missing..
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…