实现可输入权重的卷积和反卷积
Created by: Angus07
现在想实现 Z = conv2d(X, W) 和 X = conv2d_transpose(Z, W) 期望conv2d和conv2d_transpose互为逆操作。X, W,Z均可直接从外部输入。
Z = conv2d(X, W)已经实现如下: l_type = 'conv2d' helper = LayerHelper(l_type, **locals()) dtype = helper.input_dtype() padding =0 stride=1 stride = layers.utils.convert_to_list(stride, 2, 'stride') padding = layers.utils.convert_to_list(padding, 2, 'padding') pre_bias = helper.create_variable_for_type_inference(dtype) helper.append_op( type=l_type, inputs={ 'Input': X, 'Filter': W, }, outputs={"Output": Z}, attrs={ 'strides': stride, 'paddings': padding, 'use_cudnn': True, 'use_mkldnn': False, 'fuse_relu_before_depthwise_conv': False, } )
下面继续实现反conv op_type = 'conv2d_transpose' helper = LayerHelper(op_type, **locals()) C = helper.create_variable_for_type_inference(dtype) helper.append_op( type=op_type, inputs={'Input': [Z], 'Filter': [W]}, outputs={'Output': C}, attrs={ 'output_size': X.shape, 'strides': stride, 'paddings': padding, 'use_cudnn': True, }) 报错如下: 如果按照报错信息,把stride扩展到[1,1,1,1],一样报错