<p>You cannot do the following line apparently</p>

<pre><code>dog_img = dog_img[:, :, 0:3]   # Opera has added alpha channel
</code></pre>

<p>So I loaded the image using a utility in Keras called <code>load_img</code>, which doesn't add the alpha channel.</p>

<p>The complete code </p>

<pre><code>import imageio
from matplotlib import pyplot as plt
from skimage.transform import resize
import numpy as np
from keras import activations
from keras.applications import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input, decode_predictions

# Build the VGG16 network with ImageNet weights
model = VGG16(weights='imagenet', include_top=True)
dog_img = image.img_to_array(image.load_img(r"F:\tmp\Opera Snapshot_2018-09-24_133452_arxiv.org.png", target_size=(224, 224)))

x = np.expand_dims(dog_img, axis=0)
x = preprocess_input(x)

pred = model.predict(x)
print(decode_predictions(pred))

[[('n02108089', 'boxer', 0.29122102), ('n02108422', 'bull_mastiff', 0.199128), ('n02129604', 'tiger', 0.10050287), ('n02123159', 'tiger_cat', 0.09733449), ('n02109047', 'Great_Dane', 0.056869864)]]   
</code></pre>
Poor accuracy of Keras VGG16 while reproducing paper results
<p>I'm trying to reproduce some results from the <a href="https://arxiv.org/pdf/1610.02391.pdf" rel="nofollow noreferrer">paper, describing Grad-CAM method</a>, using Keras with Tensorflow-GPU backend, and obtain totally incorrect labels.</p>

<p>I've captured the screenshot of figure 1(a) from that paper and trying to make the pretrained VGG16 from Keras Applications to classify it.</p>

<p>Here is my image:</p>

<p><a href="https://i.stack.imgur.com/utqcY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/utqcY.png" alt="snapshot"></a></p>

<p>Here is my code (cell from the Jupyter notebook). Part of code was copied from the <a href="https://keras.io/applications/#vgg16" rel="nofollow noreferrer">Keras manuals</a></p>

<pre><code>import imageio
from matplotlib import pyplot as plt
from skimage.transform import resize

from keras import activations
from keras.applications import VGG16
from keras.applications.vgg16 import preprocess_input, decode_predictions

# Build the VGG16 network with ImageNet weights
model = VGG16(weights='imagenet', include_top=True)

%matplotlib inline

dog_img = imageio.imread(r"F:\tmp\Opera Snapshot_2018-09-24_133452_arxiv.org.png")
dog_img = dog_img[:, :, 0:3]   # Opera has added alpha channel
dog_img = resize(dog_img, (224, 224, 3))

x = np.expand_dims(dog_img, axis=0)
x = preprocess_input(x, mode='tf')

pred = model.predict(x)
decode_predictions(pred)
</code></pre>

<p>Output: </p>

<pre><code>[[('n03788365', 'mosquito_net', 0.017053505),
  ('n03291819', 'envelope', 0.015034639),
  ('n15075141', 'toilet_tissue', 0.012603286),
  ('n01737021', 'water_snake', 0.010620943),
  ('n04209239', 'shower_curtain', 0.009625845)]]
</code></pre>

<p>However, when I submit the same image to the online service, run by the paper authors, <a href="http://gradcam.cloudcv.org/classification" rel="nofollow noreferrer">http://gradcam.cloudcv.org/classification</a>, I see correct label "Boxer"</p>

<p>Here is the output from something that they call "Terminal":</p>

<pre><code>Completed the Classification Task

"Time taken for inference in torch: 9.0"
"Total time taken: 9.12565684319"
{"classify_gcam": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gcam_243.png", "execution_time": 9.0, "label": 243.0, "classify_gb_gcam": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gb_gcam_243.png", "classify_gcam_raw": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gcam_raw_243.png", "input_image": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/Opera Snapshot_2018-09-24_133452_arxiv.org.png", "pred_label": 243.0, "classify_gb": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gb_243.png"}
Completed the Classification Task

"Time taken for inference in torch: 9.0"
"Total time taken: 9.05940508842"
{"classify_gcam": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gcam_243.png", "execution_time": 9.0, "label": 243.0, "classify_gb_gcam": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gb_gcam_243.png", "classify_gcam_raw": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gcam_raw_243.png", "input_image": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/Opera Snapshot_2018-09-24_133452_arxiv.org.png", "pred_label": 243.0, "classify_gb": "./media/grad_cam/classification/86560f84-bfe5-11e8-a657-22000b4a9274/classify_gb_243.png"}
Job published successfully
Publishing job to Classification Queue
Starting classification job on VGG_ILSVRC_16_layers.caffemodel
Job published successfully
Publishing job to Classification Queue
Starting classification job on VGG_ILSVRC_16_layers.caffemodel
</code></pre>

<p>I use Anaconda Python 64-bit, on Windows 7. </p>

<p>Versions of relevant software on my PC:</p>

<pre><code>keras                     2.2.2                         0
keras-applications        1.0.4                    py36_1
keras-base                2.2.2                    py36_0
keras-preprocessing       1.0.2                    py36_1
tensorflow                1.10.0          eigen_py36h849fbd8_0
tensorflow-base           1.10.0          eigen_py36h45df0d8_0
</code></pre>

<p>What am I doing wrong? How can I get boxer label?</p>