Quantcast
Channel: Concat OP in Tensorflow2.0.0 - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Concat OP in Tensorflow2.0.0

$
0
0

I tried to use Tensorflow2.0 to implement some deep learning alogrithms.

However, the problem i met seems weried. It's a dimension problem when concating tensors

The source code is right here

import tensorflow as tf
import numpy as np


image = tf.keras.layers.Input(shape=(224, 224, 6), name='image')
conv1_2 = tf.keras.layers.Input(shape=(224, 224, 64), name='block1_conv2')
conv2_2 = tf.keras.layers.Input(shape=(112, 112, 128), name='block2_conv2')
conv3_4 = tf.keras.layers.Input(shape=(56, 56, 256), name='block3_conv4')
conv4_4 = tf.keras.layers.Input(shape=(28, 28, 512), name='block4_conv4')
conv5_4 = tf.keras.layers.Input(shape=(14, 14, 512), name='block5_conv4')

x = image
for merge_input in [conv1_2, conv2_2, conv3_4, conv4_4, conv5_4]:
    x = tf.keras.layers.Concatenate()([x, merge_input])
    x = tf.keras.layers.Conv2D(filters=56,
                               kernel_size=2,
                               padding='same',
                               activation='relu',
                               kernel_initializer=tf.initializers.he_normal())(x)
    # x = tf.keras.layers.Dropout(self.keep_prob)(x)
    x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2))(x)

model = tf.keras.Model(inputs=[image, conv1_2, conv2_2, conv3_4, conv4_4, conv5_4], outputs=x)

i = np.random.randn(1, 224, 224, 6)
c1 = np.random.randn(1, 224, 224, 64)
c2 = np.random.randn(1, 112, 112, 128)
c3 = np.random.randn(1, 56, 56, 256)
c4 = np.random.randn(1, 28, 28, 512)
c5 = np.random.randn(1, 14, 14, 512)

Q_value = model({'image': i,
                 'block1_conv2': c1,
                 'block2_conv2': c2,
                 'block3_conv4': c3,
                 'block4_conv4': c4,
                 'block5_conv4': c5})

The error implicated by the interpreter is :

ConcatOp : Dimensions of inputs should match: shape[0] = [1,224,224,64] vs. shape[1] = [1,112,112,128] [Op:ConcatV2] name: concat

Dimensions of tensors are matched when concating

Would someone have any idea about this problem?

Thanks a lot.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images