简体   繁体   English

Keras UNet Conv2DTranspose 零维数组错误

[英]Keras UNet Conv2DTranspose Zero-dimensional array error

I have a rather simple / standard Unet architecture which looks like the following:我有一个相当简单/标准的 Unet 架构,如下所示:

radar_input_layer = layers.Input(shape=(tdata.shape[1],tdata.shape[2],tdata.shape[3]))

    print(radar_input_layer.shape)

    c1 = layers.Conv2D(neurons, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(radar_input_layer)
    c1 = layers.Dropout(0.5)(c1)
    c1 = layers.Conv2D(neurons, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(c1)
    p1 = layers.MaxPooling2D((2,2))(c1)

    print(p1.shape)

    c2 = layers.Conv2D(neurons * 2, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(p1)
    c2 = layers.Dropout(0.5)(c2)
    c2 = layers.Conv2D(neurons * 2, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(c2)
    p2 = layers.MaxPooling2D((2,2))(c2)

    print(p2.shape)

    c3 = layers.Conv2D(neurons * 4, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(p2)
    c3 = layers.Dropout(0.5)(c3)
    c3 = layers.Conv2D(neurons * 4, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(c3)
    p3 = layers.MaxPooling2D((2,2))(c3)

    print(p3.shape)

    c4 = layers.Conv2D(neurons * 8, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(p3)
    c4 = layers.Dropout(0.5)(c4)
    c4 = layers.Conv2D(neurons * 8, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(c4)
    p4 = layers.MaxPooling2D((2,2))(c4)

    print(p4.shape)

    c5 = layers.Conv2D(neurons * 16, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(p4)
    c5 = layers.Dropout(0.5)(c5)
    c5 = layers.Conv2D(neurons * 16, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(c5)

    print(c5.shape)
    u1 = layers.Conv2DTranspose(neurons * 8, (2,2), strides=(2,2), padding='same')(c5)

    print(u1.shape)
    print(c4.shape)

    u1 = np.concatenate([u1,c4])
    c6 = layers.Conv2D(neurons * 8, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(u1)
    c6 = layers.Dropout(0.5)(c6)
    c6 = layers.Conv2D(neurons * 8, (3,3), activation='relu', kernel_initializer='he_normal',padding='same')(c6)

    ...

I have defined my tdata and # of neurons as:我已将我的 tdata 和神经元数量定义为:

tdata = np.zeros([100,450,552,2])
neurons = 16

Just as a sample test dataset, where channels = last in the above tdata example (ie, 100 samples, 450 rows, 552 columns).就像一个样本测试数据集,在上面的 tdata 示例中,channels = last(即 100 个样本,450 行,552 列)。

The output is as follows:输出如下:

(?, 225, 276, 16)
(?, 112, 138, 32)
(?, 56, 69, 64)
(?, 28, 34, 128)
(?, 28, 34, 256)
(?, ?, ?, 128)
(?, 56, 69, 128)
Traceback (most recent call last):
ValueError: zero-dimensional arrays cannot be concatenated

therefore, the problem is being hung up on concatenating u1 and c4.因此,问题在于连接 u1 和 c4。 More specifically, the problem is that u1 is not defined as having an actual shape (?,?,?,128) when it should be (?,56,69,128).更具体地说,问题是 u1 没有定义为具有实际形状 (?,?,?,128),而应该是 (?,56,69,128)。 Why aren't the dimensions carrying through with this example, and how can this be fixed?为什么尺寸没有在这个例子中体现出来,如何解决这个问题?

Make sure you have updated versions of Keras or Tensorflow.确保您有 Keras 或 Tensorflow 的更新版本。 I got following output from your code.我从你的代码中得到了以下输出。

(None, 450, 552, 2)
(None, 225, 276, 16)
(None, 112, 138, 32)
(None, 56, 69, 64)
(None, 28, 34, 128)
(None, 28, 34, 256)
(None, 56, 68, 128)
(None, 56, 69, 128)

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

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