Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #60

Merged
merged 8 commits into from
May 20, 2023
Merged

Dev #60

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,26 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[testing]
pip install matplotlib numpy opencv-python pdbpp tensorboard tensorflow-cpu scipy Pillow gdown isort black flake8
pip install mypy types-requests pytype pytest pytest-cov pre-commit pytest-mock pytest-flask
pip install -e .[tfcpu,api,dev,testing,linting]

- name: Test with pytest
run: |
pip install python-coveralls
python -m pytest --cov=./dfp --cov-report term-missing
pip install coveragepy-lcov
coveragepy-lcov --data_file_path .coverage --output_file_path lcov.info
python -m pytest --cov=./dfp --cov-report lcov:lcov.info

- name: Build
run: |
pip install setuptools sdist wheel twine
pip install -r requirements.txt
python setup.py sdist bdist_wheel
python -m pip install --upgrade pip
pip install -e .[tfcpu,api]

- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
./dist/*tar.gz
./dist/*.whl

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,4 @@ model/
cov.info
lcov.info
*.h5
out.jpg
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ RUN pip install -e .[tfgpu,api]
# RUN gdown https://drive.google.com/uc?id=1czUSFvk6Z49H-zRikTc67g2HUUz4imON
# RUN unzip log.zip
# RUN rm log.zip
ADD log log
COPY docs/app.toml /docs/app.toml
ADD log/store log/store

COPY resources /usr/local/resources
RUN mv /usr/local/resources .
Expand Down
60 changes: 36 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# TF2DeepFloorplan [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [<img src="https://colab.research.google.com/assets/colab-badge.svg" >](https://colab.research.google.com/github/zcemycl/TF2DeepFloorplan/blob/master/deepfloorplan.ipynb) ![example workflow](https://github.com/zcemycl/TF2DeepFloorplan/actions/workflows/main.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/zcemycl/TF2DeepFloorplan/badge.svg?branch=main)](https://coveralls.io/github/zcemycl/TF2DeepFloorplan?branch=main)
<!-- [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fzcemycl%2FTF2DeepFloorplan&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com) -->
# TF2DeepFloorplan [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [<img src="https://colab.research.google.com/assets/colab-badge.svg" >](https://colab.research.google.com/github/zcemycl/TF2DeepFloorplan/blob/master/deepfloorplan.ipynb) ![example workflow](https://github.com/zcemycl/TF2DeepFloorplan/actions/workflows/main.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/zcemycl/TF2DeepFloorplan/badge.svg?branch=main)](https://coveralls.io/github/zcemycl/TF2DeepFloorplan?branch=main)[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fzcemycl%2FTF2DeepFloorplan&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
This repo contains a basic procedure to train and deploy the DNN model suggested by the paper ['Deep Floor Plan Recognition using a Multi-task Network with Room-boundary-Guided Attention'](https://arxiv.org/abs/1908.11025). It rewrites the original codes from [zlzeng/DeepFloorplan](https://github.com/zlzeng/DeepFloorplan) into newer versions of Tensorflow and Python.
<br>
Network Architectures from the paper, <br>
Expand Down Expand Up @@ -36,8 +35,10 @@ pip install -e .[tfgpu,api,dev,testing,linting]
```
python -m dfp.train [--batchsize 2][--lr 1e-4][--epochs 1000]
[--logdir 'log/store'][--modeldir 'model/store']
[--saveTensorInterval 10][--saveModelInterval 20]
[--tfmodel 'subclass'/'func']
[--save-tensor-interval 10][--save-model-interval 20]
[--tfmodel 'subclass'/'func'][--feature-channels 256 128 64 32]
[--backbone 'vgg16'/'mobilenetv1'/'mobilenetv2'/'resnet50']
[--feature-names block1_pool block2_pool block3_pool block4_pool block5_pool]
```
- for example,
```
Expand All @@ -52,7 +53,11 @@ tensorboard --logdir=log/store
```
python -m dfp.convert2tflite [--modeldir model/store]
[--tflitedir model/store/model.tflite]
[--quantize]
[--loadmethod 'log'/'none'/'pb']
[--quantize][--tfmodel 'subclass'/'func']
[--feature-channels 256 128 64 32]
[--backbone 'vgg16'/'mobilenetv1'/'mobilenetv2'/'resnet50']
[--feature-names block1_pool block2_pool block3_pool block4_pool block5_pool]
```
6. Download and unzip model from google drive,
```
Expand All @@ -70,6 +75,9 @@ python -m dfp.deploy [--image 'path/to/image']
[--loadmethod 'log'/'pb'/'tflite']
[--weight 'log/store/G'/'model/store'/'model/store/model.tflite']
[--tfmodel 'subclass'/'func']
[--feature-channels 256 128 64 32]
[--backbone 'vgg16'/'mobilenetv1'/'mobilenetv2'/'resnet50']
[--feature-names block1_pool block2_pool block3_pool block4_pool block5_pool]
```
- for example,
```
Expand All @@ -83,16 +91,20 @@ python -m dfp.deploy --image floorplan.jpg --weight log/store/G
docker build -t tf_docker -f Dockerfile .
docker run -d -p 1111:1111 tf_docker:latest
docker run --gpus all -d -p 1111:1111 tf_docker:latest

# special for hot reloading flask
docker run -v ${PWD}/src/dfp/app.py:/src/dfp/app.py -v ${PWD}/src/dfp/deploy.py:/src/dfp/deploy.py -d -p 1111:1111 tf_docker:latest
docker logs `docker ps | grep "tf_docker:latest" | awk '{ print $1 }'` --follow
```
2. Call the api for output.
```
curl -H "Content-Type: application/json" --request POST \
-d '{"uri":"https://cdn.cnn.com/cnnnext/dam/assets/200212132008-04-london-rental-market-intl-exlarge-169.jpg","colorize":1,"postprocess":0, "output":"/tmp"}' \
http://0.0.0.0:1111/process --output /tmp/tmp.jpg
-d '{"uri":"https://cdn.cnn.com/cnnnext/dam/assets/200212132008-04-london-rental-market-intl-exlarge-169.jpg","colorize":1,"postprocess":0}' \
http://0.0.0.0:1111/uri --output /tmp/tmp.jpg


curl --request POST -F "file=@resources/30939153.jpg;type=image/jpeg" \
-F "postprocess=0" -F "colorize=0" -F "output=/tmp" http://0.0.0.0:1111/process --output out.jpg
curl --request POST -F "file=@resources/30939153.jpg" \
-F "postprocess=0" -F "colorize=0" http://0.0.0.0:1111/upload --output out.jpg
```
3. If you run `app.py` without docker, the second curl for file upload will not work.

Expand Down Expand Up @@ -148,27 +160,27 @@ git branch -d xx-features
## Optimization
- Backbone Comparison in Size

|Backbone|log|pb|tflite|
|---|---|---|---|
|VGG16|130.5Mb|119Mb|45.3Mb|
|MobileNetV1|102.1Mb|86.7Mb|50.2Mb|
|MobileNetV2|129.3Mb|94.4Mb|57.9Mb|
|ResNet50|214Mb|216Mb|107.2Mb|
|Backbone|log|pb|tflite|toml|
|---|---|---|---|---|
|VGG16|130.5Mb|119Mb|45.3Mb|[link](docs/experiments/vgg16/exp1)|
|MobileNetV1|102.1Mb|86.7Mb|50.2Mb|[link](docs/experiments/mobilenetv1/exp1)|
|MobileNetV2|129.3Mb|94.4Mb|57.9Mb|[link](docs/experiments/mobilenetv2/exp1)|
|ResNet50|214Mb|216Mb|107.2Mb|[link](docs/experiments/resnet50/exp1)|

- Feature Selection Comparison in Size

|Backbone|Feature Names|log|pb|tflite|
|---|---|---|---|---|
|MobileNetV1|"conv_pw_1_relu", <br>"conv_pw_3_relu", <br>"conv_pw_5_relu", <br>"conv_pw_7_relu", <br>"conv_pw_13_relu"|102.1Mb|86.7Mb|50.2Mb|
|MobileNetV1|"conv_pw_1_relu", <br>"conv_pw_3_relu", <br>"conv_pw_5_relu", <br>"conv_pw_7_relu", <br>"conv_pw_12_relu"|84.5Mb|82.3Mb|49.2Mb|
|Backbone|Feature Names|log|pb|tflite|toml|
|---|---|---|---|---|---|
|MobileNetV1|"conv_pw_1_relu", <br>"conv_pw_3_relu", <br>"conv_pw_5_relu", <br>"conv_pw_7_relu", <br>"conv_pw_13_relu"|102.1Mb|86.7Mb|50.2Mb|[link](docs/experiments/mobilenetv1/exp1)|
|MobileNetV1|"conv_pw_1_relu", <br>"conv_pw_3_relu", <br>"conv_pw_5_relu", <br>"conv_pw_7_relu", <br>"conv_pw_12_relu"|84.5Mb|82.3Mb|49.2Mb|[link](docs/experiments/mobilenetv1/exp2)|

- Feature Channels Comparison in Size

|Backbone|Channels|log|pb|tflite|
|---|---|---|---|---|
|VGG16|[256,128,64,32]|130.5Mb|119Mb|45.3Mb|
|VGG16|[128,64,32,16]|82.4Mb|81.6Mb|27.3Mb|
|VGG16|[32,32,32,32]|73.2Mb|67.5Mb|18.1Mb|
|Backbone|Channels|log|pb|tflite|toml|
|---|---|---|---|---|---|
|VGG16|[256,128,64,32]|130.5Mb|119Mb|45.3Mb|[link](docs/experiments/vgg16/exp1)|
|VGG16|[128,64,32,16]|82.4Mb|81.6Mb|27.3Mb||
|VGG16|[32,32,32,32]|73.2Mb|67.5Mb|18.1Mb|[link](docs/experiments/vgg16/exp2)|

- tfmot
- Pruning (not working)
Expand Down
11 changes: 6 additions & 5 deletions deepfloorplan.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"from dfp.utils.rgb_ind_convertor import *\n",
"from dfp.utils.util import *\n",
"from dfp.utils.legend import *\n",
"from dfp.utils.settings import *\n",
"from dfp.deploy import *\n",
"print(tf.test.is_gpu_available())\n",
"print(tf.config.list_physical_devices('GPU'))"
Expand All @@ -87,7 +88,11 @@
},
"outputs": [],
"source": [
"inp = mpimg.imread('./TF2DeepFloorplan/resources/30939153.jpg')"
"img_path = './TF2DeepFloorplan/resources/30939153.jpg'\n",
"inp = mpimg.imread(img_path)\n",
"args = parse_args(\"--tomlfile ./TF2DeepFloorplan/docs/notebook.toml\".split())\n",
"args = overwrite_args_with_toml(args)\n",
"args.image = img_path"
]
},
{
Expand All @@ -102,10 +107,6 @@
},
"outputs": [],
"source": [
"args = Namespace(image='./TF2DeepFloorplan/resources/30939153.jpg',\n",
" weight='./log/store/G',loadmethod='log',\n",
" postprocess=True,colorize=True,\n",
" save=None,tfmodel=\"subclass\")\n",
"result = main(args)"
]
},
Expand Down
10 changes: 10 additions & 0 deletions docs/app.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tfmodel = 'subclass'
image = ''
postprocess = 1
colorize = 1
save = ''
weight = 'log/store/G'
loadmethod = 'log'
feature_channels = [256, 128, 64, 32]
backbone = 'vgg16'
feature_names = ["block1_pool", "block2_pool", "block3_pool", "block4_pool", "block5_pool",]
9 changes: 9 additions & 0 deletions docs/experiments/mobilenetv1/exp1/compress.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tfmodel = 'func'
modeldir = 'model/store_mobilenetv1_exp1'
tflitedir = 'model/store_mobilenetv1_exp1_model.tflite'
quantize = 1
compress_mode = 'quantization'
loadmethod = 'pb'
feature_channels = [256, 128, 64, 32]
backbone = 'mobilenetv1'
feature_names = ["conv_pw_1_relu", "conv_pw_3_relu", "conv_pw_5_relu", "conv_pw_7_relu", "conv_pw_13_relu",]
14 changes: 14 additions & 0 deletions docs/experiments/mobilenetv1/exp1/deploy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tfmodel = 'func'
image = 'resources/30939153.jpg'
postprocess = 1
colorize = 1
save = ''
weight = 'log/store_mobilenetv1_exp1/G'
loadmethod = 'log'
# weight = 'model/store_mobilenetv1_exp1'
# loadmethod = 'pb'
# weight = 'model/store_mobilenetv1_exp1_model.tflite'
# loadmethod = 'tflite'
feature_channels = [256, 128, 64, 32]
backbone = 'mobilenetv1'
feature_names = ["conv_pw_1_relu", "conv_pw_3_relu", "conv_pw_5_relu", "conv_pw_7_relu", "conv_pw_13_relu",]
13 changes: 13 additions & 0 deletions docs/experiments/mobilenetv1/exp1/train.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tfmodel = 'func'
batchsize = 8
lr = 1e-4
wd = 1e-5
epochs = 100
logdir = 'log/store_mobilenetv1_exp1'
modeldir = 'model/store_mobilenetv1_exp1'
weight = ''
save_tensor_interval = 10
save_model_interval = 20
feature_channels = [256, 128, 64, 32]
backbone = 'mobilenetv1'
feature_names = ["conv_pw_1_relu", "conv_pw_3_relu", "conv_pw_5_relu", "conv_pw_7_relu", "conv_pw_13_relu",]
9 changes: 9 additions & 0 deletions docs/experiments/mobilenetv1/exp2/compress.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tfmodel = 'func'
modeldir = 'model/store_mobilenetv1_exp2'
tflitedir = 'model/store_mobilenetv1_exp2_model.tflite'
quantize = 1
compress_mode = 'quantization'
loadmethod = 'pb'
feature_channels = [256, 128, 64, 32]
backbone = 'mobilenetv1'
feature_names = ["conv_pw_1_relu", "conv_pw_3_relu", "conv_pw_5_relu", "conv_pw_7_relu", "conv_pw_12_relu",]
14 changes: 14 additions & 0 deletions docs/experiments/mobilenetv1/exp2/deploy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tfmodel = 'func'
image = 'resources/30939153.jpg'
postprocess = 1
colorize = 1
save = ''
weight = 'log/store_mobilenetv1_exp2/G'
loadmethod = 'log'
# weight = 'model/store_mobilenetv1_exp2'
# loadmethod = 'pb'
# weight = 'model/store_mobilenetv1_exp2_model.tflite'
# loadmethod = 'tflite'
feature_channels = [256, 128, 64, 32]
backbone = 'mobilenetv1'
feature_names = ["conv_pw_1_relu", "conv_pw_3_relu", "conv_pw_5_relu", "conv_pw_7_relu", "conv_pw_12_relu",]
13 changes: 13 additions & 0 deletions docs/experiments/mobilenetv1/exp2/train.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tfmodel = 'func'
batchsize = 8
lr = 1e-4
wd = 1e-5
epochs = 100
logdir = 'log/store_mobilenetv1_exp2'
modeldir = 'model/store_mobilenetv1_exp2'
weight = ''
save_tensor_interval = 10
save_model_interval = 20
feature_channels = [256, 128, 64, 32]
backbone = 'mobilenetv1'
feature_names = ["conv_pw_1_relu", "conv_pw_3_relu", "conv_pw_5_relu", "conv_pw_7_relu", "conv_pw_12_relu",]
13 changes: 13 additions & 0 deletions docs/experiments/mobilenetv2/exp1/train.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tfmodel = 'func'
batchsize = 8
lr = 1e-4
wd = 1e-5
epochs = 100
logdir = 'log/store_mobilenetv2_exp1'
modeldir = 'model/store_mobilenetv2_exp1'
weight = ''
save_tensor_interval = 10
save_model_interval = 20
feature_channels = [256, 128, 64, 32]
backbone = 'mobilenetv2'
feature_names = ["block_1_expand_relu", "block_3_expand_relu", "block_5_expand_relu", "block_13_expand_relu", "out_relu",]
13 changes: 13 additions & 0 deletions docs/experiments/resnet50/exp1/train.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tfmodel = 'func'
batchsize = 8
lr = 1e-4
wd = 1e-5
epochs = 100
logdir = 'log/store_resnet50_exp1'
modeldir = 'model/store_resnet50_exp1'
weight = ''
save_tensor_interval = 10
save_model_interval = 20
feature_channels = [256, 128, 64, 32]
backbone = 'resnet50'
feature_names = ["conv1_relu", "conv2_block3_out", "conv3_block4_out", "conv4_block6_out", "conv5_block3_out",]
9 changes: 9 additions & 0 deletions docs/experiments/vgg16/exp1/compress.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tfmodel = 'subclass'
modeldir = 'model/store_vgg16_exp1'
tflitedir = 'model/store_vgg16_exp1_model.tflite'
quantize = 1
compress_mode = 'quantization'
loadmethod = 'pb'
feature_channels = [256, 128, 64, 32]
backbone = 'vgg16'
feature_names = ["block1_pool", "block2_pool", "block3_pool", "block4_pool", "block5_pool",]
9 changes: 9 additions & 0 deletions docs/experiments/vgg16/exp1/compress_log.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tfmodel = 'subclass'
modeldir = 'log/store_vgg16_exp1/G'
tflitedir = 'model/store_vgg16_exp1_model_log.tflite'
quantize = 1
compress_mode = 'quantization'
loadmethod = 'log'
feature_channels = [256, 128, 64, 32]
backbone = 'vgg16'
feature_names = ["block1_pool", "block2_pool", "block3_pool", "block4_pool", "block5_pool",]
14 changes: 14 additions & 0 deletions docs/experiments/vgg16/exp1/deploy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tfmodel = 'subclass'
image = 'resources/30939153.jpg'
postprocess = 1
colorize = 1
save = ''
# weight = 'log/store_vgg16_exp1/G'
# loadmethod = 'log'
# weight = 'model/store_vgg16_exp1'
# loadmethod = 'pb'
weight = 'model/store_vgg16_exp1_model.tflite'
loadmethod = 'tflite'
feature_channels = [256, 128, 64, 32]
backbone = 'vgg16'
feature_names = ["block1_pool", "block2_pool", "block3_pool", "block4_pool", "block5_pool",]
13 changes: 13 additions & 0 deletions docs/experiments/vgg16/exp1/train.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tfmodel = 'subclass'
batchsize = 8
lr = 1e-4
wd = 1e-5
epochs = 100
logdir = 'log/store_vgg16_exp1'
modeldir = 'model/store_vgg16_exp1'
weight = ''
save_tensor_interval = 10
save_model_interval = 20
feature_channels = [256, 128, 64, 32]
backbone = 'vgg16'
feature_names = ["block1_pool", "block2_pool", "block3_pool", "block4_pool", "block5_pool",]
9 changes: 9 additions & 0 deletions docs/experiments/vgg16/exp2/compress.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tfmodel = 'subclass'
modeldir = 'model/store_vgg16_exp2'
tflitedir = 'model/store_vgg16_exp2_model.tflite'
quantize = 1
compress_mode = 'quantization'
loadmethod = 'pb'
feature_channels = [32, 32, 32, 32]
backbone = 'vgg16'
feature_names = ["block1_pool", "block2_pool", "block3_pool", "block4_pool", "block5_pool",]
14 changes: 14 additions & 0 deletions docs/experiments/vgg16/exp2/deploy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tfmodel = 'subclass'
image = 'resources/30939153.jpg'
postprocess = 1
colorize = 1
save = ''
weight = 'log/store_vgg16_exp2/G'
loadmethod = 'log'
# weight = 'model/store_vgg16_exp2'
# loadmethod = 'pb'
# weight = 'model/store_vgg16_exp2_model.tflite'
# loadmethod = 'tflite'
feature_channels = [32, 32, 32, 32]
backbone = 'vgg16'
feature_names = ["block1_pool", "block2_pool", "block3_pool", "block4_pool", "block5_pool",]
Loading
Loading