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


目录
相关文章
|
7月前
|
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月前
|
TensorFlow 算法框架/工具 Python
【Tensorflow】Found unexpected keys that do not correspond to any Model output: dict_keys([‘model_outp
文章讨论了在使用Tensorflow 2.3时遇到的错误信息:"Found unexpected keys that do not correspond to any Model output: dict_keys(['model_output']). Expected: ['dense']"。这个问题通常发生在模型的输出层命名与model.fit_generator的生成器函数中返回的值的键不匹配时。
74 1
|
10月前
|
并行计算 PyTorch 算法框架/工具
【已解决】RuntimeError: CuDA error: no kernel image is available for execution on the device
【已解决】RuntimeError: CuDA error: no kernel image is available for execution on the device
|
10月前
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
153 0
|
虚拟化
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
成功解决Failed to execute stage ‘Setup validation’: Hardware does not support virtualization.
|
机器学习/深度学习 异构计算 索引
PyG学习笔记2-CREATING MESSAGE PASSING NETWORKS
PyG学习笔记2-CREATING MESSAGE PASSING NETWORKS
422 0
PyG学习笔记2-CREATING MESSAGE PASSING NETWORKS
|
机器学习/深度学习 TensorFlow 算法框架/工具
Tensorboard: No graph definition files were found
Tensorboard: No graph definition files were found
205 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
594 0
AttributeError: partially initialized module ‘jieba‘ has no attribute ‘cut‘ (most likely due to a ci