Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Machine learning Keras:fit_生成器的精度要比evaluate_生成器高出一行的精度低得多?_Machine Learning_Tensorflow_Neural Network_Deep Learning_Keras - Fatal编程技术网

Machine learning Keras:fit_生成器的精度要比evaluate_生成器高出一行的精度低得多?

Machine learning Keras:fit_生成器的精度要比evaluate_生成器高出一行的精度低得多?,machine-learning,tensorflow,neural-network,deep-learning,keras,Machine Learning,Tensorflow,Neural Network,Deep Learning,Keras,我遵循迁移学习的原则: ##First I compute the saved the bottleneck features and build a new model and train it with the bottleneck features: input_layer = Input(shape=base_model.output_shape[1:]) x = GlobalAveragePooling2D()(input_layer) x = Dense(512, activati

我遵循迁移学习的原则:

##First I compute the saved the bottleneck features and build a new model and train it with the bottleneck features: 
input_layer = Input(shape=base_model.output_shape[1:])
x = GlobalAveragePooling2D()(input_layer)
x = Dense(512, activation='relu',name='fc_new_1')(x)
x = Dropout(0.2)(x)
x = Dense(512, activation='relu',name='fc_new_2')(x)
x = Dense(num_classes, activation='softmax',name='logit_new')(x)
Add_layers = Model(inputs=input_layer, outputs=x,name='Add_layers')

##Then I put this new model at the end of pretrained models: 
base_model = ResNet50(include_top=False, weights='imagenet', input_shape=
(img_shape[0],img_shape[1],3))
x = base_model.output
predictions = Add_layers(x)
model = Model(inputs=base_model.input, outputs=predictions)
model.compile(optimizer=sgd, loss='categorical_crossentropy', metrics=
['accuracy'])

##Then, I evaluate the model : 
score = model.evaluate_generator(train_generator, nb_train_samples // 
batch_size_finetuning)
print('The evaluation of the entire model before fine tuning : ')
print(score)
score = model.evaluate_generator(validation_generator, nb_validation_samples 
// batch_size_evaluation)
print('The evaluation of the entire model before fine tuning : ')
print(score)
并获得训练损失和准确性:
[0.0153620622912073827,1.0]
验证损失和准确性:
[0.89740632474422455,0.75]

##Just one line below it, I trained the new model: 
model.fit_generator(train_generator,
                steps_per_epoch= nb_train_samples // batch_size_finetuning,
                epochs=finetuning_epoch,
                validation_data=validation_generator,
                validation_steps=nb_validation_samples //batch_size_evaluation,
                callbacks=[checkpointer_finetuning, 
 history_finetuning,TB_finetuning,
lrate_finetuning,Eartly_Stopping_finetuning]);
那么输出是:

31/31 [==============================] - 35s - loss: 3.4004 - acc: 0.3297 - val_loss: 0.9591 - val_acc: 0.7083
奇怪的是:只有当我使用
Resnet50
InceptionV3
而不是
vgg16
时,这个问题才会发生。我很确定改变预训练模式是唯一的区别。我知道辍学可能会使情况有所不同,但不应该这么大,而且
vgg16
根本没有明显的问题

另一件奇怪的事情是:如果我将每一层都更改为
.trainable=False
,然后进行编译,验证的准确性仍然会显著降低。我甚至检查了每一层的权重,如果
.trainable=False
权重不会改变,
.trainable=True
权重会改变


感谢您的帮助!!!谢谢

有人有类似的问题吗?