diff --git a/.gitignore b/.gitignore index 60bf75b..53a9627 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *.npy *.pyc *.png - +*.caffemodel +*.prototxt +*.h5 +*.json diff --git a/README.md b/README.md index feab14e..71d7730 100644 --- a/README.md +++ b/README.md @@ -17,21 +17,30 @@ Already converted weights can be downloaded here: [pspnet101_cityscapes.npy](https://www.dropbox.com/s/b21j6hi6qql90l0/pspnet101_cityscapes.npy?dl=0) [pspnet101_voc2012.npy](https://www.dropbox.com/s/xkjmghsbn6sfj9k/pspnet101_voc2012.npy?dl=0) -weights should be placed in the directory with pspnet.py +npy weights should be placed in the directory weights/npy. The interpolation layer is implemented as custom layer "Interp" ## Important Results Keras: -![Original](test.jpg) +![Original](example_images/ade20k.jpg) +![New](example_results/ade20k_seg.jpg) +![New](example_results/ade20k_seg_blended.jpg) +![New](example_results/ade20k_probs.jpg) -![New](test_seg.jpg) -![New](test_seg_blended.jpg) -![New](test_probs.jpg) +![Original](example_images/cityscapes.png) +![New](example_results/cityscapes_seg.jpg) +![New](example_results/cityscapes_seg_blended.jpg) +![New](example_results/cityscapes_probs.jpg) + +![Original](example_images/pascal_voc.jpg) +![New](example_results/pascal_voc_seg.jpg) +![New](example_results/pascal_voc_seg_blended.jpg) +![New](example_results/pascal_voc_probs.jpg) ## Pycaffe result -![Pycaffe results](test_pycaffe.jpg) +![Pycaffe results](example_results/ade20k_seg_pycaffe.jpg) ## Dependencies: 1. Tensorflow 2. Keras @@ -42,5 +51,7 @@ Results Keras: ## Usage: ```bash -python pspnet.py --input-path INPUT_PATH --output-path OUTPUT_PATH +python pspnet.py +python pspnet.py -m pspnet101_cityscapes -i example_images/cityscapes.png -o example_results/cityscapes.jpg +python pspnet.py -m pspnet101_voc2012 -i example_images/pascal_voc.jpg -o example_results/pascal_voc.jpg ``` diff --git a/test.jpg b/example_images/ade20k.jpg similarity index 100% rename from test.jpg rename to example_images/ade20k.jpg diff --git a/example_images/pascal_voc.jpg b/example_images/pascal_voc.jpg new file mode 100644 index 0000000..e31945e Binary files /dev/null and b/example_images/pascal_voc.jpg differ diff --git a/example_images/test_probs.jpg b/example_images/test_probs.jpg new file mode 100644 index 0000000..c2e0c1a Binary files /dev/null and b/example_images/test_probs.jpg differ diff --git a/test_pycaffe.jpg b/example_images/test_pycaffe.jpg similarity index 100% rename from test_pycaffe.jpg rename to example_images/test_pycaffe.jpg diff --git a/example_images/test_seg.jpg b/example_images/test_seg.jpg new file mode 100644 index 0000000..e9a8b0e Binary files /dev/null and b/example_images/test_seg.jpg differ diff --git a/example_images/test_seg_blended.jpg b/example_images/test_seg_blended.jpg new file mode 100644 index 0000000..333825f Binary files /dev/null and b/example_images/test_seg_blended.jpg differ diff --git a/example_results/ade20k_probs.jpg b/example_results/ade20k_probs.jpg new file mode 100644 index 0000000..c2e0c1a Binary files /dev/null and b/example_results/ade20k_probs.jpg differ diff --git a/example_results/ade20k_seg.jpg b/example_results/ade20k_seg.jpg new file mode 100644 index 0000000..e9a8b0e Binary files /dev/null and b/example_results/ade20k_seg.jpg differ diff --git a/example_results/ade20k_seg_blended.jpg b/example_results/ade20k_seg_blended.jpg new file mode 100644 index 0000000..333825f Binary files /dev/null and b/example_results/ade20k_seg_blended.jpg differ diff --git a/example_results/ade20k_seg_pycaffe.jpg b/example_results/ade20k_seg_pycaffe.jpg new file mode 100644 index 0000000..c5f0e43 Binary files /dev/null and b/example_results/ade20k_seg_pycaffe.jpg differ diff --git a/example_results/cityscapes_probs.jpg b/example_results/cityscapes_probs.jpg new file mode 100644 index 0000000..8c9f1b5 Binary files /dev/null and b/example_results/cityscapes_probs.jpg differ diff --git a/example_results/cityscapes_seg.jpg b/example_results/cityscapes_seg.jpg new file mode 100644 index 0000000..c542b56 Binary files /dev/null and b/example_results/cityscapes_seg.jpg differ diff --git a/example_results/cityscapes_seg_blended.jpg b/example_results/cityscapes_seg_blended.jpg new file mode 100644 index 0000000..d653f7d Binary files /dev/null and b/example_results/cityscapes_seg_blended.jpg differ diff --git a/example_results/pascal_voc_probs.jpg b/example_results/pascal_voc_probs.jpg new file mode 100644 index 0000000..3beec57 Binary files /dev/null and b/example_results/pascal_voc_probs.jpg differ diff --git a/example_results/pascal_voc_seg.jpg b/example_results/pascal_voc_seg.jpg new file mode 100644 index 0000000..061dfb5 Binary files /dev/null and b/example_results/pascal_voc_seg.jpg differ diff --git a/example_results/pascal_voc_seg_blended.jpg b/example_results/pascal_voc_seg_blended.jpg new file mode 100644 index 0000000..e36c3be Binary files /dev/null and b/example_results/pascal_voc_seg_blended.jpg differ diff --git a/pspnet.py b/pspnet.py old mode 100644 new mode 100755 index 2635d91..6db4191 --- a/pspnet.py +++ b/pspnet.py @@ -1,6 +1,7 @@ +#!/usr/bin/env python from __future__ import print_function import os -from os.path import splitext +from os.path import splitext, join import argparse import numpy as np from scipy import misc, ndimage @@ -19,8 +20,8 @@ class PSPNet(object): def __init__(self, nb_classes, resnet_layers, input_shape, weights): self.input_shape = input_shape - json_path = weights + ".json" - h5_path = weights + ".h5" + json_path = join("weights", "keras", weights + ".json") + h5_path = join("weights", "keras", weights + ".h5") if os.path.isfile(json_path) and os.path.isfile(h5_path): print("Keras model & weights found, loading...") with open(json_path, 'r') as file_handle: @@ -67,9 +68,9 @@ class PSPNet(object): return pred[0] def set_npy_weights(self, weights_path): - npy_weights_path = weights_path + ".npy" - json_path = weights_path + ".json" - h5_path = weights_path + ".h5" + npy_weights_path = join("weights", "npy", weights_path + ".npy") + json_path = join("weights", "keras", weights_path + ".json") + h5_path = join("weights", "keras", weights_path + ".h5") print("Importing weights from %s" % npy_weights_path) weights = np.load(npy_weights_path).item() @@ -126,9 +127,9 @@ if __name__ == "__main__": choices=['pspnet50_ade20k', 'pspnet101_cityscapes', 'pspnet101_voc2012']) - parser.add_argument('-i', '--input_path', type=str, default='test.jpg', + parser.add_argument('-i', '--input_path', type=str, default='example_images/ade20k.jpg', help='Path the input image') - parser.add_argument('-o', '--output_path', type=str, default='test.jpg', + parser.add_argument('-o', '--output_path', type=str, default='example_results/ade20k.jpg', help='Path to output') parser.add_argument('--id', default="0") args = parser.parse_args() diff --git a/test_probs.jpg b/test_probs.jpg deleted file mode 100644 index a287722..0000000 Binary files a/test_probs.jpg and /dev/null differ diff --git a/test_seg.jpg b/test_seg.jpg deleted file mode 100644 index cccc8ea..0000000 Binary files a/test_seg.jpg and /dev/null differ diff --git a/test_seg_blended.jpg b/test_seg_blended.jpg deleted file mode 100644 index 8f9da11..0000000 Binary files a/test_seg_blended.jpg and /dev/null differ diff --git a/weight_converter.py b/weight_converter.py index e98ffcd..f775c37 100644 --- a/weight_converter.py +++ b/weight_converter.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + from __future__ import print_function import sys diff --git a/weights/caffe/Put caffemodels & prototxts here b/weights/caffe/Put caffemodels & prototxts here new file mode 100644 index 0000000..e69de29 diff --git a/weights/keras/Put keras weights here b/weights/keras/Put keras weights here new file mode 100644 index 0000000..e69de29 diff --git a/weights/npy/Put the npy weights here b/weights/npy/Put the npy weights here new file mode 100644 index 0000000..e69de29