TensorFlow implementation of original paper : https://github.com/hszhao/PSPNet

Overview

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
Comments
  • About your result output

    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

    opened by wcy940418 14
  • .npy weights

    .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!

    opened by Dayire 9
  • Cityscapes weights

    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?

    opened by jmtatsch 9
  • My results: wrong colours assignment

    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

    opened by ga84 5
  • weights converted in wrong order

    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!

    opened by scenarios 5
  • ValueError with pspnet.py

    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

    opened by nhabili 5
  • --ms and -s flags not implemented?

    --ms and -s flags not implemented?

    In the readme, it says you can use the -ms and -s flags but these don't seem to be implemented and if you use them, you get an error saying as much.

    Is it possible to use these options through the CLI?

    opened by mhkeller 4
  • scipy version and 'imresize'

    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?

    opened by eugene6789 4
  • Performance improvement using cv2 and numpy

    Performance improvement using cv2 and numpy

    I improved performance using cv2 for reading/resizing. I also used numpy instead of nested for in class_image_to_image Here is my fork: https://github.com/karolmajek/PSPNet-Keras-tensorflow

    Now I am preparing YT vid:

    img_00000203_seg_blended

    Do you want me to make a pull request?

    opened by karolmajek 4
  • "Image not found" error

    Hi, I am trying to get this running but I'm getting a Reason: Image not found error.

    1. I created a virtualenv running python 3.6.6
    2. I ran pip install -r requirements.txt --upgrade
    3. I downloaded the weights and put them in the weights/keras dir
    4. I ran python pspnet.py -m pspnet101_voc2012 -i example_images/pascal_voc.jpg -o example_results/pascal_voc.jpg

    The image pascal_voc.jpg is in that that directory so I'm not sure why it can't find that image.

    The console output I get is Using TensorFlow backend. and then it seems to fail when it imports keras

      File "pspnet.py", line 8, in <module>
        from keras import backend as K
    

    It also says

    Reason: image not found
    
    
    Failed to load the native TensorFlow runtime.
    
    See https://www.tensorflow.org/install/install_sources#common_installation_problems
    

    Do i need to do other installation steps other than pip installing the dependencies?

    opened by mhkeller 2
  • Illusion of a feature?

    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?

    opened by rakhecha42 2
  • Updates for the repository

    Updates for the repository

    [Created Issue for tracking] Disclaimer: I know there are several repos on the Github, that already include PSPNet implemented in TensorFlow with all the features included, but aint give a shit about that, just want to help anyone who use this repo, and know that I have a high-quality code.

    Alright, I haven't maintained anything here for a while, so its time to put some effort to solve as many issues as I can and upgrade repo to the:

    • fix high-severity bugs
    • latest Python/dependencies version
    • Remove deprecated methods
    • Optimize code
    • Add some tests
    • Maybe add some better deploy experience
    • Add API layer(?)

    I plan to deliver updates in several phases:

    • [x] Write some simple smoke tests, to be sure system functioning Merged PRs: https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/74

    • [x] Resolve any issues that are related to the bugfix/performance/optimization using Python3.5 interpreter Merged PRs: https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/58 https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/37 https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/70 https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/71 https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/72 https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/73

    • [ ] Remove blockers to be able to upgrade to the latest stable Python/TF/Keras versions Add support for Python3.4+, instead of some fixed version of interpreter

    • [ ] I expect to have a bunch of new issues after upgrading to the new versions, so then will be the phase of solving new issues.

    • [ ] Look and analyze https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/pull/41 (Make PSPNet fully convolutional)

    • [ ] Refactor code OOP, structure(library API layer, CLI layer,).

    • [ ] Create better logging

    • [ ] Add evaluation script

    • [ ] Upgrade training script

    • [ ] Answer the most common questions in the READme, so fewer issues with common questions will be created

    • [ ] (Different repository) Create Flask API wrapper around this project to ease up deploy/integration/whatever, so ppl without related experience can run it as easy as count to 3 e.g: git pull, make build; make deploy; then do simple http(s) request (docker-compose/Flask/nginx/uwsgi(or gunicorn)/celery worker/redis[or whatever configurable queue])

    upgrades 
    opened by Vladkryvoruchko 0
  • Python3.4+ and modern versions of TensorFlow/Keras support

    Python3.4+ and modern versions of TensorFlow/Keras support

    This PR will bring versions support to Python3.4+ and modern versions of TensorFlow/Keras

    Ideally, PSPNet will run on every Python, starting from 3.4+

    Issues(the same idea): https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/issues/63 https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/issues/49

    As discussed in that issues .h5 and .json models generated by Keras(python3.5), are not supported in python3.6 This is a very general issue, that can occur again on some other versions, even if solution for this case will be provided.

    • [ ] Put .npy weights on my personal DropBox: https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/issues/45
    • [ ] Download .npy weights on the first run and convert them with current version of Python and Keras.
    • [ ] Load only .npy weights and converting to .h5 .json automatically must resolve https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/issues/56
    • [ ] Update to a newer version of TensorFlow/Keras/Scipy and resolve all incompatibilities with different Python versions starting from Python3.4+. Define best combinations if needed
    • [ ] Define better environment in requirements.txt/README.md: https://github.com/Vladkryvoruchko/PSPNet-Keras-tensorflow/issues/38
    opened by Vladkryvoruchko 0
  • The accuracy on voc is not as expected

    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

    opened by QiZhangsama 3
  • Can't load .h5 weights

    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.

    opened by gulzainali98 3
Owner
VladKry
NodeJS/Python backend/AI, Computer Vision developer ('o')
VladKry
PyTorch implementation of PSPNet segmentation network

pspnet-pytorch PyTorch implementation of PSPNet segmentation network Original paper Pyramid Scene Parsing Network Details This is a slightly different

Roman Trusov 532 Dec 29, 2022
Fast image augmentation library and easy to use wrapper around other libraries. Documentation: https://albumentations.ai/docs/ Paper about library: https://www.mdpi.com/2078-2489/11/2/125

Albumentations Albumentations is a Python library for image augmentation. Image augmentation is used in deep learning and computer vision tasks to inc

null 11.4k Jan 9, 2023
A Next Generation ConvNet by FaceBookResearch Implementation in PyTorch(Original) and TensorFlow.

ConvNeXt A Next Generation ConvNet by FaceBookResearch Implementation in PyTorch(Original) and TensorFlow. A FacebookResearch Implementation on A Conv

Raghvender 2 Feb 14, 2022
Unofficial Tensorflow-Keras implementation of Fastformer based on paper [Fastformer: Additive Attention Can Be All You Need](https://arxiv.org/abs/2108.09084).

Fastformer-Keras Unofficial Tensorflow-Keras implementation of Fastformer based on paper Fastformer: Additive Attention Can Be All You Need. Tensorflo

Yam Peleg 10 Jan 30, 2022
Home repository for the Regularized Greedy Forest (RGF) library. It includes original implementation from the paper and multithreaded one written in C++, along with various language-specific wrappers.

Regularized Greedy Forest Regularized Greedy Forest (RGF) is a tree ensemble machine learning method described in this paper. RGF can deliver better r

RGF-team 364 Dec 28, 2022
Implementation of SETR model, Original paper: Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers.

SETR - Pytorch Since the original paper (Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers.) has no official

zhaohu xing 112 Dec 16, 2022
Minimal implementation of PAWS (https://arxiv.org/abs/2104.13963) in TensorFlow.

PAWS-TF ?? Implementation of Semi-Supervised Learning of Visual Features by Non-Parametrically Predicting View Assignments with Support Samples (PAWS)

Sayak Paul 43 Jan 8, 2023
Tensorflow implementation of Semi-supervised Sequence Learning (https://arxiv.org/abs/1511.01432)

Transfer Learning for Text Classification with Tensorflow Tensorflow implementation of Semi-supervised Sequence Learning(https://arxiv.org/abs/1511.01

DONGJUN LEE 82 Oct 22, 2022
Web-interface + rest API for classification and regression (https://jeff1evesque.github.io/machine-learning.docs)

Machine Learning This project provides a web-interface, as well as a programmatic-api for various machine learning algorithms. Supported algorithms: S

Jeff Levesque 252 Dec 11, 2022
Code for: https://berkeleyautomation.github.io/bags/

DeformableRavens Code for the paper Learning to Rearrange Deformable Cables, Fabrics, and Bags with Goal-Conditioned Transporter Networks. Here is the

Daniel Seita 121 Dec 30, 2022
Official repo for SemanticGAN https://nv-tlabs.github.io/semanticGAN/

SemanticGAN This is the official code for: Semantic Segmentation with Generative Models: Semi-Supervised Learning and Strong Out-of-Domain Generalizat

null 151 Dec 28, 2022
Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The original code is written in keras.

CasRel-pytorch-reimplement Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The o

longlongman 170 Dec 1, 2022
The code for our paper "NSP-BERT: A Prompt-based Zero-Shot Learner Through an Original Pre-training Task —— Next Sentence Prediction"

The code for our paper "NSP-BERT: A Prompt-based Zero-Shot Learner Through an Original Pre-training Task —— Next Sentence Prediction"

Sun Yi 201 Nov 21, 2022
An original implementation of "Noisy Channel Language Model Prompting for Few-Shot Text Classification"

Channel LM Prompting (and beyond) This includes an original implementation of Sewon Min, Mike Lewis, Hannaneh Hajishirzi, Luke Zettlemoyer. "Noisy Cha

Sewon Min 92 Jan 7, 2023
PyTorch Implementation of Fully Convolutional Networks. (Training code to reproduce the original result is available.)

pytorch-fcn PyTorch implementation of Fully Convolutional Networks. Requirements pytorch >= 0.2.0 torchvision >= 0.1.8 fcn >= 6.1.5 Pillow scipy tqdm

Kentaro Wada 1.6k Jan 7, 2023
PyTorch original implementation of Cross-lingual Language Model Pretraining.

XLM NEW: Added XLM-R model. PyTorch original implementation of Cross-lingual Language Model Pretraining. Includes: Monolingual language model pretrain

Facebook Research 2.7k Dec 27, 2022
An original implementation of "MetaICL Learning to Learn In Context" by Sewon Min, Mike Lewis, Luke Zettlemoyer and Hannaneh Hajishirzi

MetaICL: Learning to Learn In Context This includes an original implementation of "MetaICL: Learning to Learn In Context" by Sewon Min, Mike Lewis, Lu

Meta Research 27 Nov 2, 2021
git git《Transformer Meets Tracker: Exploiting Temporal Context for Robust Visual Tracking》(CVPR 2021) GitHub:git2] 《Masksembles for Uncertainty Estimation》(CVPR 2021) GitHub:git3]

Transformer Meets Tracker: Exploiting Temporal Context for Robust Visual Tracking Ning Wang, Wengang Zhou, Jie Wang, and Houqiang Li Accepted by CVPR

NingWang 236 Dec 22, 2022