Code Monkey home page Code Monkey logo

pspnet-keras-tensorflow's Introduction

Keras implementation of PSPNet(caffe)

Implemented Architecture of Pyramid Scene Parsing Network in Keras.

For the best compability please use Python3.5

Setup

  1. Install dependencies:
    • Tensorflow (-gpu)
    • Keras
    • numpy
    • scipy
    • pycaffe(PSPNet)(optional for converting the weights)
    pip install -r requirements.txt --upgrade
  2. Converted trained weights are needed to run the network. Weights(in .h5 .json format) have to be downloaded and placed into directory weights/keras

Already converted weights can be downloaded here:

Convert weights by yourself(optional)

(Note: this is not required if you use .h5/.json weights)

Running this needs the compiled original PSPNet caffe code and pycaffe.

python weight_converter.py <path to .prototxt> <path to .caffemodel>

Usage:

python pspnet.py -m <model> -i <input_image>  -o <output_path>
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

List of arguments:

 -m --model        - which model to use: 'pspnet50_ade20k', 'pspnet101_cityscapes', 'pspnet101_voc2012'
    --id           - (int) GPU Device id. Default 0
 -s --sliding      - Use sliding window
 -f --flip         - Additional prediction of flipped image
 -ms --multi_scale - Predict on multiscale images

Keras results:

Original New New New

Original New New New

Original New New New

Implementation details

  • The interpolation layer is implemented as custom layer "Interp"
  • Forward step takes about ~1 sec on single image
  • Memory usage can be optimized with:
    config = tf.ConfigProto()
    config.gpu_options.per_process_gpu_memory_fraction = 0.3 
    sess = tf.Session(config=config)
  • ndimage.zoom can take a long time

pspnet-keras-tensorflow's People

Contributors

davidgillsjo avatar jefequien avatar jmtatsch avatar mrlzla avatar petercheng00 avatar vladkryvoruchko avatar wassname avatar wcy940418 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pspnet-keras-tensorflow's Issues

Training Data

Hi,

May I ask for example how should be the training dataset?

thanks.

weights converted in wrong order

Hi @Vladkryvoruchko , I noticed you convert the parameter of bn layer in caffe to the numpy array by the order of 'mean = v[0], variance = v[1], scale = v[2], offset = v[3]' . However, the v[0-3] actually hold the value for scale, offset, mean, variance respectively according to the caffe blob's definition in bn layer.

The reason that you can still reproduce the results is that you reverse the order again when you try to restore the parameter for the keras model from the numpy array, i.e. model.get_layer(layer.name).set_weights([mean, variance, scale, offset]).

This may not hurt when using your code completely, but it is very unexpected for those people who just use the parameter converted by the code.

Thanks for your efforts!

is train.py written by python2?

i tried to run train.py using my own datasets, and found lots of incompatible codes with python3.5, eg, list and dict relevant operations, why don't unify writing with python3 ?

Bad results(Not bad now)

Although the converted weights produce plausible predictions,
they are not yet up to the published results of the PSPNet paper.

Current results on cityscapes validation set:

classes          IoU      nIoU
--------------------------------
road          : 0.969      nan
sidewalk      : 0.776      nan
building      : 0.871      nan
wall          : 0.532      nan
fence         : 0.464      nan
pole          : 0.302      nan
traffic light : 0.375      nan
traffic sign  : 0.567      nan
vegetation    : 0.872      nan
terrain       : 0.591      nan
sky           : 0.905      nan
person        : 0.585    0.352
rider         : 0.253    0.147
car           : 0.897    0.698
truck         : 0.606    0.284
bus           : 0.721    0.375
train         : 0.652    0.388
motorcycle    : 0.344    0.147
bicycle       : 0.618    0.348
--------------------------------
Score Average : 0.626    0.342
--------------------------------


categories       IoU      nIoU
--------------------------------
flat          : 0.974      nan
nature        : 0.876      nan
object        : 0.397      nan
sky           : 0.905      nan
construction  : 0.872      nan
human         : 0.603    0.376
vehicle       : 0.879    0.676
--------------------------------
Score Average : 0.787    0.526
--------------------------------

Accuracy of the published code on several validation/testing sets according to the author:

PSPNet50 on ADE20K valset (mIoU/pAcc): 41.68/80.04 
PSPNet101 on VOC2012 testset (mIoU): 85.41 (multiscale evaluation!)
PSPNet101 on cityscapes valset (mIoU/pAcc): 79.70/96.38

So we are still missing 79.70 - 62.60 = 17.10 % IoU

Does anyone have an idea where we lose that accuracy?

unicode error

this is on windows 10 64 + python 3.6.2 + tensorflow 1.3 + downloaded npy from dropbox

python pspnet.py -m pspnet50_ade20k -i example_images/ade20k.jpg -o example_results/ade20k.jpg
Using TensorFlow backend.
2017-10-14 16:39:03.003842: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 16:39:03.003972: W C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 16:39:03.347437: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:955] Found device 0 with properties:
name: GeForce GTX 1070
major: 6 minor: 1 memoryClockRate (GHz) 1.645
pciBusID 0000:01:00.0
Total memory: 8.00GiB
Free memory: 6.62GiB
2017-10-14 16:39:03.347582: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:976] DMA: 0
2017-10-14 16:39:03.348951: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:986] 0: Y
2017-10-14 16:39:03.349478: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
Namespace(flip=False, id='0', input_path='example_images/ade20k.jpg', model='pspnet50_ade20k', multi_scale=False, output_path='example_results/ade20k.jpg', sliding=False)
No Keras model & weights found, import from npy weights.
Building a PSPNet based on ResNet 50 expecting inputs of shape (473, 473) predicting 150 classes
PSP module will interpolate to a final feature map size of (60, 60)
Importing weights from weights\npy\pspnet50_ade20k.npy
Processing input_1
Processing conv1_1_3x3_s2
Processing conv1_1_3x3_s2_bn
Processing activation_1
Processing conv1_2_3x3
Processing conv1_2_3x3_bn
Processing activation_2
Processing conv1_3_3x3
Processing conv1_3_3x3_bn
Processing activation_3
Processing max_pooling2d_1
Processing activation_4
Processing conv2_1_1x1_reduce
Processing conv2_1_1x1_reduce_bn
Processing activation_5
Processing zero_padding2d_1
Processing conv2_1_3x3
Processing conv2_1_3x3_bn
Processing activation_6
Processing conv2_1_1x1_increase
Processing conv2_1_1x1_proj
Processing conv2_1_1x1_increase_bn
Processing conv2_1_1x1_proj_bn
Processing add_1
Processing activation_7
Processing conv2_2_1x1_reduce
Processing conv2_2_1x1_reduce_bn
Processing activation_8
Processing zero_padding2d_2
Processing conv2_2_3x3
Processing conv2_2_3x3_bn
Processing activation_9
Processing conv2_2_1x1_increase
Processing conv2_2_1x1_increase_bn
Processing add_2
Processing activation_10
Processing conv2_3_1x1_reduce
Processing conv2_3_1x1_reduce_bn
Processing activation_11
Processing zero_padding2d_3
Processing conv2_3_3x3
Processing conv2_3_3x3_bn
Processing activation_12
Processing conv2_3_1x1_increase
Processing conv2_3_1x1_increase_bn
Processing add_3
Processing activation_13
Processing conv3_1_1x1_reduce
Processing conv3_1_1x1_reduce_bn
Processing activation_14
Processing zero_padding2d_4
Processing conv3_1_3x3
Processing conv3_1_3x3_bn
Processing activation_15
Processing conv3_1_1x1_increase
Processing conv3_1_1x1_proj
Processing conv3_1_1x1_increase_bn
Processing conv3_1_1x1_proj_bn
Processing add_4
Processing activation_16
Processing conv3_2_1x1_reduce
Processing conv3_2_1x1_reduce_bn
Processing activation_17
Processing zero_padding2d_5
Processing conv3_2_3x3
Processing conv3_2_3x3_bn
Processing activation_18
Processing conv3_2_1x1_increase
Processing conv3_2_1x1_increase_bn
Processing add_5
Processing activation_19
Processing conv3_3_1x1_reduce
Processing conv3_3_1x1_reduce_bn
Processing activation_20
Processing zero_padding2d_6
Processing conv3_3_3x3
Processing conv3_3_3x3_bn
Processing activation_21
Processing conv3_3_1x1_increase
Processing conv3_3_1x1_increase_bn
Processing add_6
Processing activation_22
Processing conv3_4_1x1_reduce
Processing conv3_4_1x1_reduce_bn
Processing activation_23
Processing zero_padding2d_7
Processing conv3_4_3x3
Processing conv3_4_3x3_bn
Processing activation_24
Processing conv3_4_1x1_increase
Processing conv3_4_1x1_increase_bn
Processing add_7
Processing activation_25
Processing conv4_1_1x1_reduce
Processing conv4_1_1x1_reduce_bn
Processing activation_26
Processing zero_padding2d_8
Processing conv4_1_3x3
Processing conv4_1_3x3_bn
Processing activation_27
Processing conv4_1_1x1_increase
Processing conv4_1_1x1_proj
Processing conv4_1_1x1_increase_bn
Processing conv4_1_1x1_proj_bn
Processing add_8
Processing activation_28
Processing conv4_2_1x1_reduce
Processing conv4_2_1x1_reduce_bn
Processing activation_29
Processing zero_padding2d_9
Processing conv4_2_3x3
Processing conv4_2_3x3_bn
Processing activation_30
Processing conv4_2_1x1_increase
Processing conv4_2_1x1_increase_bn
Processing add_9
Processing activation_31
Processing conv4_3_1x1_reduce
Processing conv4_3_1x1_reduce_bn
Processing activation_32
Processing zero_padding2d_10
Processing conv4_3_3x3
Processing conv4_3_3x3_bn
Processing activation_33
Processing conv4_3_1x1_increase
Processing conv4_3_1x1_increase_bn
Processing add_10
Processing activation_34
Processing conv4_4_1x1_reduce
Processing conv4_4_1x1_reduce_bn
Processing activation_35
Processing zero_padding2d_11
Processing conv4_4_3x3
Processing conv4_4_3x3_bn
Processing activation_36
Processing conv4_4_1x1_increase
Processing conv4_4_1x1_increase_bn
Processing add_11
Processing activation_37
Processing conv4_5_1x1_reduce
Processing conv4_5_1x1_reduce_bn
Processing activation_38
Processing zero_padding2d_12
Processing conv4_5_3x3
Processing conv4_5_3x3_bn
Processing activation_39
Processing conv4_5_1x1_increase
Processing conv4_5_1x1_increase_bn
Processing add_12
Processing activation_40
Processing conv4_6_1x1_reduce
Processing conv4_6_1x1_reduce_bn
Processing activation_41
Processing zero_padding2d_13
Processing conv4_6_3x3
Processing conv4_6_3x3_bn
Processing activation_42
Processing conv4_6_1x1_increase
Processing conv4_6_1x1_increase_bn
Processing add_13
Processing activation_43
Processing conv5_1_1x1_reduce
Processing conv5_1_1x1_reduce_bn
Processing activation_44
Processing zero_padding2d_14
Processing conv5_1_3x3
Processing conv5_1_3x3_bn
Processing activation_45
Processing conv5_1_1x1_increase
Processing conv5_1_1x1_proj
Processing conv5_1_1x1_increase_bn
Processing conv5_1_1x1_proj_bn
Processing add_14
Processing activation_46
Processing conv5_2_1x1_reduce
Processing conv5_2_1x1_reduce_bn
Processing activation_47
Processing zero_padding2d_15
Processing conv5_2_3x3
Processing conv5_2_3x3_bn
Processing activation_48
Processing conv5_2_1x1_increase
Processing conv5_2_1x1_increase_bn
Processing add_15
Processing activation_49
Processing conv5_3_1x1_reduce
Processing conv5_3_1x1_reduce_bn
Processing activation_50
Processing zero_padding2d_16
Processing conv5_3_3x3
Processing conv5_3_3x3_bn
Processing activation_51
Processing conv5_3_1x1_increase
Processing conv5_3_1x1_increase_bn
Processing add_16
Processing activation_52
Processing average_pooling2d_4
Processing average_pooling2d_3
Processing average_pooling2d_2
Processing average_pooling2d_1
Processing conv5_3_pool6_conv
Processing conv5_3_pool3_conv
Processing conv5_3_pool2_conv
Processing conv5_3_pool1_conv
Processing conv5_3_pool6_conv_bn
Processing conv5_3_pool3_conv_bn
Processing conv5_3_pool2_conv_bn
Processing conv5_3_pool1_conv_bn
Processing activation_56
Processing activation_55
Processing activation_54
Processing activation_53
Processing lambda_4
Processing lambda_3
Processing lambda_2
Processing lambda_1
Processing concatenate_1
Processing conv5_4
Processing conv5_4_bn
Processing activation_57
Processing dropout_1
Processing conv6
Processing lambda_5
Processing activation_58
Set a total of 121 weights
Finished importing weights.
Writing keras model & weights
Traceback (most recent call last):
File "pspnet.py", line 265, in
weights=args.model)
File "pspnet.py", line 142, in init
input_shape=input_shape, weights=weights)
File "pspnet.py", line 48, in init
self.set_npy_weights(weights)
File "pspnet.py", line 129, in set_npy_weights
json_string = self.model.to_json()
File "C:\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2665, in to_json
model_config = self._updated_config()
File "C:\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2632, in _updated_config
config = self.get_config()
File "C:\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2326, in get_config
layer_config = layer.get_config()
File "C:\Anaconda3\lib\site-packages\keras\layers\core.py", line 659, in get_config
function = func_dump(self.function)
File "C:\Anaconda3\lib\site-packages\keras\utils\generic_utils.py", line 175, in func_dump
code = marshal.dumps(func.code).decode('raw_unicode_escape')
UnicodeDecodeError: 'rawunicodeescape' codec can't decode bytes in position 208-209: truncated \UXXXXXXXX escape

allow custom path for model files

i want to run in a custom environment where i have to keep to model npy file in a different location. would be nice to have an option for a custom model path.

error : load weights

I want to run train.py and I get:
Importing weights from weights/npy/pspnet50_ade20k.npy
input_1
conv1_1_3x3_s2
'conv1_1_3x3_s2'
conv1_1_3x3_s2_bn
Traceback (most recent call last):
File "train.py", line 152, in
args.batch, args.weights, args.initial_epoch, args.model, args.sep)
File "train.py", line 98, in train
set_npy_weights(pre_trained, model)
File "train.py", line 32, in set_npy_weights
mean = weights[layer.name]['mean'].reshape(-1)
KeyError: 'conv1_1_3x3_s2_bn'

If I use load_model, it shows:
model = load_model("./weights/keras/pspnet50_ade20k.h5")
File "~/.local/lib/python3.5/site-packages/keras/models.py", line 268, in load_model
raise ValueError('No model found in config file.')
ValueError: No model found in config file.

If i use np.load(h5_path).item(), it shows:
File "train.py", line 155, in
train(args.datadir, args.logdir, (473, 473), args.classes, args.resnet_layers,
File "train.py", line 99, in train
input_shape=input_size)
File "train.py", line 27, in set_npy_weights
#weights = np.load(npy_weights_path,encoding="bytes").item()
File "~/.local/lib/python3.5/site-packages/numpy/lib/npyio.py", line 443, in load
"Failed to interpret file %s as a pickle" % repr(file))
OSError: Failed to interpret file 'weights/keras/pspnet50_ade20k.h5' as a pickle

SystemError: unknown opcode

Namespace(flip=True, glob_path=None, id='0', input_path='example_images/cityscapes.png', input_size=500, model='pspnet50_ade20k', output_path='example_results/cityscapes.jpg', weights=None)
weights/keras/pspnet50_ade20k.json
Keras model & weights found, loading...
XXX lineno: 18, opcode: 0
Traceback (most recent call last):
File "/home/jiurui/temp/PSPNet-Keras-tensorflow-master/pspnet.py", line 186, in
weights=args.model)
File "/home/jiurui/temp/PSPNet-Keras-tensorflow-master/pspnet.py", line 133, in init
input_shape=input_shape, weights=weights)
File "/home/jiurui/temp/PSPNet-Keras-tensorflow-master/pspnet.py", line 34, in init
self.model = model_from_json(file_handle.read())
File "/home/jiurui/env_mask_rcnn/lib/python3.6/site-packages/keras/models.py", line 345, in model_from_json
return layer_module.deserialize(config, custom_objects=custom_objects)
File "/home/jiurui/env_mask_rcnn/lib/python3.6/site-packages/keras/layers/init.py", line 54, in deserialize
printable_module_name='layer')
File "/home/jiurui/env_mask_rcnn/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 139, in deserialize_keras_object
list(custom_objects.items())))
File "/home/jiurui/env_mask_rcnn/lib/python3.6/site-packages/keras/engine/topology.py", line 2497, in from_config
process_node(layer, node_data)
File "/home/jiurui/env_mask_rcnn/lib/python3.6/site-packages/keras/engine/topology.py", line 2454, in process_node
layer(input_tensors[0], **kwargs)
File "/home/jiurui/env_mask_rcnn/lib/python3.6/site-packages/keras/engine/topology.py", line 602, in call
output = self.call(inputs, **kwargs)
File "/home/jiurui/env_mask_rcnn/lib/python3.6/site-packages/keras/layers/core.py", line 650, in call
return self.function(inputs, **arguments)
File "/media/tatsch/DataSSD1/workspace/PSPNet-Keras-tensorflow/pspnet/layers_builder.py", line 18, in Interp
return BatchNormalization(momentum=0.95, name=name, epsilon=1e-5)
SystemError: unknown opcode

Training error

I am trying to train the cityscapes dataset using a small number of images. When i run the training code in the terminal although no error appears but it is not moving past the first epoch.
screenshot from 2018-04-27 11-55-26

Can someone please tell me the fix?

My results: wrong colours assignment

Hello and thank you for your great work! I tried to do segmentation with this network (with cityscapes weights) and colours seem to be assigned completely wrong. Do you have an idea why this might be happening? I.e. vegetation is always blue, pavements red instead of magenta and people magenta instead of red, streets are black(static or unlabeled?) etc... Can it be that, for some reason, pixels are colourized by lowest scores? I was thinking about converting the weights myself, but I don't have pycaffe etc. installed. Could someone please upload the correct weights, after the issue with wrong order of parameters in conversion? @scenarios @karolmajek

I will post images later this evening, now I have to type from my phone and can't add pictures.

I would appreciate any suggestion what might be causing the issue.
@wcy940418 @Vladkryvoruchko @jmtatsch

Hier ist what I'm using:

Name Version Build Channel

python 3.5.5 he025d50_2 conda-forge

cudatoolkit 8.0 4

cudnn 6.0 0

tensorflow 1.1.0 np112py35_0

tensorflow-gpu 1.1.0 np112py35_0

keras 2.0.6 py35_0 conda-forge

where should i start to debug this model?

Hi, @Vladkryvoruchko , Thank you for your hard work,
I am very interested in your work about convert PSPNet model from caffe to keras,
after run current model successfully , I also confused about the results
first of all, can you try to make sure the convert process is really worked?

Can't load .h5 weights

at my end when i run the command

python pspnet.py -m pspnet101_cityscapes -i example_images/cityscapes.png -o example_results/cityscapes.jpg

It always runs .npy weights by default. How to solve this issue? i have .h5 weights downloaded.

Training error

I am trying to train PSPNet on a particular dataset.
trainingerror
Can someone please tell me the exact steps to be followed to train a dataset.

Illusion of a feature?

In pspnet.py line 163, you are taking input size from args.

Next, in line 207, you are using that user defined input size to resize the image.
cimg = misc.imresize(img, (args.input_size, args.input_size))

But now, you are not using the 'cimg' variable anywhere.

Furthermore, in line number 56, you are resizing the image again to an input shape which you have hardcoded for each pretrained model. (473x473 for pspnet101_voc2012)
img = misc.imresize(img, self.input_shape)

So what's even the point of asking for size?

'input_data' not defined in pspnet.py

I downloaded the weights and placed it in keras folder. Everything runs fine until I encounter this,
Namespace(flip=False, id='0', input_path='example_images/pascal_voc.jpg', input_size=500, model='pspnet101_cityscapes', output_path='example_results/cityscapes.jpg', weights=None)
Keras model & weights found, loading...
Predicting...
Traceback (most recent call last):
File "pspnet.py", line 193, in
probs = pspnet.predict(cimg, args.flip)
File "pspnet.py", line 61, in predict
probs = self.feed_forward(img)
File "pspnet.py", line 83, in feed_forward
prediction = self.model.predict(np.expand_dims(input_data, 0))[0]
NameError: name 'input_data' is not defined

I checked the code and input_data variable is not defined after all. What am I missing?

trained weights

Hello,
may share weight of PSPNET model in the keras.
Thanks.

train.py hasn't finished yet? especially for preprocessing.py in python_utils?

as mentioned above, i found many places demanding to debug, i don;t know the datasets how to place in the folders by author. especially for the function of "data_generator_s31 " and function of “generate”, it couldn't return the correct of images and corresponding annotations, i am trying to fix them up, does anyone find the same issues?

scipy version and 'imresize'

I've created one virtual environment on Anaconda
and installed tensorflow= 1.10.0 / numpy = 1.13.3 / scipy = 1.2.1 and keras.

I could not install tensorflow-gpu because I don't have gpu..
and If I run code,
I'm getting this message saying,
"from scipy.misc import imresize, imread
ImportError: cannot import name 'imresize"

from somewhere, somebody said that 'imresize' is deprecated from scipy ==1.0.0 so I tried a lower version but
the result was same too.

Do somebody have any idea to help me to resolve this problem?

A reminder: Do not activate tensorflow in the terminal, just run "python pspnet.py ......"

Just following the above instructions provided by the author, the code should work. If you met problems like "TypeError: pool_2d() got an unexpected keyword argument 'ws' "(theano version should be 0.9), "AttributeError: 'module' object has no attribute '_set_session' ", "ValueError: epsilon must be at least 1e-5, got 9.99999974738e-06", a potential reason is that you may activate tensorflow in the terminal before run the pspnet.py. DO NOT activate tensorflow. Just run ''python pspnet.py -m pspnet101_cityscapes -i example_images/cityscapes.png -o example_results/cityscapes.jpg''. It should work.

ValueError with pspnet.py

Hi, when I run pspnet.py, I get a ValueError due to a negative dimension (output file with error
pspnet.txt
attached). I'm using virtualenv with python2.7, tensorflow version 1.3.0 and keras version 2.0.8. I'm also using the weight files that you've provided.

Any help would be greatly appreciated!

Thanks
Nariman

bn layer order problem

Hi,
It seems that bn_layer weight order is [gamma, offset, mean, var]
but in your code, set weight as [mean, var, gamma, offset]
can someone tell me why ?
Thanks.

About your result output

Hello, thank you for your excellent work. I am also interested in implementing PSPNet in TF. I have not tested your code yet, but about your output, I found some post process code in original matlab code.

function score = ms_caffe_process(input_data,net)
    score = net.forward({input_data});
    score = score{1};
    score_flip = net.forward({input_data(end:-1:1,:,:)});
    score_flip = score_flip{1};
    score = score + score_flip(end:-1:1,:,:);

    score = permute(score, [2 1 3]);
    score = exp(score);
    score = bsxfun(@rdivide, score, sum(score, 3));
end

It seems that they feed in the image twice each time, and one is flipped. Do you know why they did this?

Thank you

The accuracy on voc is not as expected

I used pspnet101_voc2012.h5 and pspnet101_voc2012.json to test VOC data,and it's mIOU is 82.51% after uploaded the results. But the real value is 85.4% in the paper. I want to know why.

This is my resutls:

Competition Category Score
Object Segmentation (comp6) background 95.69300
Object Segmentation (comp6) aeroplane 93.16350
Object Segmentation (comp6) bicycle 68.16070
Object Segmentation (comp6) bird 92.60880
Object Segmentation (comp6) boat 77.27700
Object Segmentation (comp6) bottle 82.46240
Object Segmentation (comp6) bus 91.86820
Object Segmentation (comp6) car 91.61700
Object Segmentation (comp6) cat 94.20940
Object Segmentation (comp6) chair 37.09920
Object Segmentation (comp6) cow 88.46340
Object Segmentation (comp6) diningtable 74.82890
Object Segmentation (comp6) dog 87.07190
Object Segmentation (comp6) horse 93.95220
Object Segmentation (comp6) motorbike 89.37420
Object Segmentation (comp6) person 90.35040
Object Segmentation (comp6) pottedplant 68.82600
Object Segmentation (comp6) sheep 90.44340
Object Segmentation (comp6) sofa 60.11600
Object Segmentation (comp6) train 85.58210
Object Segmentation (comp6) tvmonitor 79.56540
  Object Segmentation (comp6) 82.51110

Using your repo on CPU

Hi, thanks for your work!

Is it possible to make just inference of your modele using CPU? How can I do it?

Best regards,

.npy weigths

Hey! Thanks for yoor work @Vladkryvoruchko , somebody have new links to dowload the weights in .npy format?? I want to train the net from a pretrained model and the function set_npy_weights seems that only works with .npy files, beacuse if you use the .h5 or .json that can be downloaded using the README links the code throws the error:
ValueError: You called set_weights(weights) on layer "conv1_1_3x3_s2_bn" with a weight list of length 1, but the layer was expecting 4 weights. Provided weights: [<HDF5 group "/conv1_1_3x3_s2_bn" (1 members)>]..`

Thanks in advance!

ADE20K segmaps not correctly labeled

When I used the '-m pspnet50_ade20k' option, the RGB segmaps generated were not correctly labeled/colored. I found out a fix for this,

Line number 209 of 'pspnet.py' must be changed as follows,

import ade20k_labels
color_cm = utils.class_image_to_image(cm,ade20k_labels.labels)

Similar changes must be made according to the other options -m 'pspnet101_cityscapes' OR 'pspnet101_voc2012' chosen by the user.

Auxiliary loss

Hello, thanks for your works! Have you implemented the auxiliary loss? And where is it?

npy file ilnks are not working.

I found out there are three links for pre-trained weight files.

pspnet50_ade20k.npy
pspnet101_cityscapes.npy
pspnet101_voc2012.npy

However, only one of them are working, pspnet50_ade20k.npy.
I hope to download pspnet101_voc2012.npy file, specifically.
Can I get a link for this file?

License == ?

Hi, I would like to know under which license is your work available. GitHub's default license is "all rights reserved" for public repositories, such as this one.

Adding a license to your repository is simple:
https://help.github.com/articles/adding-a-license-to-a-repository/
Just be sure that in the template you pick to add your name(s).

You may also want to take a look at the following in the case you took code from this source: https://github.com/hszhao/PSPNet/blob/master/LICENSE

Many thanks!

Number of classes in cityscapes dataset.

In the pspnet.py code the number of classes mentioned in the cityscapes dataset is 19 whereas in the cityscapes_labels.py the number of classes are 35. Can someone please tell me why is this so?

which are the correct EVALUATION_SCALES values

in the main code you have:
if args.multi_scale: EVALUATION_SCALES = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] # must be all floats! EVALUATION_SCALES = [0.15, 0.25, 0.5] # must be all floats!
is the first one intended to be overridden by the second?

error in pspnet.prototxt

Hello,
when run weight-converter this error occur:

"caffe.LayerParameter" has no field named "bn_param".

                      i replace it with "batch_norm_param"

again occur below error:
"caffe.BatchNormParameter" has no field named "slope_filler".

Environment not well defined

It would be useful to specify the exact details of the entire environment. Specifically, the exact version of Python. After trial-and-error, I figured out that Python 3.5 (not 3.6/latest nor 2.7) work properly. Just add it to the requirements file.

.npy weights

Hello,

Can anyone upload the .npy weights for cityscapes (and others if possible) since the conversion is not working for me, PSPNet caffe is not working well.

Thanks!

Adaptive_Pooling Error

File "/home/examples/PyramidSceneParsingNetwork_PSPNet.py", line 347, in
activation="softmax", name="PSP")
File "/home/examples/PyramidSceneParsingNetwork_PSPNet.py", line 329, in build_pspnet
psp = build_pyramid_pooling_module(res)
File "/home/examples/PyramidSceneParsingNetwork_PSPNet.py", line 305, in build_pyramid_pooling_module
interp_block1 = interp_block(res, 1, output_size)
File "/home/examples/PyramidSceneParsingNetwork_PSPNet.py", line 291, in interp_block
use_bias=False)(prev_layer)
File "/home/anaconda3/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 728, in call
self.build(input_shapes)
File "/home/anaconda3/lib/python3.6/site-packages/tensorflow/python/keras/layers/convolutional.py", line 149, in build
raise ValueError('The channel dimension of the inputs '
ValueError: The channel dimension of the inputs should be defined. Found None.

The output of the following layer has the shape of (?,1, 1, ?).
prev_layer = AdaptivePooling2D(level, mode='avg')(prev_layer)

Please, Any help is appreciated! Thanks in Advance!

Cityscapes weights

Hi Vlad,

I am trying to convert the original pspnet101_cityscapes weights from https://github.com/hszhao/PSPNet to keras.

python weight_converter.py pspnet101_cityscapes_713.prototxt pspnet101_cityscapes.caffemodel

In PSPNet-Keras-tensorflow I adjusted:

WEIGHTS = 'pspnet101_cityscapes.npy'
DATA_MEAN = np.array([[[72.78044, 83.21195, 73.45286]]]) # RGB
x = Conv2D(19, (1, 1), strides=(1, 1), name="conv6")(x) # changed the classes from 150 to 19 

PSPNet runs through without errors, unfortunately, the output for a test image remains indiscernible:

test
out

Do you have an idea what I could be missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.