Skip to content

Commit 5a45406

Browse files
committed
Researching the saved models.
1 parent 4721b7b commit 5a45406

File tree

8 files changed

+114
-4
lines changed

8 files changed

+114
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ output/*
44
.idea
55
_models/*
66
_posenet_weights/*
7+
env.sh
78

89
# Byte-compiled / optimized / DLL files
910
__pycache__/

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM tensorflow/tensorflow:2.0.0-gpu-py3-jupyter
1+
FROM tensorflow/tensorflow:nightly-py3-jupyter
2+
# This is the CPU version!
23
# see: https://www.tensorflow.org/install/docker
34
# see: https://hub.docker.com/r/tensorflow/tensorflow/
45

@@ -7,6 +8,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
78
bzip2 \
89
git \
910
wget && \
11+
pip install --upgrade pip && \
1012
rm -rf /var/lib/apt/lists/*
1113

1214
COPY requirements.txt /work/
@@ -15,6 +17,12 @@ WORKDIR /work
1517

1618
RUN pip install -r requirements.txt
1719

20+
RUN git clone https://github.com/patlevin/tfjs-to-tf.git && \
21+
cd tfjs-to-tf && \
22+
pip install . && \
23+
cd .. && \
24+
rm -r tfjs-to-tf
25+
1826
ENV PYTHONPATH='/work/:$PYTHONPATH'
1927

2028
CMD ["bash"]

Dockerfile-gpu

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM tensorflow/tensorflow:2.0.0-gpu-py3-jupyter
2+
# see: https://www.tensorflow.org/install/docker
3+
# see: https://hub.docker.com/r/tensorflow/tensorflow/
4+
5+
# Install system packages
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
bzip2 \
8+
git \
9+
wget && \
10+
pip install --upgrade pip && \
11+
rm -rf /var/lib/apt/lists/*
12+
13+
COPY requirements.txt /work/
14+
15+
WORKDIR /work
16+
17+
RUN pip install -r requirements.txt
18+
19+
RUN git clone https://github.com/patlevin/tfjs-to-tf.git && \
20+
cd tfjs-to-tf && \
21+
pip install . && \
22+
cd .. && \
23+
rm -r tfjs-to-tf
24+
25+
ENV PYTHONPATH='/work/:$PYTHONPATH'
26+
27+
CMD ["bash"]

docker_img_build.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/usr/bin/env bash
22

3-
docker rmi -f posenet-python
3+
if [ -z "$1" ]; then
4+
echo "pass CPU or GPU as argument"
5+
echo "Docker image build failed..."
6+
exit 1
7+
fi
48

5-
docker build -t posenet-python -f Dockerfile .
9+
if [ "$1" = "GPU" ]; then
10+
image="posenet-python-gpu"
11+
dockerfile="Dockerfile-gpu"
12+
else
13+
image="posenet-python-cpu"
14+
dockerfile="Dockerfile"
15+
fi
16+
17+
docker rmi -f "$image"
18+
19+
docker build -t "$image" -f "$dockerfile" .

docker_run.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,26 @@
22

33
WORK=$(pwd)
44

5-
docker run --gpus all -it -v $WORK:/work posenet-python python "$@"
5+
if [ -z "$POSENET_PYTHON_DEVICE" ]; then
6+
echo "set the environment variable POSENET_PYTHON_DEVICE to CPU or GPU, or enter your choice below:"
7+
read -p "Enter your device (CPU or GPU): " device
8+
if [ "$device" = "GPU" ]; then
9+
source <(echo "export POSENET_PYTHON_DEVICE=GPU");
10+
elif [ "$device" = "CPU" ]; then
11+
source <(echo "export POSENET_PYTHON_DEVICE=CPU");
12+
else
13+
echo "Device configuration failed..."
14+
exit 1
15+
fi
16+
fi
17+
18+
19+
echo "device is: $POSENET_PYTHON_DEVICE"
20+
21+
if [ "$POSENET_PYTHON_DEVICE" = "GPU" ]; then
22+
image="posenet-python-gpu"
23+
else
24+
image="posenet-python-cpu"
25+
fi
26+
27+
docker run --gpus all -it --rm -v $WORK:/work "$image" python "$@"

posenet/converter/tfjs2tf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import tfjs_graph_converter as tfjs
2+
import os
3+
4+
5+
def convert(model_id, model_dir, check=False):
6+
tfjsdir = os.path.join('/opt/project/_posenet_weights', 'mobilenet_v1_101')
7+
tfdir = os.path.join('/opt/project/_models', 'model-mobilenet_v1_101_test')
8+
tfjs.api.graph_model_to_saved_model(tfjsdir, tfdir, ['serve'])

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ scipy==1.1.*
44
pyyaml==3.*
55
opencv-python-headless==3.4.5.20
66
# opencv-python==3.4.5.20
7+
# tensorflowjs==1.3.2
8+
tensorflowjs==1.4.0

test_tfjs2tf.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import posenet.converter.tfjs2tf as converter
2+
3+
4+
def main():
5+
converter.convert()
6+
7+
# have a look at: https://github.com/tensorflow/tfjs/tree/master/tfjs-converter
8+
9+
# see: https://stackoverflow.com/questions/58841355/bodypix-real-time-person-segmentation/59509874#59509874
10+
# https://github.com/patlevin/tfjs-to-tf
11+
# https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/float/model-stride16.json
12+
# see weightsManifest.paths for the shard names:
13+
# https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/float/group1-shard1of23.bin
14+
# ...
15+
# https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/resnet50/float/group1-shard23of23.bin
16+
17+
18+
# https://storage.googleapis.com/tfjs-models/savedmodel/bodypix/mobilenet/float/100/model-stride16.json
19+
# see weightsManifest.paths
20+
# "group1-shard1of4.bin",
21+
# "group1-shard2of4.bin",
22+
# "group1-shard3of4.bin",
23+
# "group1-shard4of4.bin"
24+
25+
26+
# https://storage.googleapis.com/tfjs-models/weights/posenet/mobilenet_v1_101/manifest.json
27+
28+

0 commit comments

Comments
 (0)