added examples for other weights, pascal_voc works too

This commit is contained in:
Julian Tatsch
2017-08-18 14:03:11 +02:00
parent b0ec4bd1eb
commit e984abf933
26 changed files with 33 additions and 16 deletions
+4 -1
View File
@@ -1,4 +1,7 @@
*.npy
*.pyc
*.png
*.caffemodel
*.prototxt
*.h5
*.json
+18 -7
View File
@@ -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
```

Before

Width:  |  Height:  |  Size: 926 KiB

After

Width:  |  Height:  |  Size: 926 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Regular → Executable
+9 -8
View File
@@ -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()
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 KiB

+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import sys