当前位置:网站首页>Solve valueerror: no model found in config file
Solve valueerror: no model found in config file
2022-06-11 08:10:00 【sinysama】
solve ValueError: No model found in config file.
A friend showed me one bug, Before you say that .h5 All files can be loaded normally , Why does the above problem suddenly appear . I looked at , The first reaction is that there is no given model structure , That is, the following ↓

( Record only , Prevent more people from stepping on the pit . If there is anything wrong , Please give me more advice .)
1 Wrong presentation
No model found in config file.
2 The process of the problem
Use load_model() Method to save the model
3 Problem cause analysis
Look at the code , Just two lines . Plus the bag (from tensorflow.keras.models import load_model), Only three lines , Yes , It's just a process of loading the model .
filepath="./CNN.weights.h5"
model=load_model(filepath)
There is no problem with this code , After all, I often use , Quite familiar . that , The problem can only occur in .h5 How to save and how to load the model , Let's rule it out one by one .
4 Solution
When saving the model , There are some main ways to save :
①save()→ Save model parameters and network structure
②save_weights()→ Save only model parameters .
③tf.keras.callbacks.ModelCheckpoint()→ After configuring the parameters , It can be saved at any time during training .
Have a look at the code of the friend generation model , He was in model.fit Have adopted the ③ The way :
tf.keras.callbacks.ModelCheckpoint(filepath=filepath,monitor='val_accuracy',verbose=1,save_best_only=True,save_weights_only=True)
Sure enough ,save_weights_only=True, This is the reason for the error report , Missing network diagram structure , Because the code only saves parameter weights (only!!!). therefore , That's easy .
4.1 Solution one : Add network diagram structure
To match .h5 file , Write the network diagram structure again , then load_model Just fine .
4.2 Solution two : Save a new .h5 file
Get rid of save_weights_only=True Or the True Change it to False, Retrain the model and save .h5 file .( get to the root of sth. , When saving the model in the future, it is recommended to save the diagram structure and parameters together , Just take up more memory , The usual toy model is not very big , Why bother yourself by being lazy ?┗|`O′|┛ Ow ~~)
tf.keras.callbacks.ModelCheckpoint(filepath=filepath,monitor='val_accuracy',verbose=1,save_best_only=True)
The error report disappeared 
summary
Save only network parameters , Use load_weights().
Save graph structure and network parameters , Use load_model()( The saved .h5 The file is bigger );
Generally, no error will be reported if it is used without confusion
The comparison is as follows :
边栏推荐
- How to output the percent sign "%" in printf function in C language
- Dameng database startup and shutdown
- Image data enhancement (translation, rotation, brightness transformation, flipping, adding Gaussian noise, scaling, cropping)
- 自定义ViewGroup的知识点总结-持续更新
- 134. gas station
- Figure seamless database integration tushare interface
- Solve notimplementederror: layer XX has arguments in`__ init__` and therefore must override `get_ config`
- JSP technology: JSP overview, JSP basic syntax, JSP instructions, JSP implicit objects, JSP action elements
- 嵌入式软件面试问题总结
- Scrape captures 51job Recruitment Information (static page)
猜你喜欢

Summary of embedded software interview questions

Training yolov4 CSP model using coco dataset

2022.6.7 特长生模拟

mpi

Printing diamond of beginner C

C language - growth diary-04- preliminary exploration of local variables (local variables)

Image data enhancement (translation, rotation, brightness transformation, flipping, adding Gaussian noise, scaling, cropping)

进程控制:进程等待(回收子进程)

这几个小工具也太好用了

【案例解读】医疗单据OCR识别助力健康险智能理赔
随机推荐
如何开始参与开源社区
嵌入式软件面试问题总结
学习《缠解论语》
Using Tkinter to realize guessing numbers game
TypeScript-接口和类型别名异同
Bladed入门教程(视频)
C language to achieve a simple game - minesweeping
使用特殊字符拼接字符串“+“
Typescript type alias
Summary of embedded software interview questions
The solution of "no startup device" after running Bochs
DAMENG 用户管理
通过ComponentCallbacks2来接收onTrimMemory等回调,并mock对应的场景
Request request object and response response object
Post - payload of interface test
Xshell7 和 Xftp7要继续使用此程序,您必须应用最新的更新或者使用新版本
Thoroughly remember the difference between ImageView background and SRC
C language - Growth Diary -02- function
Tutoriel de démarrage bladed (vidéo)
Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel