-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathMakefile
342 lines (256 loc) · 8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
VENV = venv
ifeq ($(OS),Windows_NT)
VENV_BIN = $(VENV)/Scripts
else
VENV_BIN = $(VENV)/bin
endif
PYTHON = $(VENV_BIN)/python
PIP = $(VENV_BIN)/python -m pip
SYSTEM_PYTHON = python3
VENV_TEMP = venv_temp
ARGS =
IMAGE_URL = https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Person_Of_Interest_-_Panel_%289353656298%29.jpg/640px-Person_Of_Interest_-_Panel_%289353656298%29.jpg
BACKGROUND_IMAGE_URL = https://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Gold_Coast_skyline.jpg/640px-Gold_Coast_skyline.jpg
OUTPUT_MASK_PATH = data/example-mask.jpg
OUTPUT_SELECTED_MASK_PATH = data/example-selected-mask.jpg
OUTPUT_COLORED_MASK_PATH = data/example-colored-mask.jpg
OUTPUT_SELECTED_COLORED_MASK_PATH = data/example-selected-colored-mask.jpg
OUTPUT_WEBCAM_MASK_PATH = data/webcam-mask.jpg
MASK_THRESHOLD = 0.75
ADD_OVERLAY_ALPHA = 0.5
SELECTED_PARTS = left_face right_face
WEBCAM_PATH = webcam:0
VIRTUAL_VIDEO_DEVICE = /dev/video2
IMAGE_NAME = de4code/tf-bodypix_unstable
IMAGE_TAG = develop
venv-clean:
@if [ -d "$(VENV)" ]; then \
rm -rf "$(VENV)"; \
fi
venv-create:
$(SYSTEM_PYTHON) -m venv $(VENV)
dev-install-build-dependencies:
$(PIP) install --requirement=requirements.build.txt
dev-install: dev-install-build-dependencies
$(PIP) install \
--constraint=constraints.txt \
--requirement=requirements.dev.txt \
--requirement=requirements.txt
dev-install-tflite: dev-install-build-dependencies
$(PIP) install \
--constraint=constraints.txt \
--requirement=requirements.dev.txt
$(PIP) install .[tflite,image]
dev-run-pip:
$(PIP) $(ARGS)
dev-venv: venv-create dev-install
dev-flake8:
$(PYTHON) -m flake8 tf_bodypix tests setup.py
dev-pylint:
$(PYTHON) -m pylint tf_bodypix tests setup.py
dev-mypy:
$(PYTHON) -m mypy --ignore-missing-imports --show-error-codes \
tf_bodypix tests setup.py
dev-lint: dev-flake8 dev-pylint dev-mypy
dev-pytest:
$(PYTHON) -m pytest -p no:cacheprovider $(ARGS)
dev-pytest-tflite:
$(MAKE) dev-pytest \
ARGS='tests/cli_test.py -k test_should_be_able_to_use_existing_tflite_model'
dev-watch:
$(PYTHON) -m pytest_watch -- -p no:cacheprovider -p no:warnings $(ARGS)
dev-watch-tflite:
$(MAKE) dev-watch \
ARGS='tests/cli_test.py -k test_should_be_able_to_use_existing_tflite_model'
dev-test: dev-lint dev-pytest
dev-remove-dist:
rm -rf ./dist
dev-build-dist:
$(PYTHON) setup.py sdist bdist_wheel
dev-list-dist-contents:
tar -ztvf dist/tf-bodypix-*.tar.gz
dev-get-version:
$(PYTHON) setup.py --version
dev-test-install-dist:
$(MAKE) VENV=$(VENV_TEMP) venv-create
$(VENV_TEMP)/bin/pip install -r requirements.build.txt
$(VENV_TEMP)/bin/pip install --force-reinstall ./dist/*.tar.gz
$(VENV_TEMP)/bin/pip install --force-reinstall ./dist/*.whl
run:
$(PYTHON) -m tf_bodypix $(ARGS)
list-models:
$(PYTHON) -m tf_bodypix \
list-models
list-tflite-models:
$(PYTHON) -m tf_bodypix \
list-tflite-models
convert-example-draw-mask:
$(PYTHON) -m tf_bodypix \
draw-mask \
--source \
"$(IMAGE_URL)" \
--output \
"$(OUTPUT_MASK_PATH)" \
--threshold=$(MASK_THRESHOLD) \
$(ARGS)
convert-example-draw-selected-mask:
$(PYTHON) -m tf_bodypix \
draw-mask \
--source \
"$(IMAGE_URL)" \
--output \
"$(OUTPUT_SELECTED_MASK_PATH)" \
--threshold=$(MASK_THRESHOLD) \
--parts $(SELECTED_PARTS) \
$(ARGS)
convert-example-draw-colored-mask:
$(PYTHON) -m tf_bodypix \
draw-mask \
--source \
"$(IMAGE_URL)" \
--output \
"$(OUTPUT_COLORED_MASK_PATH)" \
--threshold=$(MASK_THRESHOLD) \
--colored \
$(ARGS)
convert-example-draw-selected-colored-mask:
$(PYTHON) -m tf_bodypix \
draw-mask \
--source \
"$(IMAGE_URL)" \
--output \
"$(OUTPUT_SELECTED_COLORED_MASK_PATH)" \
--threshold=$(MASK_THRESHOLD) \
--colored \
--parts $(SELECTED_PARTS) \
$(ARGS)
webcam-draw-mask:
$(PYTHON) -m tf_bodypix \
draw-mask \
--source \
"$(WEBCAM_PATH)" \
--show-output \
--threshold=$(MASK_THRESHOLD) \
--add-overlay-alpha=$(ADD_OVERLAY_ALPHA) \
$(ARGS)
webcam-blur-background:
$(PYTHON) -m tf_bodypix \
blur-background \
--source \
"$(WEBCAM_PATH)" \
--show-output \
--threshold=$(MASK_THRESHOLD) \
$(ARGS)
webcam-replace-background:
$(PYTHON) -m tf_bodypix \
replace-background \
--source \
"$(WEBCAM_PATH)" \
--background \
"$(BACKGROUND_IMAGE_URL)" \
--show-output \
--threshold=$(MASK_THRESHOLD) \
$(ARGS)
webcam-v4l2-draw-mask:
$(PYTHON) -m tf_bodypix \
draw-mask \
--source \
"$(WEBCAM_PATH)" \
--output=$(VIRTUAL_VIDEO_DEVICE) \
--threshold=$(MASK_THRESHOLD) \
--add-overlay-alpha=$(ADD_OVERLAY_ALPHA) \
$(ARGS)
webcam-v4l2-draw-mask-colored:
$(PYTHON) -m tf_bodypix \
draw-mask \
--source \
"$(WEBCAM_PATH)" \
--output=$(VIRTUAL_VIDEO_DEVICE) \
--threshold=$(MASK_THRESHOLD) \
--add-overlay-alpha=$(ADD_OVERLAY_ALPHA) \
--colored \
$(ARGS)
webcam-v4l2-blur-background:
$(PYTHON) -m tf_bodypix \
blur-background \
--source \
"$(WEBCAM_PATH)" \
--output=$(VIRTUAL_VIDEO_DEVICE) \
--threshold=$(MASK_THRESHOLD) \
$(ARGS)
webcam-v4l2-replace-background:
$(PYTHON) -m tf_bodypix \
replace-background \
--source \
"$(WEBCAM_PATH)" \
--background \
"$(BACKGROUND_IMAGE_URL)" \
--output=$(VIRTUAL_VIDEO_DEVICE) \
--threshold=$(MASK_THRESHOLD) \
$(ARGS)
convert-tfjs-models-to-tflite:
mkdir -p "./data/tflite-models"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/050/model-stride8.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/mobilenet-float-multiplier-050-stride8-float16.tflite"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/050/model-stride16.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/mobilenet-float-multiplier-050-stride16-float16.tflite"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/075/model-stride8.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/mobilenet-float-multiplier-075-stride8-float16.tflite"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/075/model-stride16.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/mobilenet-float-multiplier-075-stride16-float16.tflite"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/100/model-stride8.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/mobilenet-float-multiplier-100-stride8-float16.tflite"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/100/model-stride16.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/mobilenet-float-multiplier-100-stride16-float16.tflite"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/float/model-stride16.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/resnet50-float-stride16-float16.tflite"
$(PYTHON) -m tf_bodypix \
convert-to-tflite \
--model-path \
"https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/float/model-stride32.json" \
--optimize \
--quantization-type=float16 \
--output-model-file "./data/tflite-models/resnet50-float-stride32-float16.tflite"
docker-build:
docker build . -t $(IMAGE_NAME):$(IMAGE_TAG)
docker-run:
docker run \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$$DISPLAY \
-v /dev/shm:/dev/shm \
--rm $(IMAGE_NAME):$(IMAGE_TAG) $(ARGS)