Giter Site home page Giter Site logo

deephyperx's Introduction

DeepHyperX

A Python tool to perform deep learning experiments on various hyperspectral datasets.

https://www.onera.fr/en/research/information-processing-and-systems-domain

https://www-obelix.irisa.fr/

Reference

This toolbox was used for our review paper in Geoscience and Remote Sensing Magazine :

N. Audebert, B. Le Saux and S. Lefevre, "Deep Learning for Classification of Hyperspectral Data: A Comparative Review," in IEEE Geoscience and Remote Sensing Magazine, vol. 7, no. 2, pp. 159-173, June 2019.

Bibtex format :

@article{8738045, author={N. {Audebert} and B. {Le Saux} and S. {Lefèvre}}, journal={IEEE Geoscience and Remote Sensing Magazine}, title={Deep Learning for Classification of Hyperspectral Data: A Comparative Review}, year={2019}, volume={7}, number={2}, pages={159-173}, doi={10.1109/MGRS.2019.2912563}, ISSN={2373-7468}, month={June},}

Requirements

This tool is compatible with Python 2.7 and Python 3.5+.

It is based on the PyTorch deep learning and GPU computing framework and use the Visdom visualization server.

Setup

The easiest way to install this code is to create a Python virtual environment and to install dependencies using: pip install -r requirements.txt

(on Windows you should use pip install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html)

Docker

Alternatively, it is possible to run the Docker image.

Grab the image using:

docker pull registry.gitlab.inria.fr/naudeber/deephyperx:preview

And then run the image using:

docker run -p 9999:8097 -ti --rm -v `pwd`:/workspace/DeepHyperX/ registry.gitlab.inria.fr/naudeber/deephyperx:preview

This command:

  • starts a Docker container using the image registry.gitlab.inria.fr/naudeber/deephyperx:preview
  • starts an interactive shell session -ti
  • mounts the current folder in the /workspace/DeepHyperX/ path of the container
  • binds the local port 9999 to the container port 8097 (for Visdom)
  • removes the container --rm when the user has finished.

All data and products are stored in the current folder.

Users can build the Docker image locally using the Dockerfile using the command docker build ..

Hyperspectral datasets

Several public hyperspectral datasets are available on the UPV/EHU wiki. Users can download those beforehand or let the tool download them. The default dataset folder is ./Datasets/, although this can be modified at runtime using the --folder arg.

At this time, the tool automatically downloads the following public datasets:

  • Pavia University
  • Pavia Center
  • Kennedy Space Center
  • Indian Pines
  • Botswana

The Data Fusion Contest 2018 hyperspectral dataset is also preconfigured, although users need to download it on the DASE website and store it in the dataset folder under DFC2018_HSI.

An example dataset folder has the following structure:

Datasets
├── Botswana
│   ├── Botswana_gt.mat
│   └── Botswana.mat
├── DFC2018_HSI
│   ├── 2018_IEEE_GRSS_DFC_GT_TR.tif
│   ├── 2018_IEEE_GRSS_DFC_HSI_TR
│   ├── 2018_IEEE_GRSS_DFC_HSI_TR.aux.xml
│   ├── 2018_IEEE_GRSS_DFC_HSI_TR.HDR
├── IndianPines
│   ├── Indian_pines_corrected.mat
│   ├── Indian_pines_gt.mat
├── KSC
│   ├── KSC_gt.mat
│   └── KSC.mat
├── PaviaC
│   ├── Pavia_gt.mat
│   └── Pavia.mat
└── PaviaU
    ├── PaviaU_gt.mat
    └── PaviaU.mat

Adding a new dataset

Adding a custom dataset can be done by modifying the custom_datasets.py file. Developers should add a new entry to the CUSTOM_DATASETS_CONFIG variable and define a specific data loader for their use case.

Models

Currently, this tool implements several SVM variants from the scikit-learn library and many state-of-the-art deep networks implemented in PyTorch.

Adding a new model

Adding a custom deep network can be done by modifying the models.py file. This implies creating a new class for the custom deep network and altering the get_model function.

Usage

Start a Visdom server: python -m visdom.server and go to http://localhost:8097 to see the visualizations (or http://localhost:9999 if you use Docker).

Then, run the script main.py.

The most useful arguments are:

  • --model to specify the model (e.g. 'svm', 'nn', 'hamida', 'lee', 'chen', 'li'),
  • --dataset to specify which dataset to use (e.g. 'PaviaC', 'PaviaU', 'IndianPines', 'KSC', 'Botswana'),
  • the --cuda switch to run the neural nets on GPU. The tool fallbacks on CPU if this switch is not specified.

There are more parameters that can be used to control more finely the behaviour of the tool. See python main.py -h for more information.

Examples:

  • python main.py --model SVM --dataset IndianPines --training_sample 0.3 This runs a grid search on SVM on the Indian Pines dataset, using 30% of the samples for training and the rest for testing. Results are displayed in the visdom panel.
  • python main.py --model nn --dataset PaviaU --training_sample 0.1 --cuda This runs on GPU a basic 4-layers fully connected neural network on the Pavia University dataset, using 10% of the samples for training.
  • python main.py --model hamida --dataset PaviaU --training_sample 0.5 --patch_size 7 --epoch 50 --cuda This runs on GPU the 3D CNN from Hamida et al. on the Pavia University dataset with a patch size of 7, using 50% of the samples for training and optimizing for 50 epochs.

Say Thanks!

deephyperx's People

Contributors

ayush-iitkgp avatar nshaud avatar romain3ch216 avatar thortom avatar ucalyptus 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

deephyperx's Issues

Add support for unsupervised models

Maybe out of scope for this toolbox.

The toolbox currently work with the assumption that the models are supervised. Working with unsupervised models (e.g. autoencoders) could be helpful.

  • Support other criterions in models.py (easy)
  • Support other metrics in metrics() (medium)
  • Either support no target or target = data (e.g. autoencoder) (hard)

How to create DFC2018_HSI dataset

Downloaded DFC2018_HSI dataset, not found

Hainan -2018_ IEEE_ GRSS_ DFC_ GT_ TR.tif
Hainan -2018_ IEEE_ GRSS_ DFC_ HSI_ TR
Hainan -2018_ IEEE_ GRSS_ DFC_ HSI_ TR.aux.xml
Hainan -2018_ IEEE_ GRSS_ DFC_ HSI_ TR.HDR

I would like to know how you configured these files. Thank you very much

How to use the disjoint mode?

Hello,

Can anyone teach me how to use the disjoint mode correctly please?

I use the below command but the code cannot be run.
!python main.py --model SVM --dataset IndianPines --sampling_mode disjoint --cuda 0

I also tried to find if there were training and testing split samples on the GRSS DASE Website to download. However, there are only testing samples to download.

Here is the environment I used:

  • OS: Google Colab
  • CUDA : yes

can't reproduce the results

HI ~
Thanks for your great work, Recently I am trying to reproduce the experiment on paper. But I found there are no accurate experiment settings in the part of the experiment. I am wondering if you can give me some suggestions on the initialization of the parameters. Such as the learning_rate、training_sample etc.

Here is the result by using the command python main.py --model hamida --dataset IndianPines --training_sample 0.1 --cuda 0.
I found its accuracy has a margin comparing the result on paper.

image

Looking forward to your early reply ~ Thanks for your consideration.

Can't obtain Table III results with Li's 3D CNN network

Hi,
I am testing Li's 3D CNN network on IndianPines dataset. In table III in disjoint mode, you have an accuracy of 75%. I can't reach more than 65%.

  • Are the default parameters of the network (lr = 0.01, epoch = 200, patch_size = 5, momentum=0.9, weight_decay = 5e-4, n_planes = 16) the ones you have used ? In particular, in the original paper, n_planes = 2
  • Did you just apply flip_augmentation or also mixture_augmentation or radiation_augmentation ? Even with those it doesn't work.
  • The other parameters I used : training_sample = 0.9, default batch_size, class_balancing=True

Thank you :)

Refactor

  • Rewrite disjoint sampling method
  • Move sklearn models into their own file
  • Rewrite the Dataset
  • Add parallelization option (see #32)
  • Use a unique IGNORED_INDEX value for all ignored pixels
  • Use sklearn.metrics everywhere needed (especially in validation)
  • Move data exploration/data visualization functions into their own file
  • Rewrite the build_dataset function
  • Main script uses a main function
  • Unify val and test function
  • Deal with the varying tensor sizes when using : spectra (1D), images (2D), cubes (3D).
  • Unify segmentation and classification datasets
  • Use Sequential API for simple models
  • Add --overlap options for training and test
  • Use scheduler/auto LR reduction (see #22)
  • Save output image after training
  • Rewrite data augmentation as torchvision.transforms (see #33)
  • Move downloaders into their own script
  • Add other class balancing schemes (see #39)
  • Add IoU/dice score loss
  • Improve cross-validation support
  • Optional: Simplify dataset configuration
  • Optional: Support defining a dataset as a collection of HSI images and GT masks

Why the lose value is Nan at the beginning of training sometimes?

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior (e.g. the command that you used).

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: [e.g. Linux/Windows]
  • CUDA : yes/no

Use block-wise spatial sampling for train/test splitting

The current spatially disjoint train/test split divides the image in 2 for each class. However there might be spatial correlations between the pixels for those regions and this approach is not well-suited to repeated runs or cross-validation anyway. A more robust way to perform a spatially disjoint split is to extract random blocks (i.e. windows larger than the model's patch size) with constraints on class percentages.

See e.g. BlockCV that does this kind of thing in R.

How to set `ignored_labels`

Hello, Recently,I miss a question .I want to omit some label_values in My Training set .
Please tell me how to set ignored_labels

Have issue with the 'disjoint' eksperiment

Hi, I have tried to run your code with "hu" model and sampling_mode "disjoint". However, I got a worse result than the result in Table 3 of your paper. Is there any specific setting for the result of Table 3? Thank you very much.

Prediction vs test_gt

Describe the bug
I am encountering an issue with the prediction versus test_gt (labels border are eliminated) for the 'Sharma' and 'Chen' models in my project. The predictions seem to be inconsistent or incorrect compared to the ground truth labels.

Expected behavior
I expect the model to generate a full prediction image that includes the border labels, accurately capturing the entire image.

Desktop :

  • OS: Windows
    screenshot

About the model "Sharma(2DCNN)"

Hi, I'm very thanks for your great work. Here, I have a question about the model "sharma" to ask for your help.

I can't understand the input "x" of the network,
why "'" x = torch.zeros( (1, 1, self.input_channels, self.patch_size, self.patch_size))"'"?
what is """b, t, c, w, h = x.size()"""?

I am looking for your apply, thanks!

Salinas loading

I have suffered from loading failure before I examine the name of the data.
Now code runs after
#img = open_file(folder + 'Salinas.mat')['Salinas_corrected']
img = open_file(folder + 'Salinas_corrected.mat')['salinas_corrected']
#gt = open_file(folder + 'Salinas_gt.mat')['Salinas_gt']
gt = open_file(folder + 'Salinas_gt.mat')['salinas_gt']

Parallelize data loading

Currently, the torch DataLoader uses blocking data loading. Although loading is very fast (we store the NumPy arrays in-memory), transfer to GPU and data augmentation (which is done on CPU) can slow things done.

Using workers > 0 would make data loading asynchronous and workers > 1 could increase speed somewhat.

TODO:

  • Benchmark speed gain using asynchronous data loading
  • Implement asynchronous data loading for all DataLoader objects
  • Add a user-input option to define the number of jobs

OSError: [Errno 22] Invalid argument

Traceback (most recent call last): File "main.py", line 312, in <module> display=viz) File "C:\Users\yang6\PycharmProjects\DeepHyperX\models.py", line 1059, in train save_model(net, camel_to_snake(str(net.__class__.__name__)), data_loader.dataset.name, epoch=e, metric=abs(metric)) File "C:\Users\yang6\PycharmProjects\DeepHyperX\models.py", line 1068, in save_model torch.save(model.state_dict(), model_dir + filename + '.pth') File "C:\Users\yang6\Anaconda3\envs\DeepHyperX\lib\site-packages\torch\serialization.py", line 260, in save return _with_file_like(f, "wb", lambda f: _save(obj, f, pickle_module, pickle_protocol)) File "C:\Users\yang6\Anaconda3\envs\DeepHyperX\lib\site-packages\torch\serialization.py", line 183, in _with_file_like f = open(f, mode) **OSError: [Errno 22] Invalid argument: './checkpoints/hamida_et_al/PaviaU/2020-07-03 10:52:46.094626_epoch2_0.78.pth'**

I am very confused about this error. How to solve it?

Defined hyperspectral-specific Transforms

torchvision defines Transforms objects to apply data augmentation and other transformations to data.

We could and should define our own custom Transforms.

Pros:

  • easier to reuse the data augmentation transforms that we implement
  • easier to apply various kinds of DA in the toolbox

Cons:

  • adds an external dependency to torchvision

Batch training

I'm trying to train a model with multiple images at once.
It seems I need to change the DATASETS_CONFIG.
If anyone has any insight into what the method is, your thoughts would be much appreciated.

Class balancing/resampling

Current approach to class balancing is to use inverse median frequency loss reweighting.

Other options could be:

Resampling

Resample the dataset (e.g. upsample minority classes or downsamples majority classes)

  • Static resampling before constructing the train Dataset
  • Dynamic resampling in the DataLoader

Loss balancing

  • IMF, this is what we do.
  • IF, ignore the median cost.
  • others?

Why ignored label appeared in prediction map?

Sorry, I`m bothering you again.

I meeted a problem again:
1. I trained some model and the result is bad
2. In the final Confusion matrix ,there appeared a lot of elements in Undefined column.

Confusion matrix :
[[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[ 0 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[ 0 0 568 0 0 0 0 0 0 0 0 1 2 0 0 0 0]
[ 66 0 1 265 0 0 0 0 0 0 0 0 0 0 0 0 0]
[ 5 0 0 0 90 0 0 0 0 0 0 0 0 0 0 0 0]
[ 27 0 0 0 0 166 0 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 292 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0]
[ 11 0 0 0 0 0 0 0 180 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0]
[ 31 0 0 0 0 0 0 0 0 0 358 0 0 0 0 0 0]
[ 36 0 0 0 0 0 0 0 0 0 0 946 0 0 0 0 0]
[ 14 0 0 0 0 0 0 0 0 0 0 0 223 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 82 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 506 0 0]
[ 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 105 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 35]]---

I feel this is not reasonable.I think that it makes the model to influence the final bad result

Is there any way to solve this problem?

@nshaud

Defining Train Set and Test Set

Hi,

Anyone know how to define the training and test set?

I have the GT defined in a mat file and I put the path in but it comes back with the following error:

python main.py --model nn --dataset Selene1TestX --train_set C:\Users\bbop1\hsi-toolbox-master\DeepHyperX\Datasets\Selene1TrainX\Sub1TargetMapPyTrainX.mat --cuda 0

Setting up a new session...
Image has dimensions 1250x1596 and 134 channels
Traceback (most recent call last):
File "main.py", line 275, in
test_gt[(train_gt > 0)[:w,:h]] = 0
TypeError: '>' not supported between instances of 'dict' and 'int'

I have a feeling the train gt needs to be defined as a dictionary. Has anyone done this?

Cheers,

Bop

“loss ” is very large

Hi, When I run 'python main.py --model hu --dataset IndianPines --training_sample 0.1 --cuda 0', the loss is over 2.
And it's useless to change the training_sample, because it's still over 1.
How can I solve it?
Would you please give me the best train parameters?
Thank you very much.

problem for weights with ignore_label

Describe the bug
when i run this demo,the result of confusion matrix is not correct, cm[0,0] always equals to zero. so i check the parameters of weight, 'weights': tensor([0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,])
the weights[0] is always 0.
the function of get_model instantiate the weights.
weights = torch.ones(n_classes)
weights[torch.LongTensor(kwargs["ignored_labels"])] = 0.0
i think it maybe casued by the ignored_labels=[0]
so, i replace ignored_labels=[] instead of ignored_labels=[0]
but it don't work
when i delete or comment out weights[torch.LongTensor(kwargs["ignored_labels"])] = 0.0
the initial values weight, 'weights': tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,])

when , i replace ignored_labels=[2] instead of ignored_labels=[0]
the values weight, 'weights': tensor([0., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,])
anywhere,weights[0] always equals to zero.
To Reproduce
Steps to reproduce the behavior (e.g. the command that you used).

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: window
  • CUDA : yes

Visdom server does not work

visdom_error

The visdom server does not show any of the visualizations during or after training, as shown attached. Any fixes for this?

Docker repository doesn't exist

Hi, thank you very much for such a great tool.
I was trying like to grab a Docker image but seems that it doesn't exist. Would you please upload it once again so I could copy the image?

(base) alexanch@alexanch:~/docker$ docker pull registry.gitlab.inria.fr/naudeber/deephyperx:preview
Error response from daemon: manifest for registry.gitlab.inria.fr/naudeber/deephyperx:preview not found

Inverse Median Frequency Weights functioning?

Hi!

I was using this framework (thank you), but I cannot understand if the inverse median frequency weights are called at all? For me it seems they are created after constructing the loss function and thus never passed anywhere. Is this assumption wrong on my part? Where do they come into play? I assumed the weights would have been passed to the get_model function through the hyperparameters, then used to construct the loss function and not be overwritten by the new initialization of the weight vector. Thank you!

Tensorboard

Migrate visualization from Visdom to Tensorboard

/bin/sh: 0: Can't open start.sh

Hello,

I tried running the container on both Docker and Singularity; however, I am getting this error "/bin/sh: 0: Can't open start.sh". Is there a way to fix this?

This is the command I ran on Docker docker run -p 9999:8097 -ti --rm -v pwd:/workspace/DeepHyperX/ registry.gitlab.inria.fr/naudeber/deephyperx:rc2 and on Singularity singularity run ./deephyperxtest_latest.sif.

Thank you!

Attribute of input is error when summary is running

Attribute of input is error when summary in main.py is running.
When I go to 'python main.py --model conv3d --dataset IndianPines --training_sample 0.05 --cuda 0' , I see error 'AttributeError: 'builtin_function_or_method' object has no attribute 'size' '.Error code:'summary(model.to(hyperparams["device"]), input.size()[1:])'
Conv3d model is added by myself.

How to get stable results?

Thanks for your great work!
I run the code and set "--run 10", but the results of each run fluctuate wildly.
I adjusted lr, batchsize ..., but it didn't work.
Could you give me some advice? thank you!

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.