Skip to content
Snippets Groups Projects
Commit be07fb4c authored by Baris Büyüktas's avatar Baris Büyüktas
Browse files

Update README.md

parent c03ad242
No related branches found
No related tags found
1 merge request!1Update README.md, data/austria_train.csv, data/switzerland_train.csv,...
# Learning Across Decentralized Multi-Modal Remote Sensing Archives with Federated Learning
This repository contains code of the paper abstract `Learning Across Decentralized Multi-Modal Remote Sensing Archives with Federated Learning` submitted to IEEE International Geoscience and Remote Sensing Symposium (IGARSS) 2023. This work has been done at the [Remote Sensing Image Analysis group](https://www.rsim.tu-berlin.de/menue/remote_sensing_image_analysis_group/) by [Baris Buyuktas](https://rsim.berlin/team/members/baris-buyuktas/), [Gencer Sumbul](https://rsim.berlin/team/members/gencer-sumbul/), and [Begüm Demir](https://begumdemir.com/).
```
This repository contains (in parts) code that has been adapted from:
* https://github.com/InterDigitalInc/CompressAI/
* https://github.com/WeiChengTseng/Pytorch-PCGrad
* https://github.com/intel-isl/MultiObjectiveOptimization
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Introduction
Remote sensing (RS) images are usually stored in compressed format to reduce the storage size of the archives. Thus, existing content-based image retrieval (CBIR) systems in RS require decoding images before applying CBIR (which is computationally demanding in the case of large-scale CBIR problems). To address this problem, in this paper, we present a joint framework that simultaneously learns RS image compression and indexing, eliminating the need for decoding RS images before applying CBIR. The proposed framework is made up of two modules. The first module aims at effectively compressing RS images. It is achieved based on an auto-encoder architecture. The second module aims at producing hash codes with a high discrimination capability. It is achieved based on a deep hashing method that exploits soft pairwise, bit-balancing and classification loss functions. We also propose a two stage learning strategy with gradient manipulation techniques to obtain image representations that are compatible with both RS image indexing and compression.
## Add your files
## Prerequisites
The code in this repository requires Python 3.7.6, pytorch 1.7.0 and ranger coder.
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
The code is tested in Ubuntu 20.04.
An exemplary setup which contains everything needed:
```
cd existing_repo
git remote add origin https://git.tu-berlin.de/rsim/learning-across-decentralized-multi-modal-remote-sensing-archives-with-federated-learning.git
git branch -M main
git push -uf origin main
(1) wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
(2) bash Miniconda3-latest-Linux-x86_64.sh (say yes to append path to bashrc)
(3) source .bashrc
(4) sudo add-apt-repository ppa:ubuntugis/ppa && sudo apt-get update && sudo apt-get install g++
(5) sudo apt-get install libgdal-dev gdal-bin
(6) ogrinfo --version
(7) conda activate base
(9) conda install matplotlib scipy scikit-learn scikit-image tqdm pillow pytorch
(7) pip install wandb glymur pybind11 xlrd faiss-gpu
(10) pip install --global-option=build_ext --global-option="-I/usr/include/gdal/" GDAL==<GDAL VERSION FROM OGRINFO>
(11) python ./hashing-and-compression/compression/cpp_exts/setup.py build
(12) python ./hashing-and-compression/compression/cpp_exts/setup.py install
```
## Integrate with your tools
- [ ] [Set up project integrations](https://git.tu-berlin.de/rsim/learning-across-decentralized-multi-modal-remote-sensing-archives-with-federated-learning/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Datasets
* [BigEarthNet](http://bigearth.net)
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
Downloaded data should be placed in a folder named `Dataset` and keep the original structure as following:
```
Dataset
└───BigEarthNet
| └───S2A_MSIL2A_20170613T101031_0_48
| │ S2A_MSIL2A_20170613T101031_0_48_B0
| │ ...
| ...
|
└───...
```
> **Note**:
> The train/val/test splits of the dataset and its subsets are placed in ./hashing-and-compression/datasets.
>
> To load the data from `memory-map` files for fast processing, set the flag `--flag_npmem` to create and load binary files.
>
> To use the subset data, set the flag `--flag_subset`.
### Logging results with W&B
* Create an account here (free): https://wandb.ai
* After the account is set, make sure to include your API key in `parameters.py` under `--wandb_key`.
* Set the flag `--log_online` to use wandb logging, if the network is unavailable in the training environment, set the flag `--wandb_dryrun` to make wandb store the data locally, and upload the data with the command `wandb sync <$path/wandb/offline..>`
* Set `--project`, `--group` and `--savename` during the training.
## Training
The training of the joint model is divided into two stages, the first stage is done by `train_compression.py`, and the second stage is done by `train.py`.
The training of the hashing baseline is done by `train_hashing.py`.
All the parameters are listed and explained in `parameters.py`.
A set of exemplary runs is provided in `./hashing-and-compression/sample_run`.
If the training is stopped accidentally, it can be resumed by setting `--load_from_checkpoint`, load the check point from `$save_path/every_epoch.pth.tar`.
### Common setups
The following are common setups for all the training scripts:
* `--source_path`: Path for the dataset, eg. `$path/Dataset`.
* `--dataset_name`: Dataset name, choose `BigEarthNet`.
* `--save_path`: Path to save everything.
* `--use_npmem`: Flag. If set, create `memory-map` files and read data from `memory-map` files during training.
* `--flag_subset`: Flag. If set, select subset dataset.
* `--batch_size`: The size of each batch that will be processed.
* `--epochs`: Total number of epochs for training.
### Train joint model
#### Stage 1: train the compression part to a wide range of bit-rates
The script `train_compression.py` expects the following command line arguments:
* `--arch_c`: Compression model architecture.
* `--noBpp_epoch`: Epochs which will not backprop Bpp loss, only applicable for CNN compression model.
* `--iter`: iterations for RNN compression model.
> **Note**:
> flag ` --noBpp_epoch ` sets the number of epochs which trains the distortion loss only in CNN compression model.
>
> When the current epoch is smaller than `--noBpp_epoch`, the checkpoint is saved for the best PSNR on the validation set.
>
> When the current epoch is larger than `--noBpp_epoch`, the checkpoint is saved for current smallest bit-rate on the validation set.
```bash
# CNN compression model
python ./hashing-and-compression/train_compression.py --source_path ./Dataset --dataset_name BigEarthNet --save_path ./output --use_npmem --flag_subset --batch_size 32 --arch_c AttentionResidualJointMixGaussian --epochs 1500 --noBpp_epoch 120 --log_online --project compression_BigEarthNet --group ssim_cnn --savename ssim_cnn
```
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
#### Stage 2: train the framework jointly
The script `train.py` expects the following command line arguments:
* `--load_from_checkpoint`: Path of the pretrained compression model in Stage 1.
* `--flag_start_new`: Flag. If set, reset the initial epoch to 0 and log everything in a new folder.
* `--flag_PCGrad`: Flag. If set, the hashing sublosses are optimized by PCGrad.
* `--arch_h`: Hashing model architecture.
* `--hash_bits`: length of the hashcode.
* `--lr`: learning rate of the compression part, default 1e-7.
* `--hash_lr`: learning rate of the hashing part, default 1e-4.
* `--flag_from_y_hat`: Flag. If set, train hashcodes from quantilized latents.
> **Note**:
> Stage 2 loads the pretrained compression part, and train the comrpession and hashing jointly.
>
> The checkpoint is saved for the best averaged precision on the validation set.
```bash
# The CNN compression part is optimized by MGDA, the hashing part is optimized by PCGrad.
python ./hashing-and-compression/train.py --source_path ./Dataset --dataset_name BigEarthNet --save_path ./output --use_npmem --flag_subset --batch_size 32 --epochs 40 --load_from_checkpoint ./output/ssim_cnn/AttentionResidualJointMixGaussian_bpp0.7.pth.tar --flag_start_new --flag_PCGrad --arch_h MiLAN_SGN_attention --hash_bits 64 --lr 1e-7 --hash_lr 1e-4 --log_online --project hashing_and_compression --group ssim_cnn --savename SSIM_stage2_bpp0.7_hashbits64
```
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
### Train hashing baseline
The script `train_hashing.py` expects the following command line arguments:
* `--arch_autoencoder`: Backbone architecture.
* `--arch_h`: Hashing model architecture.
* `--flag_PCGrad`: Flag. If set, the hashing sublosses are optimized by PCGrad.
* `--flag_dwa`: Flag. If set, the hashing sublosses are optimized by Dynamic Weight Average.
* `--hash_bits`: length of the hashcode.
* `--lr`: learning rate of the backbone, default 1e-4.
* `--hash_lr`: learning rate of the hashing part, default 1e-4.
```bash
# CNN backbone
python ./hashing-and-compression/train_hashing.py --source_path ./Dataset --dataset_name BigEarthNet --save_path ./output --use_npmem --flag_subset --batch_size 32 --epochs 40 --arch_autoencoder AutoencoderAttentionResidual --arch_h MiLAN_SGN --flag_PCGrad --hash_bits 64 --log_online --project hashing --group ssim_cnn --savename hashing_baseline_hashbit64
```
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
## Evaluation
The evaluation results are written into the checkpoint folder.
The script `eval.py` expects the following command line arguments:
* `--dataset_path`: Path for the dataset, eg. `$path/Dataset/BigEarthNet`.
* `--use_npmem`: Flag. If set, create `memory-map` files and read data from `memory-map` files during evaluation.
* `--flag_subset`: Flag. If set, select subset dataset.
* `--batch_size`: The size of each batch that will be processed.
* `--metrics`: List of metrics for evaluating retrieval performance.
* `--K`: Numper of samples to compute metrics.
* `--load_from_checkpoint`: Path of the pretrained models (compression or hashing or both).
* `--entropy_estimation`: Flag. If set, use estimated entropy to evaluate the compression performance.
* `--cuda`: Flag. If set, use cuda during evluation.
* `--flag_hash_from_bits`: Flag. If set, the retrieval is evaluated from hashcodes generated from bitstream.
```bash
# Evaluate the compression and retrieval performance of joint training
python ./hashing-and-compression/eval.py --dataset_path ./Dataset/BigEarthNet --use_npmem --flag_subset --load_from_checkpoint ./output/SSIM_stage2_bpp0.7_hashbits64/AttentionResidualJointMixGaussian_MiLAN_SGN_attention_bpp0.7.pth.tar
```
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
## Authors
**Jun Xiang**
xj.junxiang@gmail.com
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
**Gencer Sümbül**
http://www.user.tu-berlin.de/gencersumbul/
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
**Nimisha Thekke Madam**
nimiviswants@gmail.com
## License
For open source projects, say how it is licensed.
The code in this repository is licensed under the **MIT License**:
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
```
MIT License
Copyright (c) 2022 The Authors of The Paper, "A Novel Framework to Jointly Compress and Index Remote Sensing Images for Efficient Content-based Retrieval"
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment