Code Monkey home page Code Monkey logo

deep-ordinal-classification-with-inequality-constraints's Introduction

Please report any issue through the issue tool of Github and not through email.

Pytorch code for: Non-parametric Uni-modality Constraints for Deep Ordinal Classification

@article{belharbi2019unimoconstraints,
  title={Non-parametric Uni-modality Constraints for Deep Ordinal Classification},
  author={Belharbi, S. and Ben Ayed, I. and McCaffrey, L. and Granger, E.},
  journal={coRR},
  volume={abs/1911.10720},
  year={2019}
}

Content:

Method overview:

Posterior probability consistency in ordinal classification:

intuition

Prediction over FGNET dataset with 70 classes (test samples. More results over other datasets are in ./demo.md):

example

Experimental results:

example

example

Download datasets:

See ./cmds on how to download the datasets. You find the splits in ./folds. Unzip first (folds.zip). The code that generated the splits is ./create_folds.py.

Requirements:

We use Pytorch 1.2.0 and Python 3.7.0. For installation, see ./dependencies for a way on how to install the requirements within a virtual environment.

How to run the code:

python main.py --cudaid your_cuda_id --yaml basename_your_yaml_file

You can override the values of the yaml file using command line:

python main.py --cudaid 1 --yaml bach-part-a-2018.yaml --bsize 8 --lr 0.001 --wdecay 1e-05 --momentum 0.9 --epoch 4 --stepsize 100 --modelname resnet18 --alpha 0.6 --kmax 0.1 --kmin 0.1 --dout 0.0 --modalities 5 --pretrained True  --dataset bach-part-a-2018 --split 0 --fold 0  --loss LossCE

See all the keys that you can override using the command line in tools.get_yaml_args(). You can generate the yaml files using ./yaml-gen.py

General notes:

  • All the experiments, splits generation were achieved using seed 0. See ./create_folds.py
  • All the results in the paper were obtained using one GPU with 16GB (not really used) of memory and less than 10GB of RAM.
  • Please report any issue with reproducibility.

Paths:

You need to to set the paths to the data on your own. An error will be raised when the host is not recognized. See the function in tools.get_rootpath_2_dataset().

Reproducibility

Reproducibility (Single GPU: 100% reproducible):

We took a particular care to the reproducibility of the code.

Completely reproducible results are not guaranteed across PyTorch releases, individual commits or different platforms. Furthermore, results need not be reproducible between CPU and GPU executions, even when using identical seeds.

  • The code is guaranteed to be reproducible over the same device INDEPENDENTLY OF THE NUMBER OF WORKERS (>= 0). You have to use a seed in order to obtain the same results over two identical runs. See ./reproducibility.py
  • Samples can be preloaded in memory to avoid disc access. See ./loader.PhotoDataset(). DEFAULT SEED IS 0 which we used in all our experiments.
  • Samples can be preloaded AND preprocessed AND saved in memory (for inference, i.e., test). However, for large dataset, and when the pre-processing aims at increasing the size of the data (for instance, upsampling), this is to be avoided. See ./loader.PhotoDataset()
  • We decorated sensitive operations that use random generators by a fixed seed. This allowed more flexibility in terms of reproducibility. For instance, if you decide to switch off pre-processing samples of a dataset (given that such operation relies heavily on random generators) and do the processing on the fly, such a decorator seed allows the state of the random generators in the following code to be independent of the results of this switch. This is a work-around. In the future, we consider more clean, and easy way to make the operations that depend on random generator independent of each other.

MultiGPU support and reproducibility (100% reproducibility not guaranteed. Sometimes the results are different, but most of the time the results are constant):

  • The code supports MultiGPUs.
  • Despite our effort to make the code reproducible in the case of multigpu, we achieve reproducibility but, sometimes it breaks. See this.

Synchronized-Batch-Norm support (MultiGPUs):

The code supports synchronized BN. By default, SyncBN is allowed as long as multigpu mode is on. You can prevent using SynchBN, and get back to the standard Pytroch non-synchronized BN, using bash command, before running the code:

# $ export ACTIVATE_SYNC_BN="True"   ----> Activate the SynchBN
# $ export ACTIVATE_SYNC_BN="False"   ----> Deactivate the SynchBN

All the credits of the SynchBN go to Tamaki Kojima([email protected]) (https://github.com/tamakoji/pytorch-syncbn).

deep-ordinal-classification-with-inequality-constraints's People

Contributors

sbelharbi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

wanli-19

deep-ordinal-classification-with-inequality-constraints's Issues

KeyError: Caught KeyError in DataLoader worker process 0.

================================================================================
START TRAINING

0%| | 0/80 [00:00<?, ?it/s]
['/Deep-Ordinal-Classification-with-Inequality-Constraints/cmds/FGNET/images/035A07.JPG', '7']
['
/Deep-Ordinal-Classification-with-Inequality-Constraints/cmds/FGNET/images/058A03.JPG', '3']
['/Deep-Ordinal-Classification-with-Inequality-Constraints/cmds/FGNET/images/058A05.JPG', '5']
['
/Deep-Ordinal-Classification-with-Inequality-Constraints/cmds/FGNET/images/003A38.JPG', '38']
['/Deep-Ordinal-Classification-with-Inequality-Constraints/cmds/FGNET/images/055A08.JPG', '8']
['
/Deep-Ordinal-Classification-with-Inequality-Constraints/cmds/FGNET/images/010A04.JPG', '4']
Traceback (most recent call last):
File "main.py", line 333, in
training_log, ALLOW_MULTIGPUS=ALLOW_MULTIGPUS, NBRGPUS=NBRGPUS)
File "/home/vishwa/Deep-Ordinal-Classification-with-Inequality-Constraints/deeplearning/train.py", line 48, in train_one_epoch
enumerate(dataloader), ncols=80, total=length):
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/tqdm/_tqdm.py", line 897, in iter
for obj in iterable:
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 345, in next
data = self._next_data()
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 856, in _next_data
return self._process_data(data)
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 881, in _process_data
data.reraise()
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/torch/_utils.py", line 394, in reraise
raise self.exc_type(msg)
KeyError: Caught KeyError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/vishwa/anaconda3/envs/env_souf/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/vishwa/Deep-Ordinal-Classification-with-Inequality-Constraints/loader.py", line 634, in getitem
img, mask, target = self.load_sample_i(index)
File "/home/vishwa/Deep-Ordinal-Classification-with-Inequality-Constraints/loader.py", line 464, in load_sample_i
label = self.get_original_input_label_int(i)
File "/home/vishwa/Deep-Ordinal-Classification-with-Inequality-Constraints/loader.py", line 450, in get_original_input_label_int
return self.name_classes[label_str]
KeyError: 16

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.