Fork me on CSDN

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

源代码:

model = vgg16()
model.summary()

错误提示:

D:\Anaconda\envs\tensorflow\python.exe D:/PYCHARMprojects/Dailypractise/P29.py
2021-07-27 15:02:48.283426: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "D:/PYCHARMprojects/Dailypractise/P29.py", line 79, in <module>
    model.summary()
  File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\training.py", line 2351, in summary
    raise ValueError('This model has not yet been built. '
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.

Process finished with exit code 1

 

 修正:

model = vgg16()
model.build(input_shape=( 100, 28, 28, 1))
model.summary()

效果:

D:\Anaconda\envs\tensorflow\python.exe D:/PYCHARMprojects/Dailypractise/P29.py
2021-07-27 15:07:47.046058: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
reshape (Reshape)            (100, 28, 28, 1)          0         
_________________________________________________________________
conv2d (Conv2D)              (100, 28, 28, 64)         640       
_________________________________________________________________
conv2d_1 (Conv2D)            (100, 28, 28, 64)         36928     
_________________________________________________________________
max_pooling2d (MaxPooling2D) (100, 14, 14, 64)         0         
_________________________________________________________________
conv2d_2 (Conv2D)            (100, 14, 14, 128)        73856     
_________________________________________________________________
conv2d_3 (Conv2D)            (100, 14, 14, 128)        147584    
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (100, 7, 7, 128)          0         
_________________________________________________________________
conv2d_4 (Conv2D)            (100, 7, 7, 256)          295168    
_________________________________________________________________
conv2d_5 (Conv2D)            (100, 7, 7, 256)          590080    
_________________________________________________________________
conv2d_6 (Conv2D)            (100, 7, 7, 256)          590080    
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (100, 3, 3, 256)          0         
_________________________________________________________________
conv2d_7 (Conv2D)            (100, 3, 3, 512)          1180160   
_________________________________________________________________
conv2d_8 (Conv2D)            (100, 3, 3, 512)          2359808   
_________________________________________________________________
conv2d_9 (Conv2D)            (100, 3, 3, 512)          2359808   
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (100, 1, 1, 512)          0         
_________________________________________________________________
conv2d_10 (Conv2D)           (100, 1, 1, 512)          2359808   
_________________________________________________________________
conv2d_11 (Conv2D)           (100, 1, 1, 512)          2359808   
_________________________________________________________________
conv2d_12 (Conv2D)           (100, 1, 1, 512)          2359808   
_________________________________________________________________
flatten (Flatten)            (100, 512)                0         
_________________________________________________________________
dense (Dense)                (100, 256)                131328    
_________________________________________________________________
dropout (Dropout)            (100, 256)                0         
_________________________________________________________________
dense_1 (Dense)              (100, 256)                65792     
_________________________________________________________________
dropout_1 (Dropout)          (100, 256)                0         
_________________________________________________________________
dense_2 (Dense)              (100, 10)                 2570      
_________________________________________________________________
activation (Activation)      (100, 10)                 0         
=================================================================
Total params: 14,913,226
Trainable params: 14,913,226
Non-trainable params: 0
_________________________________________________________________

Process finished with exit code 0

 

posted @ 2021-07-27 15:10  追风赶月的少年  阅读(2339)  评论(0编辑  收藏  举报