demo on how to get net weights using the matlab interface
[platform/upstream/caffeonacl.git] / matlab / caffe / matcaffe_demo_weights.m
1 function layers = matcaffe_demo_weights(use_gpu)
2 % layers = matcaffe_demo_weights(use_gpu)
3
4 % Demo of how to extract network parameters ("weights") using the matlab
5 % wrapper.
6 %
7 % input
8 %   use_gpu  1 to use the GPU, 0 to use the CPU
9 %
10 % output
11 %   layers   struct array of layers and their weights
12 %
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
15 %  $ export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
16 % Or the equivalent based on where things are installed on your system
17
18 % init caffe network (spews logging info)
19 if caffe('is_initialized') == 0
20   model_def_file = '../../examples/imagenet_deploy.prototxt';
21   model_file = '../../examples/alexnet_train_iter_470000';
22   caffe('init', model_def_file, model_file);
23 end
24
25 % set to use GPU or CPU
26 if exist('use_gpu', 'var') && use_gpu
27   caffe('set_mode_gpu');
28 else
29   caffe('set_mode_cpu');
30 end
31
32 % put into test mode
33 caffe('set_phase_test');
34
35 layers = caffe('get_weights');