Keras / TensorFlow低精度和val_acc

时间:2019-12-11 15:04:30

标签: python tensorflow machine-learning keras deep-learning

我是ML的新手,并且正在使用MobileNet mobel和Keras Sequential进行项目。我正在进行多类分类,而且我不知道为什么收到如此糟糕的认证。我的数据集包含超过20000张图像,我分为80%用于训练,10%验证和10%测试。附言我尝试实施学习率时间表,但没有帮助。这是我用于模型的代码:

base_model=tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE,
include_top=False,
weights='imagenet')
feature_batch=base_model(image_batch)
base_model.trainable=False
global_average_layer=tf.keras.layers.GlobalAveragePooling2D()
feature_batch_average=global_average_layer(feature_batch)
print(feature_batch_average.shape)
prediction_layer=keras.layers.Dense(7, activation='softmax')
prediction_batch=prediction_layer(feature_batch_average)
model=tf.keras.Sequential([base_model,
global_average_layer,
prediction_layer])
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001, beta_1=0.9, beta_2=0.999, amsgrad=False),
              loss='categorical_crossentropy',
              metrics=['accuracy'])
model.summary()
initial_epochs=20
steps_per_epoch=round(len(train_images_set))//BATCH_SIZE
validation_steps=20
loss0,accuracy0 = model.evaluate(validation_batches, steps = validation_steps)
print("initial loss: {:.2f}".format(loss0))
print("initial accuracy: {:.2f}".format(accuracy0))
history = model.fit(train_batches,
                    epochs=initial_epochs,
                    validation_data=validation_batches)

0 个答案:

没有答案