Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to visualize the ILSVRC mean image

I had an issue with how to visualize the ILSVRC mean image. I just wanted to look at it and see how much does it differ from using pixel-wise mean subtraction instead of image-wise mean subtraction.

I assume that you have already downloaded the CaffeNet pretrained and model definition files.

The trick is to initialize two networks, one with mean file set (called net_mean) and the other one without mean file (called net). Then create a fake all 1 image. Use the net_mean to preprocess the fake image for data layer and save the result as fake_pre. Then use the net to deprocess fake_pre for data layer and save it as fake_re. If the two networks net and net_mean were the same then fake_re would be equal to fake, but since we have not set any mean file for net then we can visualize the mean image using 1 - fake_re. Take a look at the code.

The result looks like this:

ILSVRC mean image

import caffe
import numpy as np
from matplotlib import pylab as plt
net = caffe.Classifier('/path/to/caffe/models/bvlc_reference_caffenet/deploy.prototxt',
channel_swap=(2, 1, 0), raw_scale=255)
net_mean = caffe.Classifier('/path/to/caffe/models/bvlc_reference_caffenet/deploy.prototxt',
channel_swap=(2, 1, 0), raw_scale=255)
fake = np.ones((227, 227, 3))
fake_pre = net_mean.preprocess('data', fake)
fake_re = net.deprocess('data', fake_pre)
mean_image = 1 - fake_re
Copy link

ih4cku commented Mar 9, 2015

It seems that the image link is not corrupted.
And, how would it affect the prediction result of using the two ways of mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment