我正在开发一个简单的keras模型,我想使用一些回调,例如Tensorboard和ReduceLROnPlateau,但是出现类似以下错误:
tensorflow.python.framework.errors_impl.FailedPreconditionError:尝试使用未初始化的值training / Adam / Variable_81
模型可在tensorflow 1.14,python 3.6,keras 2.2.4中使用
我尝试了keras.backends.get_session()。run(*** initializers),但是仍然显示相同的错误。
log_dir ='logs/'
data_gen_args = dict(rotation_range=0.2,
width_shift_range=0.05,
height_shift_range=0.05,
shear_range=0.05,
zoom_range=0.05,
horizontal_flip=True,
fill_mode='nearest')
myGene=trainGenerator(2,'data/membrane/train','image','label',data_gen_args,save_to_dir = None)
model_checkpoint = ModelCheckpoint(log_dir + "ep{epoch:03d}-loss{loss:.3f}.h5",
monitor='loss', save_weights_only=True, save_best_only=True, period=1)
logging = TensorBoard(log_dir=log_dir)
reduce_lr = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=3, verbose=1)
early_stopping = EarlyStopping(monitor='loss', min_delta=0, patience=3, verbose=1)
model = unet()
model.fit_generator(myGene,steps_per_epoch=5,epochs=10,callbacks=[logging, reduce_lr, early_stopping, model_checkpoint])
##########################
model codes, another .py file
##########################
from keras.models import *
from keras.layers import *
from keras.optimizers import *
from keras.callbacks import ModelCheckpoint, ReduceLROnPlateau
from keras import backend as keras
def unet(pretrained_weights = None,input_size = (256,256,1)):
inputs = Input(input_size)
conv1
......
conv10 = Conv2D(1, 1, activation = 'sigmoid')(conv9)
model = Model(input = inputs, output = conv10)
model.compile(optimizer = Adam(lr = 1e-4), loss =
'binary_crossentropy', metrics = ['accuracy'])
return model
early_stopping回调工作良好,也许与Adam无关。我只想在keras模型中添加一些回调函数。
或者与model.fit_generator有关系吗?