无法在Google Colab中打开文件文件读取失败:时间= 2020年8月23日星期日...

问题描述

我正在Google Colab中训练用于图像分割的神经网络。

培训代码为:

 print('Training')
 batch_size = 8
 nb_epoch = 5
 mcp_save = ModelCheckpoint('weight_isic18',save_best_only=True,monitor='val_loss',mode='min')
 reduce_lr_loss = ReduceLROnPlateau(monitor='val_loss',factor=0.1,patience=7,verbose=1,epsilon=1e-4,mode='min')
 history = model.fit(tr_data,tr_mask,batch_size=batch_size,epochs=nb_epoch,shuffle=True,validation_data=(val_data,val_mask),callbacks=[mcp_save,reduce_lr_loss] )
 print('Trained model saved')
 with open('hist_isic18','wb') as file_pi:
    pickle.dump(history.history,file_pi)

训练过程进展顺利,权重保存在这里

enter image description here

在加载砝码时会出现错误

model.load_weights('weight_isic18')

为:

enter image description here

在这方面的任何帮助将不胜感激。

解决方法

您正在尝试从目录加载模型。请注意,命令.load_weights()需要扩展名为.h5的文件,当然也不能包含目录。

我认为您正在寻找这个:
model = tf.saved_model.load(path)