python-3.x - Keras 中用于 2d 卷积层的 merge() 函数的类型错误
问题描述
我正在尝试重新创建 Inception 模型版本 4。但我想在我的图像数据集标准形状上对其进行训练(224,224,3)
,因此我没有采用任何预训练的权重。但我收到这样的错误。
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
TypeError: 'module' object is not callable
这是代码:
def inception_stem(input):
if K.image_dim_ordering() == "th":
channel_axis = 1
else:
channel_axis = -1
# Input Shape is 299 x 299 x 3 (th) or 3 x 299 x 299 (th)
x = conv_block(input, 32, 3, 3, subsample=(2, 2), border_mode='valid')
x = conv_block(x, 32, 3, 3, border_mode='valid')
x = conv_block(x, 64, 3, 3)
x1 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x2 = conv_block(x, 96, 3, 3, subsample=(2, 2), border_mode='valid')
x = tf.concat([x1,x2],axis=channel_axis)
#x = merge([x1, x2], mode='concat', concat_axis=channel_axis) #here is the error occuring try find out the reason behind it
x1 = conv_block(x, 64, 1, 1)
x1 = conv_block(x1, 96, 3, 3, border_mode='valid')
x2 = conv_block(x, 64, 1, 1)
x2 = conv_block(x2, 64, 1, 7)
x2 = conv_block(x2, 64, 7, 1)
x2 = conv_block(x2, 96, 3, 3, border_mode='valid')
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
x1 = conv_block(x, 192, 3, 3, subsample=(2, 2), border_mode='valid')
x2 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(x)
x = merge([x1, x2], mode='concat', concat_axis=channel_axis)
return x
我正在使用python 3.6
, keras 2.2.2
, tensorflow-gpu 1.9.0
.
我关注了 GitHub 的问题,但答案并不明确和准确。 任何人都可以找到解决方案。
解决方案
使用连接层,这应该可以帮助你
from tensorflow.python.keras.layers import concatenate
x = concatenate([x1, x2], axis=channel_axis)
return x
推荐阅读
- vue.js - Vuex 状态更改未更新 Vuetify 表
- javascript - 如何在 React 中制作动态单选按钮?
- authentication - 使用表单身份验证时使公共页面可访问
- amazon-web-services - 不了解 AWS Amplify 身份验证流程
- fail2ban - Fail2ban 不禁止错误的私钥文件登录尝试
- python-3.x - python Huffman 编码成本
- html - 显示带有新行的内联错误消息
- mysql - 如何在 UwAmp 中升级 MySQL?
- angular - FormControl 在 mat-multiselect-Angular Material 中无法正常工作
- nginx - Nginx代理请求返回404,直接访问返回200