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

Examples_core.ipynb doesn't work #73

Closed
alfredonuhe opened this issue Jul 17, 2021 · 2 comments
Closed

Examples_core.ipynb doesn't work #73

alfredonuhe opened this issue Jul 17, 2021 · 2 comments

Comments

@alfredonuhe
Copy link

Hi, I am running the core example code for Vanilla Gradient & SmoothGrad on a Kaggle notebook, and I get the error below:


ValueError Traceback (most recent call last)
in
6 ShowImage(im_orig)
7
----> 8 _, predictions = model(np.array([im]))
9 prediction_class = np.argmax(predictions[0])
10 call_model_args = {class_idx_str: prediction_class}

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
996 inputs = self._maybe_cast_inputs(inputs, input_list)
997
--> 998 input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
999 if eager:
1000 call_fn = self.call

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
272 ' is incompatible with layer ' + layer_name +
273 ': expected shape=' + str(spec.shape) +
--> 274 ', found shape=' + display_shape(x.shape))
275
276

ValueError: Input 0 is incompatible with layer model_1: expected shape=(None, 224, 224, 3), found shape=(1, 224, 224, 4)


Here is the kaggle notebook with the error.

The only lines I have modified in the example are:

# From our repository.
import saliency.core as saliency

and

# Load the image
im_orig = LoadImage('./doberman.png')

as

# From our repository.
try:
    import saliency.core as saliency`
except:
    ! pip install saliency
    import saliency.core as saliency`

and

# Load the image
im_orig = LoadImage('../input/saliency-imgs/doberman.png')

Also, I have seen there was an issue (#5) created for the code examples to be adapted to TF2. But since the current title of the examples states "for TF2 and other frameworks" I assume the code was finally adapted, and this issue isn't relevant anymore for the problem I am describing.

Thank you.

@joydisette
Copy link

@alfredonuhe You need to load jpg images or convert your png to jpg to remove a dimension

@bwedin
Copy link
Collaborator

bwedin commented Jul 27, 2021

Yes it looks like your version of the image has an extra alpha layer (RGBA image rather than RGB). You could do as @joydisette suggested above (convert to JPG, or convert to a PNG with no alpha/transparency layer). Alternatively, you could remove the extra alpha channel from the numpy array directly:

im_rgba = LoadImage('../input/saliency-imgs/doberman.png') im_rgb = im_rgba[:,:,:3] im = PreprocessImage(im_rgb)

Let us know if you are still having issues. Thanks!

@bwedin bwedin closed this as completed Jul 28, 2021
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

3 participants