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


目录
相关文章
|
4月前
|
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:
|
算法框架/工具
成功解决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
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
|
7月前
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target S
107 0
|
虚拟化
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
ORB_SLAM2_CUDA : Make failed - Compiling examples - Undefined References
ORB_SLAM2_CUDA : Make failed - Compiling examples - Undefined References
111 0
|
机器学习/深度学习 TensorFlow 算法框架/工具
Tensorboard: No graph definition files were found
Tensorboard: No graph definition files were found
168 0
Tensorboard: No graph definition files were found
AttributeError: partially initialized module ‘jieba‘ has no attribute ‘cut‘ (most likely due to a ci
AttributeError: partially initialized module ‘jieba‘ has no attribute ‘cut‘ (most likely due to a ci
558 0
AttributeError: partially initialized module ‘jieba‘ has no attribute ‘cut‘ (most likely due to a ci
Error: invalid option: --with-training-tools
Error: invalid option: --with-training-tools
177 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.