python - ValueError: 层 max_pooling2d_12 的输入 0 与层不兼容:预期 ndim=4,发现 ndim=0。收到的完整形状:[]
问题描述
我该如何解决这个错误?
ValueError: Input 0 of layer max_pooling2d_12 is incompatible with the layer: expected ndim=4, found ndim=0. Full shape received: []
我已经尝试了所有值,例如 conv 、 inputs 和 ....
# UNQ_C1
# GRADED FUNCTION: conv_block
def conv_block(inputs=(96,128,3), n_filters=32, dropout_prob=0, max_pooling=True):
"""
Convolutional downsampling block
Arguments:
inputs -- Input tensor
n_filters -- Number of filters for the convolutional layers
dropout_prob -- Dropout probability
max_pooling -- Use MaxPooling2D to reduce the spatial dimensions of the output volume
Returns:
next_layer, skip_connection -- Next layer and skip connection outputs
"""
### START CODE HERE
conv = Conv2D(32, # Number of filters
3, # Kernel size
activation='relu',
padding='same',
kernel_initializer='he_normal')(inputs)
conv = Conv2D(32, # Number of filters
3, # Kernel size
activation='relu',
padding='same',
kernel_initializer='he_normal')(conv)
### END CODE HERE
# if dropout_prob > 0 add a dropout layer, with the variable dropout_prob as parameter
if dropout_prob > 0:
### START CODE HERE
conv = dropout_prob
### END CODE HERE
# if max_pooling is True add a MaxPooling2D with 2x2 pool_size
if max_pooling:
### START CODE HERE
next_layer = tf.keras.layers.MaxPooling2D(pool_size=(2,2))(conv)
### END CODE HERE
else:
next_layer = conv
skip_connection = conv
return next_layer, skip_connection
解决方案
我认为问题在于您正在分配
conv = dropout_prob
所以 conv 是 tensorflow 的一个实例,而 dropout_prob 是一个数字,问题是你必须添加一个 dropout 层,变量 dropout_prob 作为参数。不设置它等于参数。
右行是:
conv = tf.keras.layers.Dropout(dropout_prob)(conv)
推荐阅读
- javascript - 如何通过 div 将点击传递到其下方不相关的 div 并触发两个 div 的 onClick 侦听器?
- google-chrome - 本地托管的 HTTPS 站点给出有关 websocket 的 Chrome 错误(使用 ParcelJS 包时)
- node.js - Docker compose 未正确复制文件以运行反应应用程序
- db2 - 无法将数据插入到 IDAA 服务器中的 AOT(仅加速表)表中
- android - 如何使用 volley 访问 json 数据?
- python - 在 Celery - Python 中的进程(工作者)之间共享数据的最佳解决方案是什么?
- php - 防止日志中的重复条目
- python-3.x - 评估功能没有返回正确答案?
- android - Android - 即时更改语言
- mysql - 如何在 CASE 中有 AS 别名