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]))


目录
相关文章
|
3月前
|
PyTorch 算法框架/工具 Python
Traceback (most recent call last):WARNING: Dataset not found, nonexistent paths:
这篇文章描述了在使用YOLOv5进行训练时遇到的"Dataset not found"错误,分析了可能的原因,包括网络连接问题和数据集路径配置错误,并提供了相应的解决方法,如检查网络设置和确认数据集文件的存放位置。
Traceback (most recent call last):WARNING: Dataset not found, nonexistent paths:
“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题
“Could not find suitable distribution for Requirement.parse(‘XXXX‘)”的问题
354 0
ERROR: No matching distribution found for gradio>=3.23
该博客文章提供了解决使用pip安装gradio版本3.23时出现的"No matching distribution found"错误的步骤,包括从官网下载相应的whl文件并手动安装。
ERROR: No matching distribution found for gradio>=3.23
|
算法框架/工具
成功解决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
|
6月前
|
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
|
虚拟化
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
|
数据库
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
1120 0
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matching
jinja2: Can't perform this operation for unregistered loader type
jinja2: Can't perform this operation for unregistered loader type
140 0
|
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.
|
算法框架/工具 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