Home

Awesome

P<sup>2</sup>Net

GitHub stars

Share us a :star: if this repo does help

The official implementation of "Contrastive Learning for Fine-grained Ship Classification in Remote Sensing Images". The paper can be accessed in [IEEE | Lab Server | ResearchGate]. (Accepted by TGRS 2022)

If you encounter any question, please feel free to contact us. You can create an issue or just send email to me windvchen@gmail.com. Also welcome for any idea exchange and discussion.

Updates

Table of Contents

Introduction

Our Network Structure

We focus on the "imbalanced fineness" and "imbalanced appearances" in the fine-grained ship classification task in remote sensing images and propose P<sup>2</sup>Net to address the above issues. P<sup>2</sup>Net is a weakly-supervised method, and can be trained in an end-to-end way. Our P<sup>2</sup>Net can outperform many recent methods in the FGSC task.

Results and Trained Model

Models trained on augmented train dataset

MethodParams(M)FLOPs(G)FGSC-23 (AA)FGSCR-42(AA)
ResNet-5023.64.1286.9291.62
HBPNet``ECCV1874.96.5987.7291.32
DCL``CVPR1923.84.1285.3590.24
TASN``CVPR1934.818.787.0391.85
GFNet``NIPS2056.54.5987.13<ins>92.03</ins>
API-Net``AAAI2023.64.12<ins>87.78</ins>91.47
ProtoTree``CVPR21108.820.784.1789.92
P<sup>2</sup>Net26.94.2388.99<br />[Google Drive | Baidu Pan (code:tr3i)]93.21<br />[Google Drive | Baidu Pan (code:nyro)]

Models trained on original train dataset without pre-augmentations

MethodFGSC-23 (AA)FGSCR-42(AA)
ResNet-5085.6891.85
HBPNet``ECCV18<ins>86.09</ins>92.09
DCL``CVPR1984.3190.65
TASN``CVPR1986.1192.87
GFNet``NIPS2085.37<ins>92.85</ins>
API-Net``AAAI2085.3291.92
ProtoTree``CVPR2180.4679.14
P<sup>2</sup>Net88.56<br />[Google Drive | Baidu Pan (code:4qxh)]94.19<br />[Google Drive | Baidu Pan (code:v06g)]

Preliminaries

Please at first download datasets FGSC-23 [code:n8ra] or FGSCR-42, then prepare the datasets as the following structure:

├── train
        ├── cls 1  # The first class
            ├── img_1.jpg  # The first image, for FGSCR-42 it should be '.bmp'
            ├── img_2.jpg
            ├── ...
        ├── cls 2
        ├── ...
├── valid
├── test

We provide DatasetSplit.py to easily arrange the dataset into the above structure.

To overcome the imbalanced sample issue of the two datasets, you can make use of customTransform.py to augment the fewer-sample subclass in the train dataset. (Please notice that the val/test dataset is not suggested to be augmented, and you can also choose not to augment the train dataset to see the performance of P<sup>2</sup>Net on the imbalanced sample issue.)

You can also find here all the datasets we used for reproduction or comparative experiments: [Baidu Pan (code:4j35) | Google Drive]

Environments

Run Details

Train Process

To train our P^2Net, run:

# For FGSC-23 dataset
python PPNet.py --data FGSC23_path --epochs 100 --workers 4 --batch-size 64 --num_classes 23 --proxy_per_cls 3 --pretrained

# For FGSCR-42 dataset
python PPNet.py --data FGSCR242_path --epochs 100 --workers 4 --batch-size 64 --num_classes 42 --proxy_per_cls 2 --pretrained

To train the baseline, just add --baseline, run:

# For FGSC-23 dataset
python PPNet.py --data FGSC23_path --epochs 100 --workers 4 --batch-size 64 --num_classes 23 --pretrained --baseline

# For FGSCR-42 dataset
python PPNet.py --data FGSCR242_path --epochs 100 --workers 4 --batch-size 64 --num_classes 42 --pretrained --baseline

The architecture is ResNet-50 by default, and you can also change --arch to other architecture like "densenet121" or so on by your preference. The train results will be saved in model/expX.

Test Process

Just add --test and determine --test_model_path when to conduct an inference.

To test our P^2Net, run:

# For FGSC-23 dataset
python PPNet.py --data FGSC23_path --epochs 100 --workers 4 --batch-size 64 --num_classes 23 --proxy_per_cls 3 --test --test_model_path model_path

# For FGSCR-42 dataset
python PPNet.py --data FGSCR42_path --epochs 100 --workers 4 --batch-size 64 --num_classes 42 --proxy_per_cls 2 --test --test_model_path model_path

To test the baseline, run:

# For FGSC-23 dataset
python PPNet.py --data FGSC23_path --epochs 100 --workers 4 --batch-size 64 --num_classes 23 --baseline --test --test_model_path model_path

# For FGSCR-42 dataset
python PPNet.py --data FGSCR42_path --epochs 100 --workers 4 --batch-size 64 --num_classes 42 --baseline --test --test_model_path model_path

Visualization

We provide two visualization tools drawCM.py and tsne.py. You can make use of them and modify PPNet.py a bit to visualize the confusion matrix or t-SNE results.

Citation

If you find this paper useful in your research, please consider citing:

@ARTICLE{9832938,  
 author={Chen, Jianqi and Chen, Keyan and Chen, Hao and Li, Wenyuan and Zou, Zhengxia and Shi, Zhenwei},  
 journal={IEEE Transactions on Geoscience and Remote Sensing},   
 title={Contrastive Learning for Fine-Grained Ship Classification in Remote Sensing Images},   
 year={2022},  
 volume={60},  
 number={},  
 pages={1-16},  
 doi={10.1109/TGRS.2022.3192256}}

License

This project is licensed under the MIT License. See LICENSE for details