Code Monkey home page Code Monkey logo

mahmudulalam / automatic-identification-and-counting-of-blood-cells Goto Github PK

View Code? Open in Web Editor NEW
119.0 6.0 52.0 10.35 MB

Machine learning approach of automatic identification and counting of blood cells (RBC, WBC, and Platelet) with KNN and IOU based verification.

Home Page: https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/htl.2018.5098

License: GNU General Public License v3.0

Python 91.19% Cython 8.81%
cbc blood-cells detection counting machine-learning automated-diagnosis cnn blood-cell-detection blood-cell-counting iou

automatic-identification-and-counting-of-blood-cells's Introduction

Automatic Identification and Counting of Blood Cells

GitHub stars GitHub forks GitHub issues Version GitHub license

Dataset

The Complete Blood Count (CBC) Dataset has been used for automatic identification and counting of blood cells. Download the dataset, unzip and put the Training, Testing, and Validationfolders in the working directory.

Requirements

requirements requirements

  • Tensorflow-GPU==2.2.0 (tested on 2.1.0, 2.2.0, and 2.3.0) conda install tensorflow-gpu
  • TF-slim==1.1.0 pip install tf-slim==1.1.0
  • Weights: download the trained weights file for blood cell detection and put the weights folder in the working directory.

Download Download

Getting Started

  1. Build the cython extension in place python setup.py build_ext --inplace
  2. Run detect.py python detect.py

Update

The darkflow.cython_utils.cy_yolo_findboxes problem has been fixed. Make sure to build the cython extension in place before running the code.

Paper

The code was originally written and developed with TensorFlow v1.x. The new updated version v2.0 included TensorFlow v2.x support, tested on both TensorFlow v2.1.0 and v2.2.0. You can download the previous version from here .

How to Run the Code 🏃

To detect the blood cells, simply run the detect.py file in the terminal or use an IDE. A step-by-step guideline of how to run the blood cell detection code in your computer is provided in this wiki . If you have any trouble running the code and facing any errors please feel free to create an issue or contact me.

How to Train on Your Dataset 🚄

A seven-step guideline of how to train on your own dataset is provided in this wiki .

Paper

Paper Paper

The code was developed for the following blood cell detection paper. For a more detailed explanation of the proposed method, please go through the pdf of the paper. If you use this code or associated dataset, please cite this paper as:

Machine learning approach of automatic identification and counting of blood cells

@article{alam2019machine,
  title={Machine learning approach of automatic identification and counting of blood cells},
  author={Alam, Mohammad Mahmudul and Islam, Mohammad Tariqul},
  journal={Healthcare Technology Letters},
  volume={6},
  number={4},
  pages={103--108},
  year={2019},
  publisher={IET}
}

Blood Cell Detection Output

KNN and IOU Based Verification

In some cases, our model predicts the same platelet twice. To solve this problem we propose a k-nearest neighbor (KNN) and intersection over union (IOU) based verification system where we find the nearest platelet of a selected platelet and calculate their overlap. We are allowing only a 10% overlap between two platelets. If the overlap is more than that then it will be a spurious prediction and we will ignore the prediction.

Before Verification After Verification

Prediction on High-Resolution Image (HRI)

We have used our model to detect and count blood cells from high-resolution blood cell smear images. These test images are of the size of 3872 x 2592 way higher than the size of our trained images of 640 x 480. So, to match the cell size of our trained images we divide those images into grid cells and run prediction in each grid cell and then combine all the prediction results.

Dividing Image into Grid/Patch

Combined Output

automatic-identification-and-counting-of-blood-cells's People

Contributors

mahmudulalam 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

automatic-identification-and-counting-of-blood-cells's Issues

traing

The loss during model training is 10-20, how to solve it? Can YOLOv7 or higher versions be used?

Loss becomes nan after 1k training steps

Hi, thank you for your great work!

I run this experiments according to the wiki step by step. I did not change any hyper-parameters except that I set gpu=0 to use a cpu for training. But I found that the loss became nan just after 1K steps training.

...
step 1655 - loss        nan - moving ave loss        nan
step 1656 - loss        nan - moving ave loss        nan
Finish 92 epoch(es)
step 1657 - loss        nan - moving ave loss        nan
step 1658 - loss        nan - moving ave loss        nan
...

Do you have any idea or have you ever observed this kind of strange thing? Thank you in advance for your help!

can you please help me in this

can you please help me in this

`Traceback (most recent call last):
File "C:/Users/jagan/Downloads/Automatic-Identification-and-Counting-of-Blood-Cells-master/Automatic-Identification-and-Counting-of-Blood-Cells-master/test.py", line 26, in
output = tfnet.return_predict(image)
File "C:\Users\jagan\Downloads\Automatic-Identification-and-Counting-of-Blood-Cells-master\Automatic-Identification-and-Counting-of-Blood-Cells-master\darkflow\net\flow.py", line 83, in return_predict
'Image is not a np.ndarray'

AssertionError: Image is not a np.ndarray
`

Originally posted by @Jagan3534 in #12 (comment)

facing error while importing the module

hi thanks for the work .
even i m using the cython version 0.29.2
File "", line 1, in
from ...utils.im_transform import imcv2_recolor, imcv2_affine_trans

ImportError: attempted relative import with no known parent package

Failed to run Blood Cell Detection.py

Thank for your source code.
When I try this github, follow the instruction in wiki, I meet following error. I hope you can help me.

(tf_gpu) D:\Download\Automatic-Identification-and-Counting-of-Blood-Cells\Automatic-Identification-and-Counting-of-Blood-Cells-master>python "Blood Cell Detection.py" Traceback (most recent call last): File "Blood Cell Detection.py", line 6, in <module> from darkflow.net.build import TFNet File "D:\Download\Automatic-Identification-and-Counting-of-Blood-Cells\Automatic-Identification-and-Counting-of-Blood-Cells-master\darkflow\net\build.py", line 7, in <module> from .framework import create_framework File "D:\Download\Automatic-Identification-and-Counting-of-Blood-Cells\Automatic-Identification-and-Counting-of-Blood-Cells-master\darkflow\net\framework.py", line 1, in <module> from . import yolo File "D:\Download\Automatic-Identification-and-Counting-of-Blood-Cells\Automatic-Identification-and-Counting-of-Blood-Cells-master\darkflow\net\yolo\__init__.py", line 2, in <module> from . import predict File "D:\Download\Automatic-Identification-and-Counting-of-Blood-Cells\Automatic-Identification-and-Counting-of-Blood-Cells-master\darkflow\net\yolo\predict.py", line 7, in <module> from ...cython_utils.cy_yolo_findboxes import yolo_box_constructor ModuleNotFoundError: No module named 'darkflow.cython_utils.cy_yolo_findboxes'

I downloaded weight, installed cython. I check the folder contain .cy_yolo_findboxes, it exits.
When i find it on google, i found this link thtrieu/darkflow#168. I did as abagshaw suggest, problem is still unsolved.

Does anyone know why? Any help is appreciated.
I use window 10, virtual enviroment of anaconda

Weights issue

Hi,

Thanks for the awesome work!

I am trying to replicate your work but run into some issues with your weights.

I have downloaded your weights but it comes in different formats. For darkflow, the weights file is .weights but I cannot find this file type from your weights.

(1)Do you have .weights file?

I tried renaming your file tiny-yolo-voc-3c-3750.meta and tiny-yolo-voc-3c-3750.data-00000-of-00001 at file size, 63mb and 189mb, to .weights file but the weight just does not match with your architecture, with the error message below when I run this command, using the original darkflow github repo

flow --model cfg/tiny-yolo-voc-3c.cfg --load bin/tiny-yolo-voc-3c.weights

Note: I copy your tiny-yolo-voc-3c.cfg and rename your file to tiny-yolo-voc-3c.weights to run the above command.

Error message:

AssertionError: expect 63082056 bytes, found 63676889

Training file missing

Hi, thanks for good work. I have curiosity on how you get the detection with tiny yolo3. which accuracy is lower than original yolo3 model. could you share your training file. thanks -

Regarding Model Evaluation

Is there any command to evaluate the model.
Specifically, I am looking for:

  1. Command to get the accuracy of the model.
  2. Command to count the number of cells in the test dataset and compare it with the ground truth
  3. Command to get the error values for testing dataset.

testing on high-resolution image

when you use the model on high-resolution image and divide image into 3x3grid, how to process the cells at the edge of the image.

Not able to run the project in mac os

Hello I am using mac

My Laptop configuration
MacOS Catalina
Version- 10.15.3 (19D76)
Processor - 1.8 GHz Dual-Core Intel Core i5
Graphics - Intel HD Graphics 6000 1536 MB

i tried run

python3 blood_cell_detection.py
i got following errors

Akshays-MacBook-Air-2:Automatic-Identification-and-Counting-of-Blood-Cells-master akshaydevkate$ python3 testing_dataset.py Traceback (most recent call last): File "testing_dataset.py", line 6, in <module> from darkflow.net.build import TFNet File "/Users/akshaydevkate/Downloads/Automatic-Identification-and-Counting-of-Blood-Cells-master/darkflow/net/build.py", line 1, in <module> import tensorflow as tf File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module> from tensorflow.python.tools import module_util as _module_util File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 84, in <module> from tensorflow.python import keras File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/__init__.py", line 27, in <module> from tensorflow.python.keras import models File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/models/__init__.py", line 21, in <module> from tensorflow.python.keras._impl.keras.models import load_model File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/_impl/keras/__init__.py", line 21, in <module> from tensorflow.python.keras._impl.keras import activations File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/_impl/keras/activations.py", line 23, in <module> from tensorflow.python.keras._impl.keras import backend as K File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/_impl/keras/backend.py", line 38, in <module> from tensorflow.python.layers import base as tf_base_layers File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/layers/base.py", line 25, in <module> from tensorflow.python.keras import backend File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/backend/__init__.py", line 22, in <module> from tensorflow.python.keras._impl.keras.backend import abs ImportError: cannot import name 'abs' from partially initialized module 'tensorflow.python.keras._impl.keras.backend' (most likely due to a circular import) (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/keras/_impl/keras/backend.py)

Will i be able to run the code in mac ? some where i tried to install tensorflow-gpu from terminal i got the following output

ERROR: Could not find a version that satisfies the requirement TensorFlow-GPU==1.11.0 ERROR: No matching distribution found for TensorFlow-GPU==1.11.0

After this i uploaded the files on drive and mounted to colab and after executing

!python3 blood_cell_detection.py
the above command

i got the following errors

2021-01-16 19:46:35.482977: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1 Traceback (most recent call last): File "blood_cell_detection.py", line 5, in <module> from darkflow.net.build import TFNet File "/content/darkflow/net/build.py", line 5, in <module> from .ops import op_create, identity File "/content/darkflow/net/ops/__init__.py", line 1, in <module> from .simple import * File "/content/darkflow/net/ops/simple.py", line 1, in <module> import tensorflow.contrib.slim as slim ModuleNotFoundError: No module named 'tensorflow.contrib'

Thanks in advance :)

Issue on running code

Hi,
Thanks for this wonderful project.
I am getting some issue while running python detect.py command. Below are the details and it's screenshot. It just gets stuck for lon time. Please refer the screenshots attached.
Screenshot from 2023-01-24 16-28-09
Screenshot from 2023-01-24 16-27-57

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.