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

visualize_saliency breaks down if input_shape is (None, None, 3) #95

Closed
2 tasks done
lucasdavid opened this issue Mar 4, 2018 · 1 comment
Closed
2 tasks done

Comments

@lucasdavid
Copy link

My network accepts images of variable height and width, which can be represented by x = Input(1, None, None, 3). Invoking the vis.visualization.visualize_saliency on this network will throw the following error:

ValueError: Cannot feed value of shape (1, 3, 235, 224) for Tensor 'input_1_2:0', which has shape '(?, ?, ?, 3)'

I believe the problem is in Optimizer._get_seed_input(seed_input) (optimizer.py L95, on master), where an assumption incorrectly swaps the channel dim from its correct position to an incorrect one:

# Only possible if channel idx is out of place.
if seed_input.shape != desired_shape:
    seed_input = np.moveaxis(seed_input, -1, 1)
return seed_input.astype(K.floatx())

For example, let's say I'm feeding an image of (423, 451, 3). seed_input.shape == (1, 423, 451, 3) != (1, None, None, 3) == desired_shape will pass and seed_input.shape will become (1, 3, 451, 423).

This can be corrected by removing this condition and assuming the user knows what to input. However, if this condition must be kept, then maybe we could make this checking more strict. Something in the lines of:

channels = 1 if K.image_data_format() == 'channels_first' else -1
if seed_input.shape[channels] != desired_shape[channels]:
    seed_input = np.moveaxis(seed_input, -1, 1)
  • Check that you are up-to-date with the master branch of keras-vis. You can update with:
    pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps
  • If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.
@lucasdavid
Copy link
Author

duplicate of #90

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

1 participant