def get_vgg_twoeyes () - это определение моей модели.Я загрузил предварительно обученную модель, которая обучается на том же компьютере, а затем я хочу настроить модель.Перед переобучением модели я установил false для model.trainable, чтобы убедиться, что веса модели зафиксированы.Перед моей тренировкой весы совпадают с сохраненными весами.Я обнаружил, что выходные данные model.fit отличаются от выходных данных model.predict.Поскольку я предполагаю, что model.fit с теми же весами, что и model.predict, должен вывести тот же результат, потому что model.trainable имеет значение false, что означает, что model.fit ведет себя как model.predict.
def get_vgg_twoeyes (optimizer = 'adam ', model_type =' VGG16 ', fc1_size = 1024, fc2_size = 512, fc3_size = 256):
kern_init = initializers.glorot_normal()
img_input = Input(shape=(36, 60, 3), name='img_input')
headpose_input = Input(shape=(2,), name='headpose_input')
# create the base pre-trained model
if model_type == 'VGG19':
base_model = VGG19(input_tensor=img_input, weights='imagenet', include_top=False)
elif model_type == 'VGG16':
base_model = VGG16(input_tensor=img_input, weights='imagenet', include_top=False)
else:
raise Exception('Unknown model type in get_vgg_twoeyes')
# add a global spatial average pooling layer
x = base_model.output
x = GlobalAveragePooling2D()(x)
# let's add a fully-connected layer
x = Dense(fc1_size, kernel_initializer=kern_init)(x)
x = concatenate([x, headpose_input])
x = BatchNormalization()(x)
x = Activation('relu')(x)
x = Dense(fc2_size, kernel_initializer=kern_init)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
gaze_predictions = Dense(2, kernel_initializer=kern_init, name='pred_gaze')(x)
# this is the model we will train
model = Model(inputs=[img_input, headpose_input], outputs=gaze_predictions)
model.compile(optimizer=optimizer, loss=angle_loss, metrics=['accuracy', accuracy_angle])
return model
# fine-tune the model
models=load_model(model_path + "15Fold" + prefix + ''+str(i) +
suffix + ".h5",custom_objects={'accuracy_angle':accuracy_angle,
'angle_loss': angle_loss}))
model.trainable=False
adam = Adam(lr=0.0001, beta_1=0.9, beta_2=0.95)
model.compile(optimizer=adam, loss=angle_loss, metrics= ['accuracy', accuracy_angle])
model.fit({'img_input':cal_images,'headpose_input':cal_headposes},
cal_gazes,shuffle=False,batch_size=32,epochs=1,callbacks=
[losshistory()])
predgaze=model.predict({'img_input': cal_images, 'headpose_input':
cal_headposes}, batch_size=2,verbose=1)