Keras:乘以常数

时间:2019-01-31 16:45:37

标签: python tensorflow keras

在Keras中,输入x*a是否可能size(None, None, 3)?例如,输入xconstant a: x(batch,None,None,1024)*a(batch,1)

我在训练中使用输入size (64, 64, 3),但测试数据应使用可变的输入大小。无法调整测试尺寸以进行公平的图像处理。

我尝试使用Lambda function(lambda x : x * a)(seq)。然后,我在代码中没有问题。然后,启动model.fit函数,出现错误:

------------->>tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [7,4,4,1024] vs. [7,1]. 

conv5 = Conv2D(1024, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(pool4)
conv5 = Conv2D(1024, 3, activation = 'relu', padding = 'same', kernel_initializer = 'he_normal')(conv5)

conv_c = Conv2D(num_classes, 1, activation='softmax')(conv5)
conv_c1 = GlobalAveragePooling2D(name="class_output")(conv_c)

conv_c1_1 = conv_c1[:, 0:1]
conv_c1_2 = conv_c1[:, 1:2]
conv_c1_3 = conv_c1[:, 2:3]

conv5_b = Lambda(lambda x: x * conv_c1_1)(conv5) #conv5:Tensor(shape=(?, 4, 4, 1024))
conv5_h = Lambda(lambda x: x * conv_c1_2)(conv5) #conv_c1_1: Tensor(shape=(?, 1))
conv5_r = Lambda(lambda x: x * conv_c1_3)(conv5)

0 个答案:

没有答案