增强图层的代码
data_augmentation = tf.keras.Sequential([
layers.RandomFlip('horizontal'),
layers.RandomRotation(0.2),
])
函数get_model(模型名称,droput_rate)内的模型块:
model = tf.keras.Sequential([
data_augmentation,
layers.Conv3D(64, (5, 5, 5), padding='same', activation='relu', input_shape=(22, 64, 64, 1)),
layers.BatchNormalization(),
layers.MaxPooling3D(pool_size=(3, 3, 3)),
layers.Dropout(dropout_rate),
layers.Conv3D(128, (5, 5, 5), padding='same', activation='relu'),
layers.Conv3D(128, (5, 5, 5), padding='same', activation='relu'),
layers.BatchNormalization(),
layers.MaxPooling3D(pool_size=(3, 3, 3)),
layers.Dropout(dropout_rate),
layers.GlobalMaxPool2D(),
layers.Dense(10, activation='softmax')])
此处model_name将调用上述模型块
一个二个一个一个
执行上述代码时,显示以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-166-57c956c1a8c7> in <module>()
4
5 # plot the model architecture
----> 6 model.summary()
7 plot_model(model, to_file='/content/gdrive/MyDrive/Lip Reading/outputs/architecture_{}.pdf'.format(model_name), show_shapes=True, show_layer_names=False)
/usr/local/lib/python3.7/dist-packages/keras/engine/training.py in summary(self, line_length, positions, print_fn, expand_nested, show_trainable)
2774 if not self.built:
2775 raise ValueError(
-> 2776 'This model has not yet been built. '
2777 'Build the model first by calling `build()` or by calling '
2778 'the model on a batch of data.')
ValueError: This model has not yet been built. Build the model first by calling `build()` or by calling the model on a batch of data.
2条答案
按热度按时间kh212irz1#
抛出错误的是
model.summary()
。在调用model.summary()
之前执行model.build(input_shape=(x1, x2, x3))
。当然,您需要用所需的形状替换input_shape
。vaqhlq812#
在模型中添加下面的行对我很有效。
下面是代码片段: