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