几天来,我正试图用pytorch复制我的keras训练结果.无论我做什么,pytorch模型都会在keras中过早地设置到更强的验证集.对于pytorch,我使用与https://github.com/Cadene/pretrained-models.pytorch相同的XCeption代码.
数据加载,扩充,验证,培训计划等是等效的.我错过了一些明显的东西吗 某处肯定存在普遍问题.我尝试了数千个不同的模块星座,但似乎没有任何东西接近keras训练.有人可以帮忙吗?
Keras型号:val精度> 90%
# base model
base_model = applications.Xception(weights='imagenet', include_top=False, input_shape=(img_width, img_height, 3))
# top model
x = base_model.output
x = GlobalMaxPooling2D()(x)
x = Dense(512, activation='relu')(x)
x = Dropout(0.5)(x)
predictions = Dense(4, activation='softmax')(x)
# this is the model we will train
model = Model(inputs=base_model.input, outputs=predictions)
# Compile model
from keras import optimizers
adam = optimizers.Adam(lr=0.0001)
model.compile(loss='categorical_crossentropy',
optimizer=adam, metrics=['accuracy'])
# LROnPlateau etc. with equivalent settings as pytorch
Run Code Online (Sandbox Code Playgroud)
Pytorch模型:val精度~81%
from xception import xception
import torch.nn.functional as F
# …Run Code Online (Sandbox Code Playgroud)