Git Product home page Git Product logo

mrnet's Introduction

MIT contributions welcome Twitter Stars

Deep learning in medical imaging: How to automate the detection of knee injuries in MRI exams ?

This repository contains an implementation of a convolutional neural network that classifies specific knee injuries from MRI exams.

It also contains the matieral of a series of posts I wrote on my blog.

Dataset: MRNet

The data comes from Stanford ML Group research lab. It consits of 1,370 knee MRI exams performed at Stanford University Medical Center to study the presence of Anterior Cruciate Ligament (ACL) tears.

For more information about the ACL tear problem and the MRNet data please refer to my blog post where you can investigate the data and build the following data visualization in jupyter notebook:

To learn more about the data and how to realize this visualization widget, read my first post.

Code structure:

This charts summarizes the architecture of the project:

For more details about the code, please refer to my second blog post .

How to use the code:

If you want to retrain the network on your own you have to ask for the data from Stanford via this link.

Once you download the data, create a data folder and place it at the root of the project. You should have two folders inside: train and valid as well as a bunch of csv files.

To run the script you can execute it with the following arguments:

parser = argparse.ArgumentParser()
parser.add_argument('-t', '--task', type=str, required=True,
                    choices=['abnormal', 'acl', 'meniscus'])
parser.add_argument('-p', '--plane', type=str, required=True,
                    choices=['sagittal', 'coronal', 'axial'])
parser.add_argument('--augment', type=int, choices=[0, 1], default=1)
parser.add_argument('--lr_scheduler', type=int, choices=[0, 1], default=1)
parser.add_argument('--epochs', type=int, default=50)
parser.add_argument('--lr', type=float, default=1e-5)
parser.add_argument('--flush_history', type=int, choices=[0, 1], default=0)
parser.add_argument('--save_model', type=int, choices=[0, 1], default=1)
parser.add_argument('--patience', type=int, choices=[0, 1], default=5)

example to train a model to detect acl tears on the sagittal plane for a 20 epochs:

python -t acl -p sagittal --epochs=20

Note: Before running the script, add the following (empty) folders at the root of the project:

  • models
  • logs

Results:

I trained an ACL tear classifier on a sagittal plane and got the following AUC scores:

  • on train: 0.8669
  • on validation: 0.8850

Logs on Tensorboard:

Contributions - PR are welcome:

If you feel that some functionalities or improvements could be added to the project, don't hesitate to submit a pull request.

mrnet's People

Contributors

ahmedbesbes 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  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

mrnet's Issues

part 3: Interpret models' predictions

Hi, thank you for your wonderful work. I'm trying the third part: Interpret Models' Predictions. I find I can't visualize some of the predictions. As follows:

IndexError Traceback (most recent call last)
in
1 import shutil
----> 2 create_patiens_cam(acl[0],plane)

in create_patiens_cam(case, plane)
19 logit = mrnet(mri)
20 size_upsample = (256, 256)
---> 21 feature_conv = feature_blobs[0]
22 # print(features_blobs[0])
23

IndexError: list index out of range

and then I did this:
mrnet = torch.load(f'../models/{model_name}')
mrnet = mrnet.to(device)
mrnet.eval()

hook the feature extractor

features_blobs = []
def hook_feature(module, input, output):
features_blobs.append(output.data.cpu().numpy())
mrnet._modules.get('pooling_layer').register_forward_hook(hook_feature);

...

global features_blobs
mri = mri.to(device)
logit = mrnet(mri)
size_upsample = (256, 256)
feature_conv = features_blobs[0]
h_x = F.softmax(logit, dim=1).data.squeeze(0)
probs, idx = h_x.sort(0, True)
probs = probs.cpu().numpy()
idx = idx.cpu().numpy()
slice_cams = returnCAM(features_blobs[-1], weight_softmax, idx[:1])

...

import shutil
create_patiens_cam(acl[0],plane)

Could you tell me what went wrong? thank you

0

Seems that "Softmax" should be used instead of "Sigmoid"?

Hello, thanks for your implementation. However, I found that the "probs" for binary classification doesn't sum up to be 1.0.


        prediction = model.forward(image.float())
        loss = torch.nn.BCEWithLogitsLoss(weight=weight)(prediction, label)
        loss.backward()
        optimizer.step()

        loss_value = loss.item()
        losses.append(loss_value)

        probas = torch.sigmoid(prediction)

        y_trues.append(int(label[0][1]))
        y_preds.append(probas[0][1].item())

The issue mentioned is located in "https://github.com/ahmedbesbes/mrnet/blob/master/train.py"

I can not reproduce your train AUC, & valid AUC scores

Dear Besbes,
Firstly, I thank for your sharing code. It is very nice. I test with sagittal dataset with anterior cruciate ligament tear. However, I could not reproduce your results like train & valid AUC scores. So could you explain to clarify the issue? Or maybe I acquire a mistake somewhere?
Best regard. Linh

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.