简体   繁体   English

如何在 keras 中将密集层连接到 Conv2D

[英]How to Connect dense layer to Conv2D in keras

I want to map an input of 61 intensity values to an image of size 64×64.我想将 61 个强度值的输入 map 输入到大小为 64×64 的图像中。 The code I use is given below.我使用的代码如下。

Network Input=61×1 (intensity values)网络输入=61×1 (强度值)

OUTPUT=64×64 (image)输出=64×64 (图像)

input_img = Input(shape=(61,))

x = Dense(250, activation='relu')(input_img)
x = Dense(500, activation='relu')(x)
x = Dense(1000, activation='relu')(x)
x = Dense(4096, activation='relu')(x)

x=Conv2D(16,(3,3),padding='same',kernel_regularizer=regularizers.l2(0.001),kernel_initializer='glorot_uniform')(x)


x=Conv2D(1,(3,3),padding='same',kernel_regularizer=regularizers.l2(0.001),kernel_initializer='glorot_uniform')(x)


The dimensions are giving me problems.尺寸给我带来了问题。 How can I shape the dimensions in the code so that I can get correct mapping as 64×64 size at output.如何在代码中塑造尺寸,以便在 output 获得正确的映射为 64×64 大小。

The code error is ValueError: Input 0 is incompatible with layer conv2d_14: expected ndim=4, found ndim=2代码错误是 ValueError: Input 0 is in compatible with layer conv2d_14: expected ndim=4, found ndim=2

Thank you谢谢

The probable problem is input_img shape.可能的问题是input_img形状。

It should actually contain 3 dimensions.它实际上应该包含 3 个维度。 And internally keras will add the batch dimension making it 4.并且在内部 keras 将添加批次尺寸使其成为 4。

Since you used input_img with 1 dimensions (vector), keras is adding the 2nd.由于您使用了具有 1 个维度(向量)的input_img ,因此 keras 正在添加第 2 个维度。

You should correct the shape of your input_img您应该更正input_img的形状

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM