Coder Social home page Coder Social logo

shreyaskamathkm / ftnet Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 3.0 624 KB

Pytorch implementation of FTNet for Semantic Segmentation on SODA, SCUT Seg, and MFN Datasets

License: Other

Shell 2.16% Python 96.10% MATLAB 1.74%
convolutional-neural-networks semantic-segmentation thermal-imaging encoder-decoder-model pytorch pytorch-lightning edge-detection python3 deep-learning

ftnet's Introduction

PWC

PWC

PWC

FTNet

This repository is an official PyTorch implementation of the paper " FTNet: Feature Transverse Network for Thermal Semantic Segmentation "

Main Figure We provide scripts for the models from our paper. You can train your own model from scratch, or use pretrained models for testing.

FTNet Model Weights

Model weights are provided for ResNeXt50 and ResNeXt101.

For user convenience, the Thermal Cityscape pretrained model and weights for all datasets are provided here.

This link also provides the semantic maps generated during testing phase.

Highlight:

  • Completely Built on Pytorch Lightning with well designed code structures. This comes with built in DistributedDataParallel, DataParallel support.
  • All initialization models, trained models and predictions are available.
  • Can be easily used to plug in new models with minimal changes.

Requirements

  • Hardware: 1 - 2 GPUs (better with >=11G GPU memory)
  • Python 3.8
  • Pytorch >=1.6 (Code tested on 1.6)

Code

Clone this repository into any place you want.

git clone https://github.com/shreyaskamathkm/FTNet.git
cd FTNet

Dependencies

Please run the following to meet the requirements of the model

pip install -r requirements.txt

Setting up the environment for training and testing

We train and test the models on three dataset:

Extracting Dataset

Please download all the datasets from the link provided above. Once downloaded, run the following commands to get the dataset into the following data structure.

For simplicity sake, consider all the images are downloaded to a folder name Raw_Dataset. The rest of the steps are as follows

For Cityscapes thermal dataset

cd Codes/src/datasets/utils/  # You are now in */src/datasets/utils/
python Cityscape_folderMap.py --input-image-path /raw_dataset/SODA-20211127T202136Z-001/SODA/TIR_leftImg8bit/ --save-path /Processed_dataset/

For SODA thermal dataset

cd Codes/src/datasets/utils/  # You are now in */src/datasets/utils/
python SODA_folderMap.py --input-image-path /raw_dataset/SODA-20211127T202136Z-001/SODA/InfraredSemanticLabel/ --save-path /Processed_dataset/

For SCUTSeg thermal dataset

cd Codes/src/datasets/utils/  # You are now in */src/datasets/utils/
python scutseg_foldermap.py --input-image-path /raw_dataset/SCUT-SEG/ --save-path /Processed_dataset/

For MFN thermal dataset

cd Codes/src/datasets/utils/  # You are now in */src/datasets/utils/
python MFNDataset_folderMap.py --input-image-path /raw_dataset/ir_seg_dataset/ --save-path /Processed_dataset/

Generating Edges

Please Note: Current implementation requires MATLAB to generate edges.

cd Codes/src/datasets/edge_generation/
Change the path in the 'main.m' file and run it to generate edges

Dataset Structure

Once the extracting and edge generation is completed, the dataset looks similar to the structure provided below:

├── ...
├── Processed_dataset                                            # Dataset Folder
│   ├── Cityscapes_thermal
│   	├── CITYSCAPE_5000
│           ├── edges
│   	        └── train
│   	    ├── image
│   	        └── train
│   	    └── mask
│   	        └── train
│   ├── SODA
│           ├── edges
│   	        ├── train
│   	        ├── val
│   	        └── test
│   	    ├── image
│   	        ├── train
│   	        ├── val
│   	        └── test
│   	    └── mask
│   	        ├── train
│   	        ├── val
│   	        └── test
│   ├── MFNDataset
│           ├── edges
│   	        ├── train
│   	        ├── val
│   	        └── test
│   	    ├── image
│   	        ├── train
│   	        ├── val
│   	        └── test
│   	    └── mask
│   	        ├── train
│   	        ├── val
│   	        └── test
│   ├── SCUTSEG
│           ├── edges
│   	        ├── train
│   	        └── val
│   	    ├── image
│   	        ├── train
│   	        └── val
│   	    └── mask
│   	        ├── train
│   	        └── val
└── ...

The new processed dataset will be used for training purposes. You can now train FTNet by yourself. Training and testing script is provided in the */FTNet/Codes/src/bash folder. Before you run them, please fill in the appropriate details in the .sh file before you execute.

cd /Codes/src/bash       # You are now in */src/bash/
bash Train_and_test.sh     # To train and test one dataset. eg: SODA
cd /Codes/src/bash       # You are now in */src/bash/
bash Train_and_test_all.sh     # To train and test more than one dataset. eg: SODA, MFN, SCUT-Seg

License

Please read the LICENSE file in the repository

Citation

If you find the code or trained models useful, please consider citing:

@ARTICLE{9585453,  
author={Panetta, Karen and Shreyas Kamath, K. M. and Rajeev, Srijith and Agaian, Sos S.},
journal={IEEE Access},   
title={FTNet: Feature Transverse Network for Thermal Image Semantic Segmentation},   
year={2021},  
volume={9},  
number={},  
pages={145212-145227},  
doi={10.1109/ACCESS.2021.3123066}}

References

ftnet's People

Contributors

harsh188 avatar shreyaskamathkm avatar srijithrajeev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ftnet's Issues

ModuleNotFoundError: No module named 'core.utils.download'

Description

There is no core.utils.download but it's being imported in the init.py file under core/utils.

Log

Traceback (most recent call last):
  File "./../lightning_scripts/main.py", line 19, in <module>
    from trainers import thermal_edge_trainer
  File "/home/hmohan/Programming/T-SegModels/FTNet/Codes/src/lightning_scripts/trainers/__init__.py", line 1, in <module>
    from .thermal_edge_trainer import SegmentationLightningModel as thermal_edge_trainer
  File "/home/hmohan/Programming/T-SegModels/FTNet/Codes/src/lightning_scripts/trainers/thermal_edge_trainer.py", line 9, in <module>
    from .base_trainer import BaseTrainer
  File "/home/hmohan/Programming/T-SegModels/FTNet/Codes/src/lightning_scripts/trainers/base_trainer.py", line 26, in <module>
    from core.utils.json_extension import save_to_json_pretty
  File "/home/hmohan/Programming/T-SegModels/FTNet/Codes/src/core/utils/__init__.py", line 4, in <module>
    from .download import *
ModuleNotFoundError: No module named 'core.utils.download'

Cuda Out of Memory Issue

Hello,
I am experiencing cuda out of memory issue when run 'train_and_test.bash'.

The card is Titan RTX with 24GB memory, however, the log said

RuntimeError: CUDA out of memory. Tried to allocate 7.05GiB (GPU 0; 23.65 GiB total capacity; 16.73 GiB already allocated; 5.36GiB free; 17.00 GiB reserved in total by PyTorch)

Is there anything I should change to run training ?

Inference on single image\folder

Hi,
thanks for the great work.
I want to test some of the pre-trained models on my own data.
is there some simple way to run a pre-trained model on a folder of images? or on a single image?
thanks

Finetuning | --pretrain-checkpoints not recognized

I'm trying to finetune the model as specified by the scripts provided but I encounter the following error:

usage: main.py [-h] [--mode {train,test,train_test}] [--train_only TRAIN_ONLY] [--model MODEL] [--backbone BACKBONE] [--pretrained-base PRETRAINED_BASE]
               [--dilation DILATION] [--dataset {cityscapes_thermal_combine,soda,mfn,scutseg}] [--dataset-path DATASET_PATH] [--base-size BASE_SIZE]
               [--crop-size CROP_SIZE] [--workers WORKERS] [--no-of-filters NO_OF_FILTERS] [--edge-extracts EDGE_EXTRACTS] [--num-blocks NUM_BLOCKS]
               [--train-batch-size TRAIN_BATCH_SIZE] [--val-batch-size VAL_BATCH_SIZE] [--test-batch-size TEST_BATCH_SIZE]
               [--accumulate-grad-batches ACCUMULATE_GRAD_BATCHES] [--test-monitor TEST_MONITOR] [--test-monitor-path TEST_MONITOR_PATH] [--wandb-id WANDB_ID]
               [--wandb-name-ext WANDB_NAME_EXT] [--epochs EPOCHS] [--loss-weight LOSS_WEIGHT] [--optimizer {SGD,ADAM,RMSprop,AdaBound}] [--lr LR]
               [--momentum MOMENTUM] [--nesterov NESTEROV] [--weight-decay WEIGHT_DECAY] [--beta1 BETA1] [--beta2 BETA2] [--epsilon EPSILON]
               [--scheduler-type {step,multistep_90_160,poly_warmstartup,multistep_warmstartup,onecycle}] [--warmup-iters WARMUP_ITERS]
               [--warmup-factor WARMUP_FACTOR] [--warmup-method WARMUP_METHOD] [--gamma GAMMA] [--resume RESUME] [--save-dir SAVE_DIR]
               [--test-checkpoint TEST_CHECKPOINT] [--save-images SAVE_IMAGES] [--save-images-as-subplots SAVE_IMAGES_AS_SUBPLOTS] [--debug DEBUG] [--seed SEED]
               [--num-nodes NUM_NODES] [--gpus GPUS] [--distributed-backend {dp,ddp,ddp2,horovod}]
main.py: error: unrecognized arguments: --pretrain-checkpoint ./../../../Training_Paper/Lightning/ftnet_resnext50_32x4d_128_3_1/cityscapes_thermal_combine//ckpt/last.ckpt

I'm not sure why main.py is unable to recognize the argument.

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.