ValueError: This model has not yet been built. Build the model first by calling `build()` or calling

简介: ValueError: This model has not yet been built. Build the model first by calling `build()` or calling

ValueError: This model has not yet been built. Build the model first by calling `build()` or calling `fit()` with some data, or specify an `input_shape` argument in the first layer(s) for automatic build.

TensorFlow打印模型结构时发生上述问题

model.summary

发生问题的原因:

是模型不知道你的输入数据格式,即输入的数据维度,所以发生报错

解决方法有两种:

方法一:提前编译模型,给定输入数据维度

# 括号内为待输入数据的维度,注意第一个维度一定要存在,为批次,之后才是每个样本的维度
model.build((1, 32, 32, 1))

方法二:提前喂给模型数据,让模型知道输入数据的形式

model(tf.zeros([1, 32, 32, 1]))


目录
相关文章
|
2月前
|
Java 数据库连接 Apache
Correct the classpath of your application so that it contains compatible versions of the classes com
Correct the classpath of your application so that it contains compatible versions of the classes com
53 0
|
26天前
|
人工智能 机器人 测试技术
【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...
【CMake报错】Cannot specify compile definitions for target “PRIVATE“ which is not built...
|
25天前
|
JavaScript
解决报错did you register the component correctly? For recursive components, make sure to provide the “na
解决报错did you register the component correctly? For recursive components, make sure to provide the “na
|
算法框架/工具
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
|
9月前
|
虚拟化
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
|
6月前
|
计算机视觉 Python
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)
|
JSON 移动开发 算法框架/工具
成功解决raise ValueError(‘No model found in config file.‘) ValueError: No model found in config file.
成功解决raise ValueError(‘No model found in config file.‘) ValueError: No model found in config file.
How to find implementation of Requirement defined in Pricing Procedure
How to find implementation of Requirement defined in Pricing Procedure
How to find implementation of Requirement defined in Pricing Procedure
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
121 0
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
|
算法框架/工具 Python
成功解决 keras\callbacks.py:999: UserWarning: `epsilon` argument is deprecated and will be removed, use
成功解决 keras\callbacks.py:999: UserWarning: `epsilon` argument is deprecated and will be removed, use