Coder Social home page Coder Social logo

iliasprc / covidnet Goto Github PK

View Code? Open in Web Editor NEW
79.0 6.0 19.0 50.1 MB

PyTorch implementation of COVID-Net https://github.com/lindawangg/COVID-Net

License: GNU General Public License v3.0

Python 44.52% Jupyter Notebook 55.48%
python3 pytorch pytorch-implementation covid-19 xray

covidnet's Introduction

COVIDNet

Contributors Forks Stargazers Issues Open In Colab My PyTorch implementation of COVID-Net, for the original work please see: https://github.com/lindawangg/COVID-Net

The purpose of this github is to reproduce results and not to claim state-of-the-art performance !!

Also Google Colab Notebook for plug-n-play training and evaluation here [Open In Colab

Table of Contents

Getting Started

TODOs

  • Final Requirements
  • Pretrained models
  • Test all pretrained models
  • Instructions for training
  • Adding command line option for inference

Requirements

Installation & Data Preparation

Please refer to

 pip install -r requirements.txt
  • Python >= 3.6 (3.6 recommended)
  • PyTorch >= 1.4 (1.6.0 recommended)
  • torchvision >=0.6.0
  • tqdm (Optional for test.py)
  • tensorboard >= 1.14

Usage

Training

The network takes as input an image of shape (N, 224, 224, 3) and outputs the softmax probabilities as (N, C), where N is the number of batches and C number of output classes.

  1. To train the Network from scratch simply do python main.py Arguments for training
trainer:
  cwd: /home/ # working directory
  logger: CovidCLF # logger name
  epochs: 30 # number of training epochs
  seed: 123 # randomness seed
  cuda: True # use nvidia gpu
  gpu: 0,1 # id of gpu
  save: True # save checkpoint
  load: False # load pretrained checkpoint
  gradient_accumulation: 1 # gradient accumulation steps
  pretrained_cpkt: cpkt.pt
  log_interval: 1000 # print statistics every log_interval
  model:
    name: mobilenet_v2 # model name  [mobilenet_v2,COVIDNet_small]
    optimizer: # optimizer configuration
      type: SGD # optimizer type
      lr: 1e-2 # learning rate
      weight_decay: 0.000001 # weight decay
    scheduler: # learning rate scheduler
      type: ReduceLRonPlateau # type of scheduler
      scheduler_factor: 0.5 # learning rate change ratio
      scheduler_patience: 0 # patience for some epochs
      scheduler_min_lr: 1e-3 # minimum learning rate value
      scheduler_verbose: 5e-6 # print if learning rate is changed
  dataloader:
    train:
      batch_size: 4 # batch size
      shuffle: True # shuffle samples after every epoch
      num_workers: 2 # number of thread for dataloader1
    val:
      batch_size: 2
      shuffle: False
      num_workers: 2
    test:
      batch_size: 1
      shuffle: False
      num_workers: 2
  dataset:
    input_data: ./data/data
    name: COVIDx # dataset name COVIDx or COVID_CT
    modality: RGB # type of modality
    dim: [224,224] # image dimension
    train:
      augmentation: True # do augmentation to video
    val:
      augmentation: False
    test:
      augmentation: False

Results

with my implementation of COVID-Net and comparison with CNNs pretrained on ImageNet dataset

Results in COVIDx dataset

Model Accuracy (%) # Params (M) MACs (G)
[COVID-Net-Small] 89.10 115.42
COVID-Net-Large 91.22 118.19 3.54
Mobilenet V2 94.0 - -
ResNeXt50-32x4d 95.0 - -
ResNet-18 94.0 - -

Results in COVID-CT dataset

Model Accuracy (%) # Params (M) MACs (G)
[COVID-Net-Small] - -
[COVID-Net-Large] - -

Confusion Matrix on both datasets coming soon !!

Datasets

1) COVID-CT-Dataset

The COVID-CT-Dataset has 288 CT images containing clinical findings of COVID-19. We are continuously adding more COVID CTs.

The images are collected from medRxiv and bioRxiv papers about COVID-19. CTs containing COVID-19 abnormalities are selected by reading the figure captions in the papers. All copyrights of the data belong to medRxiv and bioRxiv.

Please refer to the preprint for details: COVID-CT-Dataset: A CT Scan Dataset about COVID-19

2) COVIDx dataset

The current COVIDx dataset is constructed by the following open source chest radiography datasets:

We especially thank the Radiological Society of North America and others involved in the RSNA Pneumonia Detection Challenge, and Dr. Joseph Paul Cohen and the team at MILA involved in the COVID-19 image data collection project, for making data available to the global community.

Steps to generate the COVIDx dataset

Download the datasets listed above

  • git clone https://github.com/ieee8023/covid-chestxray-dataset.git
  • go to this link to download the RSNA pneumonia dataset
  1. Create a data directory and within the data directory, create a train and test directory
  2. Use COVIDNet.ipynb to combine the two dataset to create COVIDx. Make sure to remember to change the file paths.
  3. We provide the train and test txt files with patientId, image path and label (normal, pneumonia or COVID-19). The description for each file is explained below:

Links

Check out this repository for more medical applications with deep-learning in PyTorch https://github.com/black0017/MedicalZooPytorch from https://github.com/black0017

covidnet's People

Contributors

glennmatlin avatar iliasprc avatar lazyshuu avatar tbnv999 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

covidnet's Issues

Index Error

Please if you can help me. When I tried to run this code using COVID_CT dataset I got this error:
File "main_edge.py", line 34, in main
val_metrics, confusion_matrix = validation(args, model, val_generator, epoch, writer)
File "/content/drive/.shortcut-targets-by-id/104/COVIDNet/trainer/train.py", line 118, in validation
confusion_matrix[t.long(), p.long()] += 1
IndexError: index 968 is out of bounds for dimension 1 with size 2

How can I handle it?!
Thanks

Pretrained weights

Hi, great work! In the paper, the authors say that they pre-trained the model on ImageNet. Were you able to do that? I see that you report an accuracy >90% on the notebook. Did you achieve that without ImageNet pre-training?

Incorrect links to models

Would you please provide updated links to the models on your Google Drive? It looks you moved the models' weights to another directory across your cloud. The link to COVID-Net-Large is not working and Google Drive throws a 404 error.

image

Training-Testing text files don't exist

The txt files required to for training/testin : /train_split_v2.txt', './test_split_v2.txt' don't exist, same for train_COVIDx.txt, test_COVIDx.txt described in readme. Could you please upload those files?

Attribute Error While Running

Thanks for your effort. When I tried to run the code I got the following error, How can I handle it?

Traceback (most recent call last):
File "main.py", line 72, in
main()
File "main.py", line 36, in main
best_pred_loss = util.save_model(model, optimizer, args, val_metrics, epoch, best_pred_loss, confusion_matrix)
File "/content/drive/My Drive/COVIDNet/utils/util.py", line 61, in save_model
loss = metrics.data['loss']
AttributeError: 'MetricTracker' object has no attribute 'data'

Attribute Error While Running

Thanks for your effort. When I tried to run the code I got the following error, How can I handle it?

Traceback (most recent call last):
File "main.py", line 72, in
main()
File "main.py", line 21, in main
model, optimizer, training_generator, val_generator, test_generator = initialize(args)
File "/home/lsz/Documents/study/COVID/COVIDNet-master/trainer/train.py", line 33, in initialize
train_loader = COVIDxDataset(mode='train', n_classes=args.classes, dataset_path=args.data,
AttributeError: 'Namespace' object has no attribute 'data'

Issues on dataset preparation

Hi,
Thanks for the work!
I am trying to generate the dataset using the code in COVIDNet.ipynb:

  1. git clone https://github.com/IliasPap/COVID-Net.git seems not exist, so I modified that to git clone https://github.com/IliasPap/COVIDNet.git . Is that correct?
  2. I cannot find the .npy file in the line '/content/COVID-Net/rsna_test_patients_{}.npy'.format(key)

Could you please help with this?
Many thanks!

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.