Skip to content

Error in get_salient_feature_mask  #1

Open

Description

@gcordova19

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?

Activity

  1. nachiket273 commented on Aug 30, 2021

    @nachiket273
    Owner

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

  2. gcordova19 commented on Aug 30, 2021

    @gcordova19
    Author

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

  3. nachiket273 commented on Aug 30, 2021

    @nachiket273
    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.

  4. gcordova19 commented on Aug 30, 2021

    @gcordova19
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions