Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in get_salient_feature_mask #1

Open
gcordova19 opened this issue Aug 30, 2021 · 4 comments
Open

Error in get_salient_feature_mask #1

gcordova19 opened this issue Aug 30, 2021 · 4 comments

Comments

@gcordova19
Copy link

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?

@nachiket273
Copy link
Owner

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

@gcordova19
Copy link
Author

gcordova19 commented Aug 30, 2021

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)])

@nachiket273
Copy link
Owner

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.

@gcordova19
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants