Changes for 1.12 release
[platform/adaptation/npu/intel-libmvnc.git] / examples / caffe / SqueezeNet / Makefile
1
2 ifneq ($(findstring movidius, $(PYTHONPATH)), movidius)
3         export PYTHONPATH:=/opt/movidius/caffe/python:$(PYTHONPATH)
4 endif
5
6 NCCOMPILE = mvNCCompile
7 NCPROFILE = mvNCProfile
8 NCCHECK   = mvNCCheck
9
10
11 PROTOTXT_FILENAME= deploy.prototxt
12 GET_PROTOTXT = wget -P . https://github.com/DeepScale/SqueezeNet/raw/master/SqueezeNet_v1.0/${PROTOTXT_FILENAME}
13
14 CAFFEMODEL_FILENAME = squeezenet_v1.0.caffemodel
15 GET_CAFFEMODEL = wget -P . -N https://github.com/DeepScale/SqueezeNet/raw/master/SqueezeNet_v1.0/${CAFFEMODEL_FILENAME}
16
17
18 .PHONY: all
19 all: profile check compile cpp
20
21 .PHONY: prereqs
22 prereqs:
23         @echo "\nmaking prereqs"
24         (cd ../../data/ilsvrc12; make)
25         @sed -i 's/\r//' run.py
26         @chmod +x run.py
27         @if [ -e LICENSE.squeezenet ] ; \
28         then \
29                 echo "LICENSE file already exists"; \
30         else \
31                 echo "Downloading LICENSE file"; \
32                 wget -P . -N https://github.com/DeepScale/SqueezeNet/raw/master/LICENSE; mv LICENSE LICENSE.squeezenet; \
33         fi ; \
34
35
36 .PHONY: prototxt
37 prototxt: prereqs
38         @echo "\nmaking prototxt"
39         @if [ -e ${PROTOTXT_FILENAME} ] ; \
40         then \
41                 echo "Prototxt file already exists"; \
42         else \
43                 echo "Downloading Prototxt file"; \
44                 ${GET_PROTOTXT}; \
45                 if [ -e ${PROTOTXT_FILENAME} ] ; \
46                 then \
47                         echo "modifying prototxt file."; \
48                         sed -i '11s/10/1/' ${PROTOTXT_FILENAME}; sed -i '530s/pad/#pad/' ${PROTOTXT_FILENAME}; \
49                 else \
50                         echo "***\nError - Could not download prototxt file. Check network and proxy settings \n***\n"; \
51                         exit 1; \
52                 fi ; \
53         fi  
54
55 .PHONY: caffemodel
56 caffemodel: 
57         @echo "\nmaking caffemodel"
58         @if [ -e ${CAFFEMODEL_FILENAME} ] ; \
59         then \
60                 echo "caffemodel file already exists"; \
61         else \
62                 echo "Downloading caffemodel file"; \
63                 ${GET_CAFFEMODEL}; \
64                 if ! [ -e ${CAFFEMODEL_FILENAME} ] ; \
65                 then \
66                         echo "***\nError - Could not download caffemodel file. Check network and proxy settings \n***\n"; \
67                         exit 1; \
68                 fi ; \
69         fi  
70
71 .PHONY: profile
72 profile: prototxt
73         @echo "\nmaking profile"
74         ${NCPROFILE} ${PROTOTXT_FILENAME} -s 12
75
76 .PHONY: browse_profile
77 browse_profile: profile
78         @echo "\nmaking browse_profile"
79         @if [ -e output_report.html ] ; \
80         then \
81                 firefox output_report.html & \
82         else \
83                 @echo "***\nError - output_report.html not found" ; \
84         fi ; 
85
86 .PHONY: compile
87 compile: prototxt caffemodel
88         @echo "\nmaking compile"
89         ${NCCOMPILE} -w ${CAFFEMODEL_FILENAME} -s 12 ${PROTOTXT_FILENAME}
90
91 .PHONY: check
92 check: prototxt caffemodel
93         @echo "\nmaking check"
94 #-${NCCHECK} -w ${CAFFEMODEL_FILENAME} -i ../../data/images/cat.jpg -s 12 -id 281 ${PROTOTXT_FILENAME} -S 255 -M ../../data/ilsvrc12/ilsvrc_2012_mean.npy
95         ${NCCHECK} -w ${CAFFEMODEL_FILENAME} -i ../../data/images/cat.jpg -s 12 -id 281  ${PROTOTXT_FILENAME} -S 255 -M 120 -metric top1
96
97 .PHONY: run
98 run: compile
99         @echo "\nmaking run"
100         ./run.py
101
102 .PHONY: run_py
103 run_py: compile
104         @echo "\nmaking run_py"
105         ./run.py
106
107 .PHONY: cpp
108 cpp: cpp/run.cpp cpp/fp16.c
109         @echo "\nmaking cpp"
110         g++ cpp/run.cpp cpp/fp16.c -o cpp/run_cpp -lmvnc
111
112 .PHONY: run_cpp
113 run_cpp: compile cpp
114         @echo "\nmaking run_cpp"
115         cd cpp; ./run_cpp; cd ..
116
117 .PHONY: help
118 help:
119         @echo "possible make targets: ";
120         @echo "  make help - shows this message";
121         @echo "  make all - makes the following: prototxt, profile, compile, check, cpp, run_py, run_cpp";
122         @echo "  make prototxt - downloads and adds input shape to Caffe prototxt file";
123         @echo "  make caffemodel - downloads the caffemodel for the network"
124         @echo "  make compile - runs SDK compiler tool to compile the NCS graph file for the network";
125         @echo "  make check - runs SDK checker tool to verify an NCS graph file";
126         @echo "  make profile - runs the SDK profiler tool to profile the network creating output_report.html";
127         @echo "  make browse_profile - runs the SDK profiler tool and brings up report in browser.";
128         @echo "  make cpp - builds the run_cpp executable example";
129         @echo "  make run_cpp - runs the run_cpp executable example program";
130         @echo "  make run_py - runs the run.py python example program";
131         @echo "  make clean - removes all created content"
132
133 clean_caffe_model:
134         @echo "\nmaking clean_caffe_model"
135         rm -f ${PROTOTXT_FILENAME}
136         rm -f ${CAFFEMODEL_FILENAME}
137
138 clean: clean_caffe_model
139         @echo "\nmaking clean"
140         rm -f graph
141         rm -f output.gv
142         rm -f output.gv.svg
143         rm -f output_report.html
144         rm -f output_expected.npy
145         rm -f zero_weights.caffemodel
146         rm -f output_result.npy
147         rm -f output_val.csv
148         rm -f cpp/run_cpp
149         rm -f LICENSE.squeezenet