GithubHelp home page GithubHelp logo

aksh-ai / neuralblack Goto Github PK

View Code? Open in Web Editor NEW
107.0 4.0 39.0 6.52 MB

A Multi-Class Brain Tumor Classifier using Convolutional Neural Network with 99% Accuracy achieved by applying the method of Transfer Learning using Python and Pytorch Deep Learning Framework

License: Other

Jupyter Notebook 94.34% Python 2.39% CSS 1.72% HTML 1.56%
brain-tumor-classification brain-tumor-detection brain-tumor braintumour brain-tumour brain cnn pytorch classification accuracy

neuralblack's Introduction

neuralBlack

Note: I have completely changed the POC for this project, and have not updated it over here since I'm publishing it as a paper.

neuralBlack is a complete brain tumor detection, classification, and diagnosis system with high accuracy (99.3%) that uses state of the art Deep Learning methods.

ResNet50 Neural Network Architecture

NN image

Dataset

We have used brain tumor dataset posted by Jun Cheng on figshare.com.

This brain tumor dataset containing 3064 T1-weighted contrast-inhanced images from 233 patients with three kinds of brain tumor: meningioma (708 slices), glioma (1426 slices), and pituitary tumor (930 slices).

Modules

  • brain_tumor_dataset_preparation.ipynb - An IPython notebook that contains preparation and preprocessing of dataset for training, validation and testing.

  • torch_brain_tumor_classifier.ipynb - An IPython notebook that contains all the steps, processes and results of training, validating and testing our brain tumor classifier.

  • test.py - A python script which accepts path to an image as input, which then classifies the image into one of the three classes.

  • deploy.py - A python script integrated with Flask server, that starts the Web Interface on local server where user can upload MRI image of brain and get classification results.

Note: We have included few images for testing under test_images directory.

Running the classifier

Download the classifier model '.pt' file from this drive link and place it under a folder named 'models' in the same directory where the files of this repository are present.

Before running the programs, kindly install the requirements as given in Requirements section of this README.

  • Use the test.py script for running the script in Terminal, Powershell or Command Prompt.

    • python test.py
  • Use deploy.py script to access the classifier as an interactive web interface.

    • python deploy.py

Screenshots (Results & Web Interface)

Web Interface

Home Page

index

Classification Results via Web Interface

class 1

class 2

class 3

Classifier Evaluation

Loss Graph

Loss Metrics

Accuracy Graph

Accuracy Metrics

Confusion Matrix on Test set

Confusion Matrix

Requirements

Python 3 is required.

Computational Specifications

Project done using Google Colab with follwing specifications:

  • Ubuntu 18.04 64-bit OS
  • 12 GB DDR4 RAM
  • 16 GB NVidia Tesla P100 GPU
  • 40 GB of Non-Persistent Storage

Library Requirements

We'll be using the following libraries to complete our classification problem:

  • Numpy - For linear algebra operations
  • Torch - Pytorch Deep Learning Framework
  • OS - To use Operating System methods
  • Random - To set random seed at specific places where random operations take place just so it happens the same way everytime it is executed
  • Pandas - To create DataFrame, CSV files, etc
  • Time - To perform date time operations
  • Seaborn - For sophisticated visualization
  • Pickle - To save and load binary files of our training data
  • Scikit-Learn - Machine learning framework. We have used this for evaluating our Classifier and for cross-validation split
  • Matplotlib - To visualize images, losses and accuracy
  • Google Colab Drive - To mount Google Drive so we can perform storage and loading operations using it (Only available on Google Colab)

The above mentioned libraries comes pre-installed and pre-configured with Google Colab.

Install the required libraries on your computer using the pip package manager.

For pip version 19.1 or above:

pip install -r requirements.txt --user

or

pip3 install -r requirements.txt --user

Pytorch

Follow the steps for installation given in the official website of Pytorch.

About

This project was done by Akshay Kumaar M. Paper is in progress. All the references papers have been included at the end of this repository's README.

References

Thanks to Vinoth Arjun for giving ideas for custom dataset class with different real-time augmentations.

License

Copyright 2020 Akshay Kumaar M

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Research Papers

Documentations

Future Scopes

  • Brain Tumor segmentation using GANs.
  • Brain Tumor detection using Object Detection for localization of tumor in a given MRI image of the brain.
  • Improve existing classification model and web interface

neuralblack's People

Contributors

aksh-ai 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

neuralblack's Issues

Port Error

HTTPConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000002BC8ED71F40>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

Is it possible to deply the model somewhere?

Hi there! I was following your project and it's really good. I was wondering if it's possible to deploy this model (.pt file) on Heroku or something so that I can make API calls to it and integrate this with an Android app

OSError: [Errno 22] Invalid argument

When I run the training loop, I get the following error:

_---------------------------------------------------------------------------
OSError Traceback (most recent call last)
in ()
20
21 # train in batches
---> 22 for b, (y, X) in enumerate(train_gen):
23 # set label as cuda if device is cuda
24 X, y = X.to(device), y.to(device)

~\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py in iter(self)
499
500 def iter(self):
--> 501 return _DataLoaderIter(self)
502
503 def len(self):

~\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py in init(self, loader)
287 for w in self.workers:
288 w.daemon = True # ensure that the worker exits on process exit
--> 289 w.start()
290
291 _update_worker_pids(id(self), tuple(w.pid for w in self.workers))

~\Anaconda3\lib\multiprocessing\process.py in start(self)
103 'daemonic processes are not allowed to have children'
104 _cleanup()
--> 105 self._popen = self._Popen(self)
106 self._sentinel = self._popen.sentinel
107 # Avoid a refcycle if the target function holds an indirect

~\Anaconda3\lib\multiprocessing\context.py in _Popen(process_obj)
221 @staticmethod
222 def _Popen(process_obj):
--> 223 return _default_context.get_context().Process._Popen(process_obj)
224
225 class DefaultContext(BaseContext):

~\Anaconda3\lib\multiprocessing\context.py in _Popen(process_obj)
320 def _Popen(process_obj):
321 from .popen_spawn_win32 import Popen
--> 322 return Popen(process_obj)
323
324 class SpawnContext(BaseContext):

~\Anaconda3\lib\multiprocessing\popen_spawn_win32.py in init(self, process_obj)
63 try:
64 reduction.dump(prep_data, to_child)
---> 65 reduction.dump(process_obj, to_child)
66 finally:
67 set_spawning_popen(None)

~\Anaconda3\lib\multiprocessing\reduction.py in dump(obj, file, protocol)
58 def dump(obj, file, protocol=None):
59 '''Replacement for pickle.dump() using ForkingPickler.'''
---> 60 ForkingPickler(file, protocol).dump(obj)
61
62 #

OSError: [Errno 22] Invalid argument

I assumed it could be because of the large size of the pickle file so I changed the loading command to the code in this link:https://www.programmersought.com/article/3832726678/

but yet I am still getting the same error..

Undefined Variables in dataset preparation code

Hey, in the code for preparing the brain tumor dataset, there are a few corrections that I noticed:

  • undefined Variable border: In the loop where you are iterating over the files, you are appending to border without defining it earlier.
  • Coordinate (coord) Undefined: It seems like you are trying to append coord to borders, but coord is not defined in the loop.

Error in the brain_tumor_dataset_preparation.ipynb


IndexError Traceback (most recent call last)
in ()
3 img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
4 img = cv2.resize(img, (512, 512))
----> 5 label = y[i-1]
6 training_data.append([img, label])
7

IndexError: list index out of range

Question consultion

Dear authors:

 Recently I have read your project.  And I have the question, is that do the project have the  paper or tutorial? And how could I download the dataset? is this web: https://figshare.com/articles/dataset/brain_tumor_dataset/1512427  all datasets?

Flask User Interface not redirecting to prediction layout

Hello, I'm a beginner in ML, I'm trying to execute your project for my study purpose and when I run the script deploy.py with powershell, the server execute and when I try to upload image and click on classify, it refreshes the page and is not showing the predicted layout.

This is what error says:
127.0.0.1 - - [05/Aug/2021 04:54:13] "POST /predict HTTP/1.1" 404 -
Exception

Expecting value: line 1 column 1 (char 0)

I thought there might be url problem as the class of predict.html is with def pred_page() so when I do change the url from:

with open(os.path.join(app.config['UPLOAD_FOLDER'], filename),'rb') as img:
predicted = requests.post("http://localhost:3000/predict", files={"file": img}).json()

to

with open(os.path.join(app.config['UPLOAD_FOLDER'], filename),'rb') as img:
predicted = requests.post("http://localhost:3000/pred_page", files={"file": img}).json()

it shows this error:
127.0.0.1 - - [05/Aug/2021 05:04:41] "POST /pred_page HTTP/1.1" 405 -
Exception

Expecting value: line 1 column 1 (char 0)

Can u help me out on this? There were some missing Import JSON line that I have added during debugging.

Thank You

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.