Skip to content

MobileNetV2 Training

Katsuya Hyodo edited this page Jun 8, 2020 · 17 revisions

Tensorflow-GPU v1.15.2 - CUDA10.1, cuDNN7, Python3.6, Ubuntu1804 https://drive.google.com/file/d/1QjmkICCoTUPyPW0H4q84brQqWAI3Ymcr/view?usp=sharing

mkdir -p /media/b920405/Windows/datasets/coco/dataset
cd /media/b920405/Windows/datasets/coco/dataset
curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1P5pir4LVhev_S1Yvu_K3q_hGERAcFpg6" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1P5pir4LVhev_S1Yvu_K3q_hGERAcFpg6" -o annotations_trainval2017.zip
unzip annotations_trainval2017.zip
rm annotations_trainval2017.zip
curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1llUu6071hd0QY2DY5vs_7VPaceI7EVst" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1llUu6071hd0QY2DY5vs_7VPaceI7EVst" -o train2017.zip
unzip train2017.zip
rm train2017.zip
curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1bB8M-WG2LJwmB6YpLMsxUTWwIX3BwYkr" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1bB8M-WG2LJwmB6YpLMsxUTWwIX3BwYkr" -o val2017.zip
unzip val2017.zip
rm val2017.zip
export PYTHONPATH=$PYTHONPATH:${HOME}/models/research:${HOME}/models/research/slim
python3 tf_pose/train.py \
  --model=mobilenet_v2_1.0 \
  --datapath=/media/b920405/Windows/datasets/coco/dataset/annotations/ \
  --imgpath=/media/b920405/Windows/datasets/coco/dataset/ \
  --batchsize=2 \
  --gpus=1 \
  --max-epoch=10 \
  --lr=0.001
python3 tf_pose/train.py \
  --model=mobilenet_v2_0.5 \
  --datapath=/media/b920405/Windows/datasets/coco/dataset/annotations/ \
  --imgpath=/media/b920405/Windows/datasets/coco/dataset/ \
  --batchsize=2 \
  --gpus=1 \
  --max-epoch=10 \
  --lr=0.001
sed -i s/"(slim.batch_norm,): {'center': True, 'scale': True},"/"(slim.batch_norm,): {'center': True, 'scale': True, 'is_training': False},"/ tf_pose/mobilenet/mobilenet_v2.py
    with tf.Session(config=config) as sess:
        loader = tf.train.Saver(net.restorable_variables())
        loader.restore(sess, pretrain_path)

        tf.train.write_graph(sess.graph_def, './tmp', 'graph.pb', as_text=True)

    with tf.Session(config=config) as sess:
        loader = tf.train.Saver(net.restorable_variables())
        loader.restore(sess, 'models/train/test/model_latest-425000')

        tf.train.write_graph(sess.graph_def, 'models/train/test', 'graph.pbtxt', as_text=True)
python3 run_checkpoint.py \
  --model=mobilenet_v2_1.0 \
  --resize=432x368
python3 run_checkpoint.py \
  --model=mobilenet_v2_1.0 \
  --resize=320x256
sed -i s/"(slim.batch_norm,): {'center': True, 'scale': True, 'is_training': False},"/"(slim.batch_norm,): {'center': True, 'scale': True},"/ tf_pose/mobilenet/mobilenet_v2.py
python3 -m tensorflow.python.tools.freeze_graph \
  --input_graph=models/train/test/graph.pbtxt \
  --output_graph=models/train/test/frozen_graph.pb \
  --input_checkpoint=models/train/test/model_latest-425000 \
  --output_node_names="Openpose/concat_stage7"
git clone -b v1.15.2 https://github.com/tensorflow/tensorflow.git
cd tensorflow
bazel build tensorflow/tools/graph_transforms:transform_graph
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
    --in_graph=${HOME}/git/tf-pose-estimation/models/train/test/frozen_graph.pb \
    --out_graph=${HOME}/git/tf-pose-estimation/models/train/test/frozen_graph_opt.pb \
    --inputs='image' \
    --outputs='Openpose/concat_stage7' \
    --transforms='
    strip_unused_nodes(type=float, shape="1,432,368,3")
    fold_old_batch_norms
    fold_batch_norms
    fold_constants(ignoreError=False)
    remove_nodes(op=Identity, op=CheckNumerics)'
Clone this wiki locally