Code Monkey home page Code Monkey logo

self-correction-human-parsing's Introduction

Self Correction for Human Parsing

Python 3.6 License: MIT

An out-of-box human parsing representation extractor.

Our solution ranks 1st for all human parsing tracks (including single, multiple and video) in the third LIP challenge!

lip-visualization

Features:

  • Out-of-box human parsing extractor for other downstream applications.
  • Pretrained model on three popular single person human parsing datasets.
  • Training and inferecne code.
  • Simple yet effective extension on multi-person and video human parsing tasks.

Requirements

conda env create -f environment.yaml
conda activate schp
pip install -r requirements.txt

Simple Out-of-Box Extractor

The easiest way to get started is to use our trained SCHP models on your own images to extract human parsing representations. Here we provided state-of-the-art trained models on three popular datasets. Theses three datasets have different label system, you can choose the best one to fit on your own task.

LIP (exp-schp-201908261155-lip.pth)

  • mIoU on LIP validation: 59.36 %.

  • LIP is the largest single person human parsing dataset with 50000+ images. This dataset focus more on the complicated real scenarios. LIP has 20 labels, including 'Background', 'Hat', 'Hair', 'Glove', 'Sunglasses', 'Upper-clothes', 'Dress', 'Coat', 'Socks', 'Pants', 'Jumpsuits', 'Scarf', 'Skirt', 'Face', 'Left-arm', 'Right-arm', 'Left-leg', 'Right-leg', 'Left-shoe', 'Right-shoe'.

ATR (exp-schp-201908301523-atr.pth)

  • mIoU on ATR test: 82.29%.

  • ATR is a large single person human parsing dataset with 17000+ images. This dataset focus more on fashion AI. ATR has 18 labels, including 'Background', 'Hat', 'Hair', 'Sunglasses', 'Upper-clothes', 'Skirt', 'Pants', 'Dress', 'Belt', 'Left-shoe', 'Right-shoe', 'Face', 'Left-leg', 'Right-leg', 'Left-arm', 'Right-arm', 'Bag', 'Scarf'.

Pascal-Person-Part (exp-schp-201908270938-pascal-person-part.pth)

  • mIoU on Pascal-Person-Part validation: 71.46 %.

  • Pascal Person Part is a tiny single person human parsing dataset with 3000+ images. This dataset focus more on body parts segmentation. Pascal Person Part has 7 labels, including 'Background', 'Head', 'Torso', 'Upper Arms', 'Lower Arms', 'Upper Legs', 'Lower Legs'.

Choose one and have fun on your own task!

To extract the human parsing representation, simply put your own image in the INPUT_PATH folder, then download a pretrained model and run the following command. The output images with the same file name will be saved in OUTPUT_PATH

python simple_extractor.py --dataset [DATASET] --model-restore [CHECKPOINT_PATH] --input-dir [INPUT_PATH] --output-dir [OUTPUT_PATH]

[Updated] Here is also a colab demo example for quick inference provided by @levindabhi.

The DATASET command has three options, including 'lip', 'atr' and 'pascal'. Note each pixel in the output images denotes the predicted label number. The output images have the same size as the input ones. To better visualization, we put a palette with the output images. We suggest you to read the image with PIL.

If you need not only the final parsing images, but also the feature map representations. Add --logits command to save the output feature maps. These feature maps are the logits before softmax layer.

Dataset Preparation

Please download the LIP dataset following the below structure.

data/LIP
|--- train_imgaes # 30462 training single person images
|--- val_images # 10000 validation single person images
|--- train_segmentations # 30462 training annotations
|--- val_segmentations # 10000 training annotations
|--- train_id.txt # training image list
|--- val_id.txt # validation image list

Training

python train.py 

By default, the trained model will be saved in ./log directory. Please read the arguments for more details.

Evaluation

python evaluate.py --model-restore [CHECKPOINT_PATH]

CHECKPOINT_PATH should be the path of trained model.

Extension on Multiple Human Parsing

Please read MultipleHumanParsing.md for more details.

Citation

Please cite our work if you find this repo useful in your research.

@article{li2020self,
  title={Self-Correction for Human Parsing}, 
  author={Li, Peike and Xu, Yunqiu and Wei, Yunchao and Yang, Yi},
  journal={IEEE Transactions on Pattern Analysis and Machine Intelligence}, 
  year={2020},
  doi={10.1109/TPAMI.2020.3048039}}

Visualization

  • Source Image. demo
  • LIP Parsing Result. demo-lip
  • ATR Parsing Result. demo-atr
  • Pascal-Person-Part Parsing Result. demo-pascal
  • Source Image. demo
  • Instance Human Mask. demo-lip
  • Global Human Parsing Result. demo-lip
  • Multiple Human Parsing Result. demo-lip

Related

Our code adopts the InplaceSyncBN to save gpu memory cost.

There is also a PaddlePaddle Implementation of this project.

self-correction-human-parsing's People

Contributors

gogoduck912 avatar levindabhi avatar mkmohangb avatar sajjadaemmi avatar xuyunqiu 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

self-correction-human-parsing's Issues

about the run environment

i have installed Python = 3.6.7, PyTorch = 1.4.0, but when i run simple_extractor.py, there is a problem,

ninja: build stopped: subcommand failed.

can you provide some solutions for this error?
tks

consistent_loss always zero?

Thanks for your excellent work.
My question is as follows:
when I train the model, the consistent_loss is always zero

Problem with inplaceABN and nvcc version in train.py


CalledProcessError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py in run_ninja_build(build_directory, verbose, error_prefix)
1520 check=True,
-> 1521 env=env)
1522 else:
/opt/conda/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
486 raise CalledProcessError(retcode, process.args,
--> 487 output=stdout, stderr=stderr)
488 return CompletedProcess(process.args, retcode, stdout, stderr)
CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
/data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/train.py in
23 from torch.utils import data
24
---> 25 import networks
26 import utils.schp as schp
27 from datasets.datasets import LIPDataSet
/data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/networks/init.py in
1 from future import absolute_import
2
----> 3 from networks.AugmentCE2P import resnet101
4
5 factory = {
/data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/networks/AugmentCE2P.py in
18 # Note here we adopt the InplaceABNSync implementation from https://github.com/mapillary/inplace_abn
19 # By default, the InplaceABNSync module contains a BatchNorm Layer and a LeakyReLu layer
---> 20 from modules import InPlaceABNSync
21 #device=torch.device('cpu')
22 BatchNorm2d = functools.partial(InPlaceABNSync, activation='none')
/data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/modules/init.py in
----> 1 from .bn import ABN, InPlaceABN, InPlaceABNSync
2 from .functions import ACT_RELU, ACT_LEAKY_RELU, ACT_ELU, ACT_NONE
3 from .misc import GlobalAvgPool2d, SingleGPU
4 from .residual import IdentityResidualBlock
5 from .dense import DenseModule
/data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/modules/bn.py in
8 from Queue import Queue
9
---> 10 from .functions import *
11
12
/data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/modules/functions.py in
18 "inplace_abn_cuda_half.cu"
19 ]],
---> 20 extra_cuda_cflags=["--expt-extended-lambda"])
21
22 # Activation names
/opt/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py in load(name, sources, extra_cflags, extra_cuda_cflags, extra_ldflags, extra_include_paths, build_directory, verbose, with_cuda, is_python_module, keep_intermediates)
977 with_cuda,
978 is_python_module,
--> 979 keep_intermediates=keep_intermediates)
980
981
/opt/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py in jit_compile(name, sources, extra_cflags, extra_cuda_cflags, extra_ldflags, extra_include_paths, build_directory, verbose, with_cuda, is_python_module, keep_intermediates)
1182 build_directory=build_directory,
1183 verbose=verbose,
-> 1184 with_cuda=with_cuda)
1185 finally:
1186 baton.release()
/opt/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py in write_ninja_file_and_build_library(name, sources, extra_cflags, extra_cuda_cflags, extra_ldflags, extra_include_paths, build_directory, verbose, with_cuda)
1280 build_directory,
1281 verbose,
-> 1282 error_prefix="Error building extension '{}'".format(name))
1283
1284
/opt/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py in run_ninja_build(build_directory, verbose, error_prefix)
1535 if hasattr(error, 'output') and error.output: # type: ignore
1536 message += ": {}".format(error.output.decode()) # type: ignore
-> 1537 raise RuntimeError(message) from e
1538
1539
RuntimeError: Error building extension 'inplace_abn': [1/3] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /opt/conda/lib/python3.7/site-packages/torch/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/TH -isystem /opt/conda/lib/python3.7/site-packages/torch/include/THC -isystem /usr/local/cuda/include -isystem /opt/conda/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS
-D__CUDA_NO_HALF_CONVERSIONS
-D__CUDA_NO_HALF2_OPERATORS --expt-relaxed-constexpr -gencode=arch=compute_70,code=sm_70 --compiler-options '-fPIC' --expt-extended-lambda -std=c++14 -c /data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/modules/src/inplace_abn_cuda_half.cu -o inplace_abn_cuda_half.cuda.o
FAILED: inplace_abn_cuda_half.cuda.o
/usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /opt/conda/lib/python3.7/site-packages/torch/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/TH -isystem /opt/conda/lib/python3.7/site-packages/torch/include/THC -isystem /usr/local/cuda/include -isystem /opt/conda/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_70,code=sm_70 --compiler-options '-fPIC' --expt-extended-lambda -std=c++14 -c /data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/modules/src/inplace_abn_cuda_half.cu -o inplace_abn_cuda_half.cuda.o
nvcc fatal : Value 'c++14' is not defined for option 'std'
[2/3] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /opt/conda/lib/python3.7/site-packages/torch/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/TH -isystem /opt/conda/lib/python3.7/site-packages/torch/include/THC -isystem /usr/local/cuda/include -isystem /opt/conda/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_70,code=sm_70 --compiler-options '-fPIC' --expt-extended-lambda -std=c++14 -c /data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/modules/src/inplace_abn_cuda.cu -o inplace_abn_cuda.cuda.o
FAILED: inplace_abn_cuda.cuda.o
/usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -isystem /opt/conda/lib/python3.7/site-packages/torch/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -isystem /opt/conda/lib/python3.7/site-packages/torch/include/TH -isystem /opt/conda/lib/python3.7/site-packages/torch/include/THC -isystem /usr/local/cuda/include -isystem /opt/conda/include/python3.7m -D_GLIBCXX_USE_CXX11_ABI=0 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --expt-relaxed-constexpr -gencode=arch=compute_70,code=sm_70 --compiler-options '-fPIC' --expt-extended-lambda -std=c++14 -c /data/aradml/data/vis/vgupta67/abhinav/panniculectomy/Amandeep/modules/src/inplace_abn_cuda.cu -o inplace_abn_cuda.cuda.o
nvcc fatal : Value 'c++14' is not defined for option 'std'
ninja: build stopped: subcommand failed.

Getting this error while running train.py. Any ideas how we can replace inplaceabn with some other layers/any fix for this error?

Multi gpu train

HI,
when I train with multi gpu, I got that error:

Traceback (most recent call last):
File "train.py", line 231, in
main()
File "train.py", line 189, in main
soft_preds = torch.cat(soft_parsing, dim=0)
RuntimeError: All input tensors must be on the same device. Received cuda:0 and cuda:1

Extract part feature

Hi,I want to know how I can get human part feature in intermediate layers, because the feature maps after Decoder have been the shape of (class_num, w, h) in your model.
I am a newbie in deep learning, maybe my question is silly, but I really want to get your help, thanks!

discussion about the performance improvement

Hi peike,

We have trained the model on our private dataset. We do observe a significant performance improvement compared to our baseline. However, the current implementation follows label refinement process with online averaging. Besides, we have also implemented a version following the original paper, which adopts a offline label update process. The performance is similar but the latter one is slightly better. Any idea why this would happen?

Some problem with tqdm(dataloader). Somehow it couldn't load the image properly

Somehow it couldn't load the image properly
In terminal:
# python simple_extractor.py --dataset 'atr' --model-restore './exp-schp-201908301523-atr.pth' --input-dir './input' --output-dir './output'
Evaluating total class number 18 with ['Background', 'Hat', 'Hair', 'Sunglasses', 'Upper-clothes', 'Skirt', 'Pants', 'Dress', 'Belt', 'Left-shoe', 'Right-shoe', 'Face', 'Left-leg', 'Right-leg', 'Left-arm', 'Right-arm', 'Bag', 'Scarf']
0%| | 0/2 [00:00<?, ?it/s]
Traceback (most recent call last):
File "simple_extractor.py", line 155, in
main()
File "simple_extractor.py", line 128, in main
for idx, batch in enumerate(tqdm(dataloader)):
File "/usr/local/lib/python3.6/dist-packages/tqdm/std.py", line 1130, in iter
for obj in iterable:
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 346, in next
data = self.dataset_fetcher.fetch(index) # may raise StopIteration
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/notebooks/datasets/simple_extractor_dataset.py", line 54, in getitem
h, w, _ = img.shape
AttributeError: 'NoneType' object has no attribute 'shape'

ImportError: /tmp/torch_extensions/inplace_abn/inplace_abn.so: undefined symbol: _ZN3c104impl25tls_local_tensor_type_setEv

Using torch==1.4.0 and torchvision==0.4.0.

In train.py, getting the following error -

Traceback (most recent call last):
File "train.py", line 25, in
import networks
File "/rapids/notebooks/atcdata/rkhilnan/Self-Correction-Human-Parsing/networks/init.py", line 3, in
from networks.AugmentCE2P import resnet101
File "/rapids/notebooks/atcdata/rkhilnan/Self-Correction-Human-Parsing/networks/AugmentCE2P.py", line 21, in
from modules import InPlaceABNSync
File "/rapids/notebooks/atcdata/rkhilnan/Self-Correction-Human-Parsing/modules/init.py", line 1, in
from .bn import ABN, InPlaceABN, InPlaceABNSync
File "/rapids/notebooks/atcdata/rkhilnan/Self-Correction-Human-Parsing/modules/bn.py", line 10, in
from .functions import *
File "/rapids/notebooks/atcdata/rkhilnan/Self-Correction-Human-Parsing/modules/functions.py", line 18, in
extra_cuda_cflags=["--expt-extended-lambda"])
File "/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 658, in load
is_python_module)
File "/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 838, in _jit_compile
return _import_module_from_library(name, build_directory, is_python_module)
File "/conda/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 982, in _import_module_from_library
return imp.load_module(module_name, file, path, description)
File "/conda/lib/python3.7/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/conda/lib/python3.7/imp.py", line 342, in load_dynamic
return _load(spec)

class InPlaceABNSync(nn.Module):

How do you use InPlaceABNsYNC in your project? I want train you code with Pytorch1.3! But I dont know how to use InPlaceABNSync and the usefulness of it. could you please tell me?

no response in train.py

I tried to train on a custom data set for human parsing. code run until this line:
for i_iter, batch in enumerate(train_loader):
and It gets pause in this line and the code does not continue to run.
maybe train_loader object is my problem!?
and after i stop the code manually, show this message:

Traceback (most recent call last):
  File "train.py", line 245, in <module>
    main()
  File "train.py", line 152, in main
    for i_iter, batch in enumerate(train_loader):
  File "/home/deep1/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/home/deep1/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 841, in _next_data
    idx, data = self._get_data()
  File "/home/deep1/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 798, in _get_data
    success, data = self._try_get_data()
  File "/home/deep1/.local/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 761, in _try_get_data
    data = self._data_queue.get(timeout=timeout)
  File "/home/deep1/anaconda3/envs/PressureUlcer/lib/python3.6/queue.py", line 173, in get
    self.not_empty.wait(remaining)
  File "/home/deep1/anaconda3/envs/PressureUlcer/lib/python3.6/threading.py", line 299, in wait
    gotit = waiter.acquire(True, timeout)

No such file or directory: './pretrain_model/resnet101-imagenet.pth'

Hello @PeikeLi
Thank you for your contribution.
I am getting the following error upon running train.py:

_Namespace(arch='resnet101', batch_size=16, cycle_epochs=10, data_dir='./data/LIP', epochs=150, eval_epochs=10, gpu='0,1,2', ignore_label=255, imagenet_pretrain='./pretrain_model/resnet101-imagenet.pth', input_size='473,473', lambda_c=0.1, lambda_e=1, lambda_s=1, learning_rate=0.007, log_dir='./log', model_restore='./log/checkpoint.pth.tar', momentum=0.9, num_classes=20, random_mirror=False, random_scale=False, schp_restore='./log/schp_checkpoint.pth.tar', schp_start=100, start_epoch=0, weight_decay=0.0005)
Traceback (most recent call last):
File "train.py", line 231, in
main()
File "train.py", line 94, in main
AugmentCE2P = networks.init_model(args.arch, num_classes=args.num_classes, pretrained=args.imagenet_pretrain)
File "/home/runque/PycharmProjects/Self-Correction-Human-Parsing-master/networks/init.py", line 13, in init_model
return __factory[name](*args, **kwargs)
File "/home/runque/PycharmProjects/Self-Correction-Human-Parsing-master/networks/AugmentCE2P.py", line 336, in resnet101
initialize_pretrained_model(model, settings, pretrained)
File "/home/runque/PycharmProjects/Self-Correction-Human-Parsing-master/networks/AugmentCE2P.py", line 324, in initialize_pretrained_model
saved_state_dict = torch.load(pretrained)
File "/home/runque/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 584, in load
with _open_file_like(f, 'rb') as opened_file:
File "/home/runque/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 234, in _open_file_like
return _open_file(name_or_buffer, mode)
File "/home/runque/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 215, in init
super(open_file, self).init(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: './pretrain_model/resnet101-imagenet.pth'

A.
I have not found pretrain_model directory within your code - is this something I should get from elsewhere?

B.
Before running simple_extractor, I would have to run train.py - am I correct?

C.
Am I correct in assuming that I would get CHECKPOINT_PATH after running the above train.py ?

Thanks

Always get black image output (all zero label parsing)

Thank you for the sharing code and the model.

I was running the evaluation on LIP with the shared pertaining dataset.
However, for any image, I get the black result output. (even for the images from the training set)

Could you help me with it?
I will appreciate your reply.

How to fine tune pretrained pascal person model on your own data?

Trying to use exp-schp-201908270938-pascal-person-part.pth model for fine tuning on data with number of classes = 3.

Where do I plug in the weights of the model?

Both --model-restore=./pretrain_model/exp-schp-201908270938-pascal-person-part.pth and --schp-restore=./pretrain_model/exp-schp-201908270938-pascal-person-part.pth are throwing errors.

--imagenet-pretrain has to be ./pretrain_model/resnet101-imagenet.pth. So where does the weights of the pascal pretrained model fit in train.py?

trained on custom dataset

Forgive my english skill :)

This is a good work. I tried to train on a custom data set for human parsing. It work good on my dataset. The performance rise about 4%.

But current model is too big for development. @PeikeLi Do you have any idea to speed up the model?

LICENSE

Hi,

thank you for sharing your work.
Could you add a LICENSE file to the repo?

thanks,

Jeremy

License?

Looks interesting - would like to try. Is this MIT license?

Error run "simple_extractor.py"

i run this command:
python simple_extractor.py --dataset pascal --model-restore models/exp-schp-201908270938-pascal-person-part.pth --input input --output output --logits
and get this error:

C:\Users\deep1\anaconda3\envs\PressureUlcer\lib\site-packages\torch\utils\cpp_extension.py:189: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified
  warnings.warn('Error checking compiler version for {}: {}'.format(compiler, error))
INFO: Could not find files for the given pattern(s).
Traceback (most recent call last):
  File "simple_extractor.py", line 24, in <module>
    import networks
  File "D:\Deep1\Projects\pressure-ulcer\Self-Correction-Human-Parsing\networks\__init__.py", line 3, in <module>
    from networks.AugmentCE2P import resnet101
  File "D:\Deep1\Projects\pressure-ulcer\Self-Correction-Human-Parsing\networks\AugmentCE2P.py", line 21, in <module>
    from modules import InPlaceABNSync
  File "D:\Deep1\Projects\pressure-ulcer\Self-Correction-Human-Parsing\modules\__init__.py", line 1, in <module>
    from .bn import ABN, InPlaceABN, InPlaceABNSync
  File "D:\Deep1\Projects\pressure-ulcer\Self-Correction-Human-Parsing\modules\bn.py", line 10, in <module>
    from modules.functions import *
  File "D:\Deep1\Projects\pressure-ulcer\Self-Correction-Human-Parsing\modules\functions.py", line 18, in <module>
    extra_cuda_cflags=["--expt-extended-lambda"])
  File "C:\Users\deep1\anaconda3\envs\PressureUlcer\lib\site-packages\torch\utils\cpp_extension.py", line 658, in load
    is_python_module)
  File "C:\Users\deep1\anaconda3\envs\PressureUlcer\lib\site-packages\torch\utils\cpp_extension.py", line 827, in _jit_compile
    with_cuda=with_cuda)
  File "C:\Users\deep1\anaconda3\envs\PressureUlcer\lib\site-packages\torch\utils\cpp_extension.py", line 876, in _write_ninja_file_and_build
    with_cuda=with_cuda)
  File "C:\Users\deep1\anaconda3\envs\PressureUlcer\lib\site-packages\torch\utils\cpp_extension.py", line 1089, in _write_ninja_file
    'cl']).decode().split('\r\n')
  File "C:\Users\deep1\anaconda3\envs\PressureUlcer\lib\subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "C:\Users\deep1\anaconda3\envs\PressureUlcer\lib\subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['where', 'cl']' returned non-zero exit status 1.

before recent updates, i could run
python evaluate.py --dataset pascal --restore-weight models/exp-schp-201908270938-pascal-person-part.pth --input input --output output --logits
in old code and it works!

My environment :
torch : 1.2.0
os : windows 10
python 3.6

Need to train on Custom Dataset

Hi I need to create part masks for custom dataset i.e. Market-1501 in my case for Person ReID. How can I do that. The issue is files and folder structure for LIP and Market-1501 are not the same. Will you please help me in this regard.

.pth vs .pth.tar

why pretrained model has .pth extension, but own trained model has .pth.tar extension?

Problems with running simple_extractor.py

What is the problem?

python simple_extractor.py --model-restore exp-schp-201908261155-lip.pth  --input-dir input --output-dir output
Traceback (most recent call last):
  File "D:\miniconda3\envs\schp\lib\site-packages\torch\utils\cpp_extension.py", line 1418, in _run_ninja_build
    subprocess.run(
  File "D:\miniconda3\envs\schp\lib\subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "simple_extractor.py", line 24, in <module>
    import networks
  File "D:\Self-Correction-Human-Parsing\networks\__init__.py", line 3, in <module>
    from networks.AugmentCE2P import resnet101
  File "D:\Self-Correction-Human-Parsing\networks\AugmentCE2P.py", line 21, in <module>
    from modules import InPlaceABNSync
  File "D:\Self-Correction-Human-Parsing\modules\__init__.py", line 1, in <module>
    from .bn import ABN, InPlaceABN, InPlaceABNSync
  File "D:\Self-Correction-Human-Parsing\modules\bn.py", line 10, in <module>
    from .functions import *
  File "D:\Self-Correction-Human-Parsing\modules\functions.py", line 10, in <module>
    _backend = load(name="inplace_abn",
  File "D:\miniconda3\envs\schp\lib\site-packages\torch\utils\cpp_extension.py", line 911, in load
    return _jit_compile(
  File "D:\miniconda3\envs\schp\lib\site-packages\torch\utils\cpp_extension.py", line 1100, in _jit_compile
    _write_ninja_file_and_build_library(
  File "D:\miniconda3\envs\schp\lib\site-packages\torch\utils\cpp_extension.py", line 1206, in _write_ninja_file_and_build_library
    _run_ninja_build(
  File "D:\miniconda3\envs\schp\lib\site-packages\torch\utils\cpp_extension.py", line 1436, in _run_ninja_build
    raise RuntimeError(message)
RuntimeError: Error building extension 'inplace_abn': [1/3] cl /showIncludes -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -ID:\miniconda3\envs\schp\lib\site-packages\torch\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\torch\csrc\api\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\TH -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include" -ID:\miniconda3\envs\schp\Include -D_GLIBCXX_USE_CXX11_ABI=0 /MD /wd4819 /EHsc -O3 -c D:\Self-Correction-Human-Parsing\modules\src\inplace_abn.cpp /Foinplace_abn.o
FAILED: inplace_abn.o
cl /showIncludes -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -ID:\miniconda3\envs\schp\lib\site-packages\torch\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\torch\csrc\api\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\TH -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include" -ID:\miniconda3\envs\schp\Include -D_GLIBCXX_USE_CXX11_ABI=0 /MD /wd4819 /EHsc -O3 -c D:\Self-Correction-Human-Parsing\modules\src\inplace_abn.cpp /Foinplace_abn.o
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.28.29914 版
版权所有(C) Microsoft Corporation。保留所有权利。

cl: 命令行 warning D9002 :忽略未知选项“-O3”
注意: 包含文件:  D:\miniconda3\envs\schp\lib\site-packages\torch\include\torch/extension.h
注意: 包含文件:   D:\miniconda3\envs\schp\lib\site-packages\torch\include\torch\csrc\api\include\torch/all.h
注意: 包含文件:    D:\miniconda3\envs\schp\lib\site-packages\torch\include\torch\csrc\api\include\torch/cuda.h
注意: 包含文件:     D:\miniconda3\envs\schp\lib\site-packages\torch\include\torch/csrc/WindowsTorchApiMacro.h
注意: 包含文件:      D:\miniconda3\envs\schp\lib\site-packages\torch\include\c10/macros/Export.h
注意: 包含文件:       D:\miniconda3\envs\schp\lib\site-packages\torch\include\c10/macros/cmake_macros.h
D:\miniconda3\envs\schp\lib\site-packages\torch\include\torch\csrc\api\include\torch/cuda.h(5): fatal error C1083: 无法打开包括文件: “cstddef”: No such file or directory
[2/3] cl /showIncludes -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -ID:\miniconda3\envs\schp\lib\site-packages\torch\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\torch\csrc\api\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\TH -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include" -ID:\miniconda3\envs\schp\Include -D_GLIBCXX_USE_CXX11_ABI=0 /MD /wd4819 /EHsc -O3 -c D:\Self-Correction-Human-Parsing\modules\src\inplace_abn_cpu.cpp /Foinplace_abn_cpu.o
FAILED: inplace_abn_cpu.o
cl /showIncludes -DTORCH_EXTENSION_NAME=inplace_abn -DTORCH_API_INCLUDE_EXTENSION_H -ID:\miniconda3\envs\schp\lib\site-packages\torch\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\torch\csrc\api\include -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\TH -ID:\miniconda3\envs\schp\lib\site-packages\torch\include\THC "-IC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include" -ID:\miniconda3\envs\schp\Include -D_GLIBCXX_USE_CXX11_ABI=0 /MD /wd4819 /EHsc -O3 -c D:\Self-Correction-Human-Parsing\modules\src\inplace_abn_cpu.cpp /Foinplace_abn_cpu.o
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.28.29914 版
版权所有(C) Microsoft Corporation。保留所有权利。

cl: 命令行 warning D9002 :忽略未知选项“-O3”
注意: 包含文件:  D:\miniconda3\envs\schp\lib\site-packages\torch\include\ATen/ATen.h
注意: 包含文件:   D:\miniconda3\envs\schp\lib\site-packages\torch\include\c10/core/Allocator.h
D:\miniconda3\envs\schp\lib\site-packages\torch\include\c10/core/Allocator.h(3): fatal error C1083: 无法打开包括文件: “stddef.h”: No such file or directory
ninja: build stopped: subcommand failed.

setup.py and .pth

I find there is no setup.py and the pre_trained model which you offer is not match the network.
I think you trained the model on another script which you not offer ,recently you improved your script, but you didn't retrained .

Trouble using mhp_extension

Hi,

Thank you for your interesting work.
I've been trying to use the demo.ipynb for multi human parsing but it seems that I need to create the demo_val.json when calling the function register_coco_instances. Could you explain how to use this for my own images ?

Thanks for your help,

Jeremy

Error while running simple_extractor.py

I ran the following command

python simple_extractor.py --dataset 'lip' --input-dir 'images' --model-restore 'pretrained/exp-schp-201908261155-lip.pth' --output-dir 'output'

input image is kept inside images folder
pretrained model is kept inside pretrained folder

I am getting some errors. I do not know how to resolve these errors. Please see the errors below

Screenshot from 2021-02-19 12-23-19
Screenshot from 2021-02-19 12-45-54
:

Let me know what is required to solve the errors

AssertionError when evaluating with batch size > 1

Hello Thanks for the awesome code
I've tried running the evaluation script using batch size > 1, however there's one assertion that failed in that case , it is line :
https://github.com/PeikeLi/Self-Correction-Human-Parsing/blob/eb84c432cc697f494d99662a05f2335eb2f26095/evaluate.py#L202

I printed the content of parsing_preds variable and it seems to contain only len(testloader) elements instead of len(lip_test_dataset). I think something must be broken in the pipeline

some problems when deploy the model to C++ with libtorch.

Hello, I meet some problems when I try to deploy your model to C++ with libtorch.

  1. 'RuntimeError: Only tensors, lists and tuples of tensors can be output from traced functions':

    That's because return [[parsing_result, fusion_result], [edge_result]] in AugmentCE2P.py->ResNet.forward().

    sulution1: change return [[parsing_result, fusion_result], [edge_result]] to return **(**[parsing_result, fusion_result], [edge_result]**)**, or removing '()' is also fine;

    solution2:if only for inference, change return [[parsing_result, fusion_result], [edge_result]] to return fusion_result, because in simple_extractor.py, output = model(image.cuda()) is only be used in upsample_output = upsample(output[0][-1][0].unsqueeze(0)), and fusion_result=output[0][-1].

  2. That's the problem I have not solved correctly.
    Exception: inplace InPlaceABNSync not supported in the JIT

    Well, it seems like that modules.bn.InPlaceABNSync is not supported by libtorch.jit.

    But, if I replace all the InPlaceABNSync layer to torch.nn.BatchNorm2d layer, it dosen't works well, because:
    1. the inference results show not as good as before, is that because the pretrained weight dosen't match well ?
    2. the speed of inference seems to become a bit lower?
    Therefore, I wonder that if I retrain the model (replaced the InPlaceABNSync layer to torch.nn.BatchNorm2d layer) in the 3 datasets, can the model work well as before? By the way, if this method worked, could you please give me links to download the 3 datasets that their structures fit to your training script?
    Or, do you have any methods to solve this problem without replacement and retraining? Thanks a lot!

how to convert the model to onnx?

Dear @PeikeLi,

The results are pretty amazing. I would love to convert the model to onnx for further development.

Here are the steps that I have done:

  1. I loaded the model

  2. Active the inference-mode:
    model = network(num_classes=num_classes, pretrained=None) model = nn.DataParallel(model) state_dict = torch.load(args.restore_weight,map_location=torch.device('cpu')) model.load_state_dict(state_dict) model.train(False)

  3. Set size for input:
    x = torch.randn(batch_size, 3, 512, 512, requires_grad=True)

  4. Export to onnx:
    torch.onnx.export( model.module, # model being run x, 'schp.onnx', export_params=True, # store the trained parameter weights inside the model file opset_version=11, # the ONNX version to export the model to do_constant_folding=True, # whether to execute constant folding for optimization input_names=['input'], # the model's input names output_names=['output'], # the model's output names dynamic_axes={'input': {0: 'batch_size'}, # variable lenght axes 'output': {0: 'batch_size'},}, verbose=False)

However, I am getting the error like this:

RuntimeError: ONNX export failed: Couldn't export operator aten::adaptive_avg_pool2d

Here is the full error message:
pytorch_onnx_error.pdf

I would like to ask if you or anyone have done any of this before, if so Can you please share me the code that you make it work?

Thank you in advance!

Vy

run error: No module named 'ninja'

I have installed ninja. I have also tried several pytorch versions, e.g., 0.4.0 / 1.0.1 / 1.2.0 / 1.6.0 / 1.7.1. It always report the below errors. I do not know how to run this code.


Traceback (most recent call last):
File "/usr/local/bin/ninja", line 6, in
from ninja import ninja
ModuleNotFoundError: No module named 'ninja'
Traceback (most recent call last):
File "/home/shuxj/tool/pycharm/helpers/pydev/pydevd.py", line 1664, in
main()
File "/home/shuxj/tool/pycharm/helpers/pydev/pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/shuxj/tool/pycharm/helpers/pydev/pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/shuxj/tool/pycharm/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/shuxj/work/code/human_parsing/SCHP/SCHP/simple_extractor_ltcc_color.py", line 24, in
import networks
File "/home/shuxj/work/code/human_parsing/SCHP/SCHP/networks/init.py", line 3, in
from networks.AugmentCE2P import resnet101
File "/home/shuxj/work/code/human_parsing/SCHP/SCHP/networks/AugmentCE2P.py", line 21, in
from modules import InPlaceABNSync
File "/home/shuxj/work/code/human_parsing/SCHP/SCHP/modules/init.py", line 1, in
from .bn import ABN, InPlaceABN, InPlaceABNSync
File "/home/shuxj/work/code/human_parsing/SCHP/SCHP/modules/bn.py", line 10, in
from .functions import *
File "/home/shuxj/work/code/human_parsing/SCHP/SCHP/modules/functions.py", line 18, in
extra_cuda_cflags=["--expt-extended-lambda"])
File "/home/shuxj/.conda/envs/schp/lib/python3.5/site-packages/torch/utils/cpp_extension.py", line 658, in load
is_python_module)
File "/home/shuxj/.conda/envs/schp/lib/python3.5/site-packages/torch/utils/cpp_extension.py", line 827, in _jit_compile
with_cuda=with_cuda)
File "/home/shuxj/.conda/envs/schp/lib/python3.5/site-packages/torch/utils/cpp_extension.py", line 850, in _write_ninja_file_and_build
verify_ninja_availability()
File "/home/shuxj/.conda/envs/schp/lib/python3.5/site-packages/torch/utils/cpp_extension.py", line 890, in verify_ninja_availability
subprocess.check_call('ninja --version'.split(), stdout=devnull)
File "/home/shuxj/.conda/envs/schp/lib/python3.5/subprocess.py", line 271, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja', '--version']' returned non-zero exit status 1

train dataset structure?

i want to train pascal model on own dataset. please explain me what is train dataset structure exactly?
annotations image pixels value must between 0 and 7 for each Person Part ??
what is train_id.txt?
thanks

About the Replace all max pooling operation

Hello. Thank you for sharing!
In the PPT about LIP Challenge say,replace all max pooling operation.
But it still have max pooling in the model.
Is my understanding right? How much difference there is between using it and not using it。

How to create bounding box for each class?

How can I create bounding boxes for the different classes? I was not able to find the pixel values for each label in the output segmentation map to create a bounding box for the different classes.

could you provide a detailed environment?

very appreciate your awesome work, but
according to your brief description of the installation requirements, i found that this program can't run at all, and various bugs will appear. just like the error of Segmentation fault (core dumped) caused by InPlaceABNSync. i use batchnorm instead of InPlaceABNSync, but i found the performance is very bad.

tks

RuntimeError while training

Hello @PeikeLi,

I cloned your train code and config to my own dataset like LIP:

However, when I run python train.py this is what I have got:

Screenshot from 2020-06-27 17-02-48

I wanted to ask if this is my mistake?

Some thoughts on the paper.

Hi @PeikeLi,

Great work on the paper and the code.

Finally, I have got my training code running on my custom dataset. While waiting for the model to convergence at 150 epochs.

I reviewed the paper again and have a question about this sentence:

Starting from a model trained on inaccurate annotations as initialization, we design a cyclically learning scheduler to infer more reliable pseudo masks by iteratively aggregating the current learned model with the former optimal one in an online manner. Besides, those corrected labels can in turn to boost the model performance, simultaneously. In this way, the self-correction mechanism will enable the model or labels to mutually promote its counterpart, leading to a more robust model and accurate label masks as training goes on.

  1. Why did you choose the number of epochs as 150?
  2. If I increase the dataset size, will the model get better? There are 2 ways I will have my dataset to increase:
  • Label more data
  • Predict on a new dataset that has the same distribution as my own now.
  1. Have you had any experience working with a much more large dataset other than LIP?

regards,

train code

Can you send me the train code to my email , pls? I want to retrain and modify upsample.
My email: [email protected]
Thanks very much.

Error when training with torch 1.5.1

There are some additional checks added in the pytorch framework which is causing the error when running the training script with torch 1.5.1. With torch version 1.2.0 training proceeds without error.

pytorch/pytorch@3e8d813

python train.py --gpu 0

Traceback (most recent call last):
File "train.py", line 231, in
main()
File "train.py", line 178, in main
preds = model(images)
File "/home/xxx/miniconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "/home/xxx/miniconda3/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 153, in forward
return self.module(*inputs[0], **kwargs[0])
File "/home/xxx/miniconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "/home/xxx/Self-Correction-Human-Parsing/networks/AugmentCE2P.py", line 298, in forward
x = self.relu1(self.bn1(self.conv1(x)))
File "/home/xxx/miniconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "/home/xxx/Self-Correction-Human-Parsing/modules/bn.py", line 119, in forward
self.training, self.momentum, self.eps, self.activation, self.slope)
RuntimeError: Some elements marked as dirty during the forward method were not returned as output. The inputs that are modified inplace must all be outputs of the Function.

confused with consistency loss

Thanks for your excellent work.
My question is as follows:
parsing_pre and edge_pre are all obtained through argmax in the code of consistency loss, are they backpropagable? If not, what positive effects have they brought?

Thanks.

Files check in input directory

Files other than image files will terminate the program. This issue is annoying when you use Jupyter Notebook as it would automatically generate .ipynb_checkpoints in the input directory.

release training code

Could u please release the training code? We want to utilize ur network for other tasks. Thanks a lot.

The effect of the wrong labels in LIP

@PeikeLi
Hi, thanks for your contribution!
Have you evaluated the effect of the wrong labels on the performance?
E.g., what is the mIoU after the model trained with all the wrongly annotated images removed?

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.