我的TF深度学习模型停留在50%的验证准确度上,而我的训练准确度是65%并在不断提高。以下是一些注意事项-
下面是我的代码。可能有点让人不知所措,请随时问我一些具体问题-
def generator(positive_dataset, negative_dataset):
while True:
for pos_rec, neg_rec in zip(positive_dataset, negative_dataset):
pos_x, pos_y = pos_rec
neg_x, neg_y = neg_rec
x = tf.concat([pos_x, neg_x], axis=0)
y = tf.concat([pos_y, neg_y], axis=0)
yield x, y
train_generator = generator(train_dataset_female, train_dataset_male)
test_generator = generator(test_dataset_female, test_dataset_male)
input_layer = layers.Input(shape=(IMG_SIZE, IMG_SIZE, 3))
mobilenet_layer = MobileNetV2(weights=None, include_top=False, alpha=0.35)(input_layer)
landmarks_layer = layers.GlobalAveragePooling2D()(mobilenet_layer)
landmarks_layer = layers.Flatten()(landmarks_layer)
landmarks_layer_flat = layers.Dense(68 * 2, activation='sigmoid', name='landmarks_flat')(landmarks_layer)
landmarks_layer = layers.Reshape(target_shape=(68, 2), name='landmarks')(landmarks_layer_flat)
landmarks_model = tf.keras.models.Model(inputs=input_layer, outputs=landmarks_layer)
prob_face_layer = layers.GlobalAveragePooling2D()(mobilenet_layer)
prob_face_layer = layers.Flatten()(prob_face_layer)
prob_face_layer = layers.concatenate([prob_face_layer, landmarks_layer_flat])
prob_face_layer = layers.Dense(256, activation='relu')(prob_face_layer)
prob_face_layer = layers.Dense(1, activation='sigmoid')(prob_face_layer)
prob_face_net = tf.keras.models.Model(inputs=input_layer, outputs=prob_face_layer)
print('Prob Face Net')
print(prob_face_net.summary())
print('Pose Model')
pose_model.summary()
print('Landmarks Model')
landmarks_model.summary()
combined_model = tf.keras.models.Model(inputs=input_layer,outputs[landmarks_layer, pose_layer])
print('Combined Model')
combined_model.summary()
full_model = tf.keras.models.Model(inputs=input_layer, outputs=[prob_face_layer, landmarks_layer, pose_layer])
print('Full Net')
print(full_model.summary())
combined_model.load_weights('/mnt/sachins/apprach2/models/bounding_box_based_model_faster_2.h5')
for layer in range(0, 8):
prob_face_net.layers[layer].trainable = False
prob_face_net.compile(loss='binary_crossentropy', optimizer='adam', metrics=[ 'accuracy'])
history = prob_face_net.fit_generator(
train_generator,
epochs=EPOCHS,
steps_per_epoch=(num_train_imgs_male+ num_train_imgs_female)//(BATCH_SIZE//2),
validation_data=test_generator,
validation_steps=(29999*2 - (num_train_imgs_male+num_train_imgs_female))//(BATCH_SIZE//2),
callbacks=callbacks,
verbose = 1)
答案 0 :(得分:0)