旅行好きなソフトエンジニアの備忘録

プログラミングや技術関連のメモを始めました

【Python】KerasでMobileNetのモデルファイルを読み込む方法

KerasでMobileNetのモデルファイルを読み込もうとすると"Unknown activation function:relu6"といったエラーが出ます。このエラーへの対処はここに書かれており、以下のようにすれば大丈夫でした。

from keras.utils.generic_utils import CustomObjectScope

with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):
    model = load_model('weights.h5')