|  | 
| 1 |  | -function scores = matcaffe_demo(im, use_gpu) | 
|  | 1 | +function [scores, layers] = matcaffe_demo(im, use_gpu) | 
| 2 | 2 | % scores = matcaffe_demo(im, use_gpu) | 
| 3 | 3 | % | 
| 4 | 4 | % Demo of the matlab wrapper using the ILSVRC network. | 
|  | 
| 11 | 11 | %   scores   1000-dimensional ILSVRC score vector | 
| 12 | 12 | % | 
| 13 | 13 | % You may need to do the following before you start matlab: | 
| 14 |  | -%  $ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/usr/local/cuda/lib64 | 
|  | 14 | +%  $ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/usr/local/cuda-5.5/lib64 | 
| 15 | 15 | %  $ export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 | 
| 16 | 16 | % Or the equivalent based on where things are installed on your system | 
| 17 | 17 | % | 
|  | 
| 20 | 20 | %  scores = matcaffe_demo(im, 1); | 
| 21 | 21 | %  [score, class] = max(scores); | 
| 22 | 22 | 
 | 
| 23 |  | -model_def_file = '../../examples/imagenet/imagenet_deploy.prototxt'; | 
| 24 |  | -% NOTE: you'll have to get the pre-trained ILSVRC network | 
| 25 |  | -model_file = '../../examples/imagenet/caffe_reference_imagenet_model'; | 
| 26 |  | - | 
| 27 | 23 | % init caffe network (spews logging info) | 
| 28 |  | -caffe('init', model_def_file, model_file); | 
|  | 24 | +if caffe('is_initialized') == 0 | 
|  | 25 | +  model_def_file = '../../examples/imagenet/imagenet_deploy.prototxt'; | 
|  | 26 | +  model_file = '../../examples/imagenet/caffe_reference_imagenet_model'; | 
|  | 27 | +  if exist(model_file, 'file') == 0 | 
|  | 28 | +    % NOTE: you'll have to get the pre-trained ILSVRC network | 
|  | 29 | +    error('You need a network model file'); | 
|  | 30 | +  end | 
|  | 31 | +  caffe('init', model_def_file, model_file); | 
|  | 32 | +end | 
| 29 | 33 | 
 | 
| 30 | 34 | % set to use GPU or CPU | 
| 31 | 35 | if exist('use_gpu', 'var') && use_gpu | 
|  | 
| 51 | 55 | scores = reshape(scores{1}, [1000 10]); | 
| 52 | 56 | scores = mean(scores, 2); | 
| 53 | 57 | 
 | 
|  | 58 | +% you can also get network weights by calling | 
|  | 59 | +layers = caffe('get_weights'); | 
| 54 | 60 | 
 | 
| 55 | 61 | % ------------------------------------------------------------------------ | 
| 56 | 62 | function images = prepare_image(im) | 
|  | 
0 commit comments