nachiket273/Self_Driving_Car

Error in get_salient_feature_mask

gcordova19 opened this issue · 4 comments

Hello there,

I have executed your code in colab, but I have problems following the get_salient_feature_mask function. At the beginning of the loop, avg_actvn = np.mean (layer, axis = 3) .squeeze (axis = 0) returns this error
AxisError: axis 3 is out of bounds for array of dimension 2
Do you know why?

Hi, can you share here the input received by get_salient_feature_mask?

Could you follow the link https://colab.research.google.com/drive/1jGEyL-YI2GN2t09nlNMmofZLiA-nnJKE?usp=sharing ?

you mean layer_outs = functor([img.reshape(1, 66, 200, 3)])

Hi,

In your code for get_model(), you have commented out the first layer(normalization layer)

#model.add(Lambda(lambda x: x /127.5 - 1.0, input_shape = (utils.IMG_HT, utils.IMG_WIDTH, utils.IMG_CH)))

that in turn changes the layer numbers and it's significant for below code:

outputs = [layer.output for layer in model.layers][1:6]
inputs = model.input
functor = K.function([inputs], outputs)

In your case change "outputs = [layer.output for layer in model.layers][1:6]" to "outputs = [layer.output for layer in model.layers][0:5]" and it'll work.

I got an error AttributeError: module 'tensorflow' has no attribute 'Session' site:stackoverflow.com
So I add
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

and change line:
with tf.compat.v1.Session() as session:
res = session.run(deconv)

And I have this error:
IndexError Traceback (most recent call last)
in ()
14 img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
15
---> 16 mask = get_salient_feature_mask(layer_outs)
17 #stacked_mask = np.dstack((np.dstack((mask, mask)), mask))
18

in get_salient_feature_mask(ops)
61 output_shape = (IMG_HT, IMG_WIDTH)
62 else :
---> 63 output_shape = (layer_ops[i+1].shape[1], layer_ops[i+1].shape[2])
64 x = tf.constant(np.reshape(avg_actvn, (1, avg_actvn.shape[0], avg_actvn.shape[1], 1)), tf.float32)
65 deconv = tf.nn.conv2d_transpose(x, get_kernel(i),(1, output_shape[0], output_shape[1], 1), get_stride(i), padding='VALID')

IndexError: list index out of range

Should be related to commented out the first layer again?