首页 > 解决方案 > 保存 CNN 模型时出现“FileNotFoundError: [Errno 2] No such file or directory”

问题描述

我尝试将 CNN 模型和权重保存为 json 格式,但我在这里遇到了一些我不知道的问题

#save model and weight
#model to json files
model_json = model.to_json()
with open("model/model_json_sgd001.json", "w") as json_file:
    json_file.write(model_json)
#weight to h5 file
model.save_weights("model/model_1_sgd001.h5")

print("Model dan Bobot telah disimpan")

错误说

> FileNotFoundError                         
> Traceback (most recent call last) <ipython-input-14-d1dce1f405b9> in <module>
>       2 #model to json files
>       3 model_json = model.to_json()
> ----> 4 with open("model/model_json_sgd001.json", "w") as json_file:
>       5     json_file.write(model_json)
>       6 #weight to h5 file
> 
> FileNotFoundError: [Errno 2] No such file or directory:
> 'model/model_json_sgd001.json'

所以我只需要制作一个文件model_json_sgd001.json

标签: pythonpython-3.7

解决方案


推荐阅读