'Dense' object has no attribute 'shape'
时间: 2023-06-21 17:18:12 浏览: 209
The error message " 'Dense' object has no attribute 'shape' " typically occurs when you are trying to access the shape attribute of a Dense layer in Keras or TensorFlow. However, Dense layers do not have a shape attribute because they do not have a fixed number of inputs or outputs - their shape depends on the input and output data.
To resolve this error, you can try removing the code where you are trying to access the shape attribute of the Dense layer, or you can try printing the output of the layer to see its dimensions. For example, you can use the following code to print the output shape of a Dense layer:
```
import tensorflow as tf
# Create a Dense layer
dense_layer = tf.keras.layers.Dense(10)
# Print the output shape of the layer
print(dense_layer(tf.zeros([1, 20])).shape)
```
This will print the shape of the output tensor of the Dense layer when given an input tensor of shape (1, 20).
阅读全文