1
我正在将项目从Keras 1.x迁移到2.x.将keras.backend.conv2d从Keras 1.x迁移到2.x
在代码中,在1.x中正常运行的keras.backend.conv2d
操作现在在2.x中崩溃。
convs = K.conv2d(a, b, padding='valid', data_format='channels_first')
输入张量形状a
和b
均为(1024, 4, 1, 1)
和输出张量形状1.x中是(1024, 1024, 1, 1)
2.x版,我发现了以下错误:
ValueError: CorrMM: impossible output shape
bottom shape: 1024 x 4 x 1 x 1
weights shape: 1 x 1 x 1024 x 4
top shape: 1024 x 1 x -1022 x -2
Apply node that caused the error: CorrMM{valid, (1, 1), (1, 1), 1 False}(Print{message='a', attrs=('__str__',), global_fn=<function DEBUG_printTensorShape at 0x00000272EF1FAD08>}.0, Subtensor{::, ::, ::int64, ::int64}.0)
Toposort index: 30
Inputs types: [TensorType(float32, (False, False, True, True)), TensorType(float32, (True, True, False, False))]
Inputs shapes: [(1024, 4, 1, 1), (1, 1, 1024, 4)]
我使用Theano后端,并在K.set_image_data_format
和conv2d
设置channels_first
两者。
'K.permute_dimensions(x,(3,2,1,0))'完成了这项工作。谢谢 ! – Overdrivr