Git Product home page Git Product logo

respirenet's Introduction

RespireNet 2020

This is the official implementation of the work RespireNet.

Dependencies:

* Python3
* Pytorch (torch, torchvision and other dependencies for Pytorch)
* Numpy
* Librosa (0.8.0)
* nlpaug (0.0.14)
* OpenCV (4.2.0)
* Pandas (0.22.0)
* scikit-learn (0.23.1)
* tqdm (4.48.0)
* cudnn (CUDA for training on GPU)

These are all easily installable via, e.g., pip install numpy. Any reasonably recent version of these packages shold work. It is recommended to use a python virtual environment to setup the dependencies and the code.

Dataset

Train and Test Script

  • We follow both the official 60-40 train-test split as well as the 80-20 split.
  • For training we employ a 2-stage training protocol.
  • Stage 1: The model is trained end-to-end on train data from all the 4 devices.
  • Stage 2: The model is fine-tuned (with a lower learning rate 1e-4) on only the data from a single device. We do this separately for each device (device specific fine-tuning).

Train Command:

Stage 1

python train.py --data_dir ../data/icbhi_dataset/audio_text_data/ --folds_file ../data/patient_list_foldwise.txt --model_path models_out --lr 1e-3 --batch_size 64 --num_worker 4 --start_epochs 0 --epochs 200 --test_fold 4

Stage 2 (Device specific fine-tuning)

python train.py --data_dir ../data/icbhi_dataset/audio_text_data/ --folds_file ../data/patient_list_foldwise.txt --model_path models_out --lr 1e-4 --batch_size 64 --num_worker 4 --start_epochs 0 --epochs 50 --test_fold 4 --checkpoint models/ckpt_best.pkl --stetho_id 0

replace the stetho_id as 0 or 1 or 2 or 3 for devices 0-3

Please go through our paper for more details.

Test Command:

Evaluation script

python eval.py --data_dir ../data/icbhi_dataset/audio_text_data/ --folds_file ../data/patient_list_foldwise.txt --batch_size 64 --num_worker 4 --test_fold 4 --checkpoint models/ckpt_best.pkl

RespireNet Overview

Quantitative Results

Performance of the proposed model

Split & Task Method Sp Se Score
60-40 split & 4-class CNN 71.4% 39.0% 55.2%
CNN+CBA+BRC 71.8% 39.6% 55.7%
CNN+CBA+BRC+FT 72.3% 40.1% 56.2%
80/20 split & 4-class CNN 78.8% 53.6% 66.2%
CNN+CBA+BRC 79.7% 54.4% 67.1%
CNN+CBA+BRC+FT 83.3% 53.7% 68.5%
80/20 split & 2-class CNN 83.3% 60.5% 71.9%
CNN+CBA+BRC 76.4% 71.0% 73.7%
CNN+CBA+BRC+FT 80.9% 73.1% 77.0%
Performance comparison of the proposed model with the state-of-the-art systems following random splits. We see significant improvements from our proposed techniques: concatenation-based augmentation (CBA), blank region clipping (BRC) and device specific fine-tuning (FT).

Effect of time window

Length 1 sec 2 sec 3 sec 4 sec 5 sec 6 sec 7 sec 8 sec 9 sec
Scores 56.6% 59.0% 60.3% 61.1% 62.3% 64.4% 66.2% 65.1% 65.5%

Some additional results

Method Sp Se Score
CNN + Mixup 73.9% 48.9% 61.4%
CNN + VGGish* 76.0% 42.2% 59.1%
Hybrid CNN + Transformer 75.3% 49.9% 63.2%
We also tried experiments with Mixup augmentations, using pre-trained VGGish features and a novel Hybrid CNN + Transformer architecture, however they did not prove to be very useful. 
However transformers with appropriate pretraining have found to be useful in many applications (especially NLP tasks) and may prove to be useful in the future.

VGGish link

About the code

  • train.py: Main trainer code.
  • image_dataloader.py: Dataloader module.
  • utils.py: Contains a lot of utility functions for audio file loading, feature extraction, augmentations, etc.
  • eval.py: Evaluation source files for trained model.
  • scripts: Directory which contains the runner scripts.
  • nets: Contains the different network modules.
  • data: Training-Testing split and should contain the ICBHI data.
  • models: Contains the trained checkpoint for our proposed framework.

Blank Region Clipping Scheme

Concatenation Based Augmentation

To cite this work:

@misc{gairola2020respirenet,
      title={RespireNet: A Deep Neural Network for Accurately Detecting Abnormal Lung Sounds in Limited Data Setting}, 
      author={Siddhartha Gairola and Francis Tom and Nipun Kwatra and Mohit Jain},
      year={2020},
      eprint={2011.00196},
      archivePrefix={arXiv},
      primaryClass={cs.SD}
}

respirenet's People

Contributors

microsoftopensource avatar sidgairo18 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

Watchers

 avatar  avatar  avatar  avatar  avatar

respirenet's Issues

TypeError: 'float' object cannot be interpreted as an integer

Hello , @sidgairo18 :

Very appreciate your works for controbuting the AI Medical.

I have a little question about the input arguments  

parser.add_argument('--aug_scale', default=None, type=float, help='Augmentation multiplier') the aug_scale type was set to float,
However when I add the --aug_scale 1 in the command,
i got the following problems:

Traceback (most recent call last): 
File "/home/RespireNet_lab/train.py", line 316, in <module> trainer = Trainer() 
File "/home/RespireNet_lab/train.py", line 124, in __init__ True, 
"params_json", self.input_transform, stetho_id=self.args.stetho_id, aug_scale=self.args.aug_scale) 

File "/home/RespireNet_lab/image_dataloader.py", line 95, in __init__ 
self.new_augment(scale=aug_scale) 
File "/home/RespireNet_lab/image_dataloader.py", line 130, 
in new_augment for idx in range(aug_nos):

TypeError: 'float' object cannot be interpreted as an integer

and  If I set   the  type to int : parser.add_argument('--aug_scale', default=None, type=int, help='Augmentation multiplier')

it will appear the  following  problems:

get individual cycles from each audio file:: 100%|██████████| 722/722 [11:40<00:00,  1.03it/s]
Traceback (most recent call last):  
File "/home/RespireNet_lab/train.py", line 316, in <module>    trainer = Trainer()  
File "/home/RespireNet_lab/train.py", line 124, in __init__    
True, "params_json", self.input_transform, stetho_id=self.args.stetho_id, aug_scale=self.args.aug_scale) 

 File "/home/RespireNet_lab/image_dataloader.py", line 111, in __init__    
  self.device_wise[self.file_to_device[sample[2]]].append(sample)

KeyError: '203_1p2_Ar_mc_AKGC417L-203_1p4_Ar_mc_AKGC417L'

could you tell us how to start up this data aug function? 
thanks in advance.

check out the acc, and Score

Hello, author:
I think you let acc = Score, in your valid stage code, you let :

  `acc = accuracy_score(y_true, y_pred)`

however, the official scocre defination : score = (sp + se)/2 which you use it in the training stage but in the valid stage you use acc instead.

Can you check it out, thanks a lot.

Data format error

Hi, I ran your code and it reported an error as follows

Original Traceback (most recent call last):
File "/home/sata/zsb/miniconda/lib/python3.9/site-packages/torch/utils/data/_u tils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/home/sata/zsb/miniconda/lib/python3.9/site-packages/torch/utils/data/_u tils/fetch.py", line 49, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/sata/zsb/miniconda/lib/python3.9/site-packages/torch/utils/data/_u tils/fetch.py", line 49, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/zsb/LHT2/Feiyin/image_dataloader.py", line 248, in getitem
audio = split_and_pad([audio, 0,0,0,0], self.desired_length, self.sample_rat e, types=1)[0][0]
File "/home/zsb/LHT2/Feiyin/utils.py", line 120, in split_and_pad
padded = generate_padded_samples(soundclip, soundclip, output_buffer_length, sample_rate, types); pad_times = (output_buffer_length-len(soundclip))/len(soun dclip)
File "/home/zsb/LHT2/Feiyin/utils.py", line 176, in generate_padded_samples
copy[:src_length] = source[:]
ValueError: setting an array element with a sequence. The requested array would exceed the maximum number of dimension of 1.

I really want to know why this error emerges, thank u!

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.