当前位置:网站首页>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 :
边栏推荐
- 通过ComponentCallbacks2来接收onTrimMemory等回调,并mock对应的场景
- Summary of embedded software interview questions
- C language - Growth Diary -03- function definition and function prototype declaration
- Node error report sorting
- 关于网络知识的50个问答题,你能答对几个?
- Servlet
- SylixOS SD设备驱动开发
- Label the mask image not obtained through labelme
- TypeScript-头文件使用细节
- TypeScript-null和undefined
猜你喜欢

Scrape captures 51job Recruitment Information (static page)

Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)

Tutoriel de démarrage bladed (vidéo)

C language lesson 2

Sign in system design: how to draw the sign in function

Typescript header file usage details

TypeScript-头文件使用细节

【案例解读】医疗单据OCR识别助力健康险智能理赔

Printing diamond of beginner C

【 史上最全的ENSP【安装图解】!】
随机推荐
Use guidelines in constraintlayout to limit the maximum width of controls
Typescript interface and type alias similarities and differences
通过ComponentCallbacks2来接收onTrimMemory等回调,并mock对应的场景
How to make hyperlinks in RichTextBox- How can I make a hyperlink work in a RichTextBox?
2021-11-05 definition of cache
使用特殊字符拼接字符串“+“
Node error report sorting
Typescript type protection
Typescript recognizable Union
使用POSTMAN 测试firebase
学习《缠解论语》
Closure and minimum dependency in database
Servlet、ServletConfig、ServletContext
Several ways to avoid concurrent modification exceptions of lists
Batch splice string
Socket [5] - struct linker usage
TypeScript-命名空间
Typescript enumeration
Testing firebase with postman
C language - Growth Diary -01- count primes and sum