caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Extracting features with Matlab script "matcaffe_demo.m"

Open caffecuda opened this issue 12 years ago • 10 comments

Hi,

I'm planning to use a pretrained ilsvrc12 model as a feature extractor for a new image dataset, and train svm classifiers for the new set. Is this sensible at all?

The "layers" output of the Matlab script "matcaffe_demo.m" has the following fields for the 8 layers, which of them should I use for my purpose? Many thanks.

[ 4-D single]
[96x1 single]

[  4-D single]
[256x1 single]

[  4-D single]
[384x1 single]

[  4-D single]
[384x1 single]

[  4-D single]
[256x1 single]

[9216x4096 single]
[4096x1    single]

[4096x4096 single]
[4096x1    single]

[4096x1000 single]
[1000x1    single]

caffecuda avatar May 21 '14 21:05 caffecuda

And the numbers in "layers" are the same for different images ("scores" are different for different images and they make sense), something is wrong?

caffecuda avatar May 21 '14 22:05 caffecuda

The layers are the CNN's weights, not the extracted features. The features from the output layer in the prototxt can be retrieved using the 'forward' command.

On Wed, May 21, 2014 at 3:32 PM, caffecuda [email protected] wrote:

And the numbers in "layers" are the same for different images ("scores" are different for different images and they make sense), something is wrong?

— Reply to this email directly or view it on GitHubhttps://github.com/BVLC/caffe/issues/432#issuecomment-43823021 .

http://www.cs.berkeley.edu/~rbg/

rbgirshick avatar May 22 '14 03:05 rbgirshick

Thanks for the reply. Is there any example Matlab script for extracting features at a specific layer? "scores = caffe('forward', input_data);" returns only output of the last layer ie the probabilities.

caffecuda avatar May 22 '14 10:05 caffecuda

@rbgirshick In particular to extract features that are good for classification, in the imagenet_deploy.prototxt file should I keep layers up to "fc7", or "relu7", or "drop7"? Many thanks!

caffecuda avatar May 28 '14 17:05 caffecuda

While extracting features, the net is in Test mode, and therefore drop7 don't do anything, so you can leave it for take it out. But you should definitely keep relu7, it would make the features more sparse. Although you could do it later in Matlab.

Sergio

2014-05-28 10:44 GMT-07:00 caffecuda [email protected]:

@rbgirshick https://github.com/rbgirshick In particular to extract features that are good for classification, in the imagenet_deploy.prototxt file should I keep layers up to "fc7", or "relu7", or "drop7"? Many thanks!

— Reply to this email directly or view it on GitHubhttps://github.com/BVLC/caffe/issues/432#issuecomment-44440860 .

sguada avatar May 28 '14 18:05 sguada

@sguada Thanks for the explanation. When used as a feature extractor for new dataset, I noticed that keeping relu7 also helps the classification performance, is this always the case? Is relu7 the best feature (for classification), or lower layers can be better?

caffecuda avatar May 28 '14 19:05 caffecuda

It depends on the task, in some cases, fc6 or even pool5 perform better. Take a look into http://arxiv.org/abs/1310.1531

I think keeping relu always help, since the network was trained in that way, and therefore the negative values are noisy.

Sergio

2014-05-28 12:42 GMT-07:00 caffecuda [email protected]:

@sguada https://github.com/sguada Thanks for the explanation. When used as a feature extractor for new dataset, I noticed that keeping relu7 also helps the classification performance, is this always the case? Is relu7 the best feature (for classification), or lower layers can be better?

— Reply to this email directly or view it on GitHubhttps://github.com/BVLC/caffe/issues/432#issuecomment-44454783 .

sguada avatar May 28 '14 19:05 sguada

@sguada Thanks. And I suppose I can use the mean of the features for the 10 crops as the feature for an image?

caffecuda avatar May 28 '14 19:05 caffecuda

I guess you could, although not sure how well it would work if you do mean of pool5 features to represent an image. You could just use the central crop if you want to save computation.

Sergio

2014-05-28 12:57 GMT-07:00 caffecuda [email protected]:

@sguada https://github.com/sguada Thanks. And I suppose I can use the mean of the features for the 10 crops as the feature for an image?

— Reply to this email directly or view it on GitHubhttps://github.com/BVLC/caffe/issues/432#issuecomment-44456447 .

sguada avatar May 29 '14 07:05 sguada

@caffecuda take a look to the new MatCaffe #501

sguada avatar Jun 16 '14 17:06 sguada