tyagi-iiitv / PointPillars

GNU General Public License v3.0
105 stars 47 forks source link

changing the Tensor shape? #36

Closed mariya12290 closed 3 years ago

mariya12290 commented 3 years ago

Hey,

I am trying to change the Tensor shape/kernel size based on paper. In the paper, it is mentioned that for pedestrian and cyclist, in Block1 stride should be 1. So I changed that stride, and also code in the detection head as you can see in the below code snippet.

` 
`   x = pillars`

    for n in range(4):

        S = (1, 1) if n == 0 else (1, 1)

        x = tf.keras.layers.Conv2D(nb_channels, (3, 3), strides=S, padding="same", activation="relu",
                                   name="cnn/block1/conv2d%i" % n)(x)

        x = tf.keras.layers.BatchNormalization(name="cnn/block1/bn%i" % n, fused=True)(x)

    x1 = x`

Detection head

occ = tf.keras.layers.Conv2D(nb_anchors, (1, 1), name="occupancy/conv2d", activation="sigmoid")(concat)

loc = tf.keras.layers.Conv2D(nb_anchors * 3, (1, 1), name="loc/conv2d", kernel_initializer=tf.keras.initializers.TruncatedNormal(0, 0.001))(concat)
#print(loc.shape)
#print(tuple(i//2 for i in image_size))

changes herefrom i//2 to i

loc = tf.keras.layers.Reshape(tuple(i for i in image_size) + (nb_anchors, 3), name="loc/reshape")(loc)

size = tf.keras.layers.Conv2D(nb_anchors * 3, (1, 1), name="size/conv2d", kernel_initializer=tf.keras.initializers.TruncatedNormal(0, 0.001))(concat)

size = tf.keras.layers.Reshape(tuple(i for i in image_size) + (nb_anchors, 3), name="size/reshape")(size)

angle = tf.keras.layers.Conv2D(nb_anchors, (1, 1), name="angle/conv2d")(concat)

heading = tf.keras.layers.Conv2D(nb_anchors, (1, 1), name="heading/conv2d", activation="sigmoid")(concat)

clf = tf.keras.layers.Conv2D(nb_anchors * nb_classes, (1, 1), name="clf/conv2d")(concat)
clf = tf.keras.layers.Reshape(tuple(i   for i in image_size) + (nb_anchors, nb_classes), name="clf/reshape")(clf)`


But now I am getting incompatible shape error while calculating loss like below.

`tensorflow.python.framework.errors_impl.InvalidArgumentError:  Incompatible shapes: [1,504,504,4,3] vs. [1,252,252,4,3]
         [[node gradient_tape/size_loss/huber_loss/BroadcastGradientArgs_5 (defined at point_pillars_training_run.py:67) ]] [Op:__inference_train_function_7712]`

I know the solution, but I am not able to find the place where I can change the shape of tensor in loss. I am pretty sure, it is somewhere in the loss.py.   

Can someone help me with this if possible?

Thanks in advance.
mariya12290 commented 3 years ago

Change the downscaling factor to 1 from 2 in config file.