[问题] Keras 每次结果不同

楼主: f496328mm (为什么会流泪)   2017-09-06 13:15:49
我目前使用 keras 的 vgg16 进行建模,但是每次结果都不一样,
即使我设定 seed,shuffle 也设 false
code 如下,想问问看有没有什么解决方法,
我上网 google ,有可能是因为 GPU 运算的关系? 那要如何解?
谢谢
PS: 环境
ubuntu 16.04
python3
gtx-1070
model_vgg16_conv = VGG16(weights=None, include_top=False)
input = Input(shape=(rows,cols,3),name = 'image_input')
output_vgg16_conv = model_vgg16_conv(input)
x = Flatten(name='flatten')(output_vgg16_conv)
x = Dense(1024, activation='relu', name='fc1')(x)
x = Dense(1024, activation='relu', name='fc2')(x)
x = Dense(2, activation='softmax', name='predictions')(x)
model = Model(input=input, output=x)
sgd = SGD(lr=1e-4, momentum=0.2, nesterov=True)
model.compile(sgd, loss='binary_crossentropy')
random.seed(100)
set_random_seed(100)
np.random.seed(1337)
model.fit(sub_train_x,
sub_train_y,
batch_size=64,
epochs=2,
verbose=1,
#validation_split=0.2,
shuffle=False)
作者: hl4 (Zec)   2017-09-06 15:51:00
可以参考一下https://github.com/fchollet/keras/issues/2743他有找到可行的做法阿,只是要重开 ipynb 而已

Links booklink

Contact Us: admin [ a t ] ucptt.com