123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- function [ features ] = caffe_features_single_image( i_image, f_mean, net, settings )
-
- if (nargin<2)
- error ( 'no mean passed');
- end
- if (nargin<3)
- error ( 'no network passed');
- end
- if (nargin<4)
- settings = [];
- end
-
-
- s_layer = getFieldWithDefault ( settings, 's_layer', 'relu7');
- b_apply_bilinear_pooling = getFieldWithDefault ( settings, 'b_apply_bilinear_pooling', false );
- b_skip_normalization_in_bilinear_pooling ...
- = getFieldWithDefault ( settings, 'b_skip_normalization_in_bilinear_pooling', false );
- b_apply_log_M = getFieldWithDefault ( settings, 'b_apply_log_M', false );
- f_sigma = getFieldWithDefault ( settings, 'f_sigma', 1e-5 );
-
-
-
-
- data = caffe_prepare_image( i_image, f_mean );
-
-
- net_input_shape = net.blobs('data').shape;
- i_batch_size = net_input_shape(4);
-
- assert ( i_batch_size == 1, 'network not reshaped for passing only a single image' );
-
-
- [~] = net.forward({data});
-
-
- features = net.blobs( s_layer ).get_data();
-
-
- if ( b_apply_bilinear_pooling )
-
-
-
-
-
- if ( ndims ( features ) == 3 )
- i_channelCount = size ( features, 3);
-
-
- features = reshape ( features, [],i_channelCount);
-
-
-
-
- if ( ~b_skip_normalization_in_bilinear_pooling )
-
-
-
-
-
-
- features = bsxfun(@times, features, 1./( max( 10e-8, sqrt(sum(features,2).^2) ) ) );
- end
-
- features = features'*features;
- else
- features = features / sqrt(sum(features)^2);
- features = features*features';
- end
-
- if ( b_apply_log_M )
- features = logm( features + f_sigma*eye( size(features) ) );
- end
-
-
-
- features = features ( logical(tril(ones(size(features)))));
-
-
- features = sign(features).*sqrt(abs(features));
-
-
- features = features / sqrt(sum(features.^2));
-
-
- else
-
- features = reshape( features, ...
- size(features,1)*size(features,2)*size(features,3), ...
- size(features,4)...
- );
- end
-
-
-
- features = double(features);
- end
|