我尝试加载我在本地机器上创建的模型,首先我将我的模型(.h5文件)上传到Google Drive,然后使用以下代码在Colab中访问我的模型
from google.colab import drivedrive.mount('/content/drive')
然后我尝试使用以下代码
from keras.models import load_modelclassifier = load_model('/content/drive/My Drive/Colab Notebooks/face_shape_recog_model.h5')
运行上述代码后,我得到了以下错误
AttributeError: module 'tensorflow' has no attribute 'placeholder'
我尝试卸载并重新安装tensorflow和keras,但仍然面临同样的问题,我也尝试了在GitHub问题中提到的解决方案
谢谢
回答:
我怀疑这是由于Keras 2.2和TensorFlow 2.x之间的不兼容性引起的。你可以通过更新到Keras 2.3或更高版本来解决这个问题:
!pip install -U keras
编辑 2020-04-10:看起来Keras 2.3现在已经是Colab的默认版本,因此上述修复不再必要。