From 7d9cba043c6994207ad36e171b4e352b2a114a32 Mon Sep 17 00:00:00 2001 From: pinaxe1 Date: Sun, 8 Sep 2019 20:31:42 -0400 Subject: [PATCH 1/5] Add files via upload --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0be125c..507d9b7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Toyota Technological Institute at Chicago ## Introduction -DeepLab is a series of image semantic segmentation models, whose latest version, i.e. v3+, proves to be the state-of-art. Its major contribution is the use of atrous spatial pyramid pooling (ASPP) operation at the end of the encoder. While the model works extremely well, its open sourced code is hard to read (at least from my personal perspective). Here we reimplemented DeepLab v3, the earlier version of v3+ (which only additionally employs the decoder architecture), in a much simpler and understandable way. +DeepLab is a series of image semantic segmentation models, whose latest version, i.e. v3+, proves to be the state-of-art. Its major contribution is the use of atrous spatial pyramid pooling (ASPP) operation at the end of the encoder. While the model works extremely well, its open source code is hard to read (at least from my personal perspective). Here we re-implemented DeepLab v3, the earlier version of v3+ (which only additionally employs the decoder architecture), in a much simpler and more understandable way. ## Dependencies @@ -172,11 +172,16 @@ Image| Label | Prediction | :-------------------------:|:-------------------------:|:-------------------------: ![](data/demos/deeplab/resnet_101_voc2012/image_3.jpg) | ![](data/demos/deeplab/resnet_101_voc2012/image_3_label.png) | ![](data/demos/deeplab/resnet_101_voc2012/image_3_prediction.png) -## Running demo on your own images:
-Just put some JPG images into demo_dir and run the script test_any_image.py -Results will be written into same folder. -Make sure that proper model trained and a checkpoint is saved in models_dir -See the script for details. +## Custom Demo + +Just put some JPG-format images into `demo_dir` and run the following command in the terminal. + +```bash +$ python test_any_image.py +``` +Results will be written into same folder. Make sure that proper model trained and a checkpoint is saved in `models_dir`. See the script for details. + +Contributed by [pinaxe1](https://github.com/leimao/DeepLab_v3/pull/7). Will modify to accept arguments and multiple image formats. ## References From 4dadec7809f50c123acdcc334dde224ecfa0f714 Mon Sep 17 00:00:00 2001 From: pinaxe1 Date: Sun, 8 Sep 2019 20:34:31 -0400 Subject: [PATCH 2/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 507d9b7..460dc5a 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ DeepLab is a series of image semantic segmentation models, whose latest version, ├── nets ├── README.md ├── test_demo.py -├── test_any_image.py +├── test_demo_any.py ├── train.py └── utils.py ``` @@ -177,7 +177,7 @@ Image| Label | Prediction | Just put some JPG-format images into `demo_dir` and run the following command in the terminal. ```bash -$ python test_any_image.py +$ python test_demo_any.py ``` Results will be written into same folder. Make sure that proper model trained and a checkpoint is saved in `models_dir`. See the script for details. From 90441ef0c342e6a5aa52b17936fa03c6c15aae4e Mon Sep 17 00:00:00 2001 From: pinaxe1 Date: Sun, 15 Sep 2019 20:29:07 -0400 Subject: [PATCH 3/5] Update README.md test_demo_cam added --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 460dc5a..111ce42 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ DeepLab is a series of image semantic segmentation models, whose latest version, ├── README.md ├── test_demo.py ├── test_demo_any.py +├── test_demo_cam.py ├── train.py └── utils.py ``` @@ -183,6 +184,13 @@ Results will be written into same folder. Make sure that proper model trained an Contributed by [pinaxe1](https://github.com/leimao/DeepLab_v3/pull/7). Will modify to accept arguments and multiple image formats. +## Camera Demo + +The script `test_demo_cam.py` does inference (semantic segmentation) on videostream from a camera. +Make sure you have trained model and set an existing checkpoint filename as a model_filename. +Just run the script and watch output in cv2.namedWindow. +To stop the script press the "q" button. + ## References L.-C. Chen, G. Papandreou, I. Kokkinos, K. Murphy, and A. L. Yuille. [Deeplab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs](https://arxiv.org/abs/1606.00915). TPAMI, 2017. From de976dfedd623396a35f3de2ac1d69c023c8518a Mon Sep 17 00:00:00 2001 From: pinaxe1 Date: Sun, 15 Sep 2019 20:30:15 -0400 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 111ce42..da5cb28 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ Contributed by [pinaxe1](https://github.com/leimao/DeepLab_v3/pull/7). Will modi The script `test_demo_cam.py` does inference (semantic segmentation) on videostream from a camera. Make sure you have trained model and set an existing checkpoint filename as a model_filename. -Just run the script and watch output in cv2.namedWindow. +Then run the script and watch output in cv2.namedWindow. To stop the script press the "q" button. ## References From c2965c8f1df8d9e4a7803b3ae3e8d31b2c0725a6 Mon Sep 17 00:00:00 2001 From: pinaxe1 Date: Sun, 15 Sep 2019 20:32:23 -0400 Subject: [PATCH 5/5] Add files via upload --- test_demo_cam.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test_demo_cam.py diff --git a/test_demo_cam.py b/test_demo_cam.py new file mode 100644 index 0000000..04c1f37 --- /dev/null +++ b/test_demo_cam.py @@ -0,0 +1,46 @@ +''' +The script does inference (semantic segmentation) on videostream from camera. +Just run the script and watch output in cv2.namedWindow. +Make sure you have trained model and set an existing checkpoint filename as a model_filename +To stop the script press the "q" button. + +Created on Sun Sep 15 19:53:37 2019 +@author: Pinaxe +''' + +from os import path as osp +import numpy as np +import cv2 + +from model import DeepLab +from utils import ( save_load_means, subtract_channel_means, label_to_color_image) + +if __name__ == '__main__': + cap = cv2.VideoCapture(0) + cv2.namedWindow('frame', cv2.WINDOW_NORMAL) + cv2.namedWindow('reslt', cv2.WINDOW_NORMAL) + model_filename = 'data/models/deeplab/resnet_101_voc2012/resnet_101_0.3685.ckpt' + + channel_means = save_load_means(means_filename='channel_means.npz',image_filenames=None, recalculate=False) + + deeplab = DeepLab('resnet_101', training=False) + deeplab.load(model_filename) + + while(True): + _, frame = cap.read() + cv2.imshow('frame', frame) + if cv2.waitKey(1) & 0xFF == ord('q'): + break + + image=frame + image_input = subtract_channel_means(image=image, channel_means=channel_means) + output = deeplab.test(inputs=[image_input], target_height=image.shape[0], target_width=image.shape[1])[0] + + img=label_to_color_image(np.argmax(output, axis=-1)) + img=img.astype(np.uint8) + cv2.imshow('reslt', img) + + + cap.release() + cv2.destroyAllWindows() + deeplab.close()