LoginSignup
5
1

More than 3 years have passed since last update.

【keras】重たいモデルのload/save

Last updated at Posted at 2019-06-28

kerasでモデルを学習して保存しておく際、通常であれば

model.save('test_model.h5')

などで保存するのが一般的であるが、これをそのままload_modelすると以下のようなエラーが出ることがある。100M以上とかの大きいファイルを読み込む時に良く出て来る。

OSError: Unable to open file (file signature not found)

保存したモデルを推論に使うのみであれば、以下のように学習に必要な情報を省略して保存することで、ファイルの大きさが半分程度になる。大体の場合はこれでエラーが出なくなる。

model.save('test_model.h5',  include_optimizer=False)
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1