{"id":19482602,"url":"https://github.com/axegon/tf2_malaria_cell_detection","last_synced_at":"2025-07-10T05:34:33.151Z","repository":{"id":172224184,"uuid":"177436139","full_name":"axegon/tf2_malaria_cell_detection","owner":"axegon","description":"Malaria cell detection with TensorFlow 2.0","archived":false,"fork":false,"pushed_at":"2024-06-17T22:44:24.000Z","size":1383,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-25T16:46:00.037Z","etag":null,"topics":["opencv","python3","tensorflow"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/axegon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-03-24T15:54:18.000Z","updated_at":"2020-06-03T15:35:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"de972bba-559e-453d-96db-85347d8199b1","html_url":"https://github.com/axegon/tf2_malaria_cell_detection","commit_stats":null,"previous_names":["axegon/tf2_malaria_cell_detection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/axegon/tf2_malaria_cell_detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axegon%2Ftf2_malaria_cell_detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axegon%2Ftf2_malaria_cell_detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axegon%2Ftf2_malaria_cell_detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axegon%2Ftf2_malaria_cell_detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axegon","download_url":"https://codeload.github.com/axegon/tf2_malaria_cell_detection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axegon%2Ftf2_malaria_cell_detection/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264535997,"owners_count":23624405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opencv","python3","tensorflow"],"created_at":"2024-11-10T20:11:23.544Z","updated_at":"2025-07-10T05:34:33.145Z","avatar_url":"https://github.com/axegon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Malaria cell detection with TensorFlow 2.0\n\n### Introduction\n\nA model originally written for a talk but as the meetup was delayed considerably, I'm open sourcing it.\n\nIn addition, the code was slightly modified to work with the new  Tensorflow 2.0.\n\nThe data-set is provided by the U.S National Library of Medicine. It consists of 27,558 images of individual\ncells, 13779 infected and 13779 uninfected cells. The provided images come in various sizes, ranging from\n90 x 90 pixels, all the way up to 320 x 240 pixels.\n\nSpecial thanks to [Dr. Julian Rayner](https://www.sanger.ac.uk/people/directory/rayner-julian), who kindly shed a lot of light on the subject and cleared many doubts.\n\nThere is plenty of variation in the images and after close examination, there are cells infections from early to late\nstages, where the cells become physically deformed.\n\n### Installation\n\nYou should have two command line tools installed:\n\n* wget\n* unzip\n\nI advise you to use a virtual environment. All the required packages can be found in requirements.txt or\nrequirements-gpu.txt. Alternatively you could use the setup.sh which should pick the right one for you.\n\n**IMPORTANT NOTES**\n\nTensorFlow 2.0 requires CUDA 10.0 and cuDNN 7.4.1. Installing those will break anything you have running with\nTensorFlow 1.x. Use at your own risk.\n\n**ONLY PYTHON 3.6+ IS SUPPORTED!**\n\nI've become a big fan of the f-string syntax and I would like to avoid maintaining code that needs additional work for\nit to run on older versions.\n\n### Running the model\n\nOnce you've trained(or downloaded the pre-trained model), you can run it with:\n\n```\n$ python run.py --model=/path/to/model.h5 \\\n        --image=/path/to/directory/of/images/or/single/image\n```\n\nUse the `--help` flag for more options.\n\nThe JSON model description must be in the same directory as the pre-trained weights and having the same name as the\nweights file with a json extension:\n\n```\npretrained\n├── model_2019-03-18T23:31:49.432520_0.9594166874885559_0.11796065587550401.h5\n└── model_2019-03-18T23:31:49.432520_0.9594166874885559_0.11796065587550401.json\n```\n\nUse the `--help` flag to see more options.\n\n### Model architecture\n\n![alt text](images/model_arch.png \"Model architecture\")\n\n```\nModel: \"sequential_1\"\n_________________________________________________________________\nLayer (type)                 Output Shape              Param #\n=================================================================\nconv2d_1 (Conv2D)            (None, 139, 139, 32)      896\n_________________________________________________________________\nmax_pooling2d_1 (MaxPooling2 (None, 69, 69, 32)        0\n_________________________________________________________________\nconv2d_2 (Conv2D)            (None, 67, 67, 64)        18496\n_________________________________________________________________\nconv2d_3 (Conv2D)            (None, 65, 65, 64)        36928\n_________________________________________________________________\nmax_pooling2d_2 (MaxPooling2 (None, 32, 32, 64)        0\n_________________________________________________________________\nconv2d_4 (Conv2D)            (None, 30, 30, 128)       73856\n_________________________________________________________________\nconv2d_5 (Conv2D)            (None, 28, 28, 128)       147584\n_________________________________________________________________\nconv2d_6 (Conv2D)            (None, 26, 26, 128)       147584\n_________________________________________________________________\nmax_pooling2d_3 (MaxPooling2 (None, 13, 13, 128)       0\n_________________________________________________________________\nflatten_1 (Flatten)          (None, 21632)             0\n_________________________________________________________________\ndropout_1 (Dropout)          (None, 21632)             0\n_________________________________________________________________\ndense_1 (Dense)              (None, 256)               5538048\n_________________________________________________________________\ndense_2 (Dense)              (None, 256)               65792\n_________________________________________________________________\ndense_3 (Dense)              (None, 1)                 257\n=================================================================\nTotal params: 6,029,441\nTrainable params: 6,029,441\nNon-trainable params: 0\n_________________________________________________________________\n```\n\nA stripped down and simplified version of VGG16 with some tweaks and changes: Namely, binary\ncross-entropy and Adam optimizer.\n\n### Training\n\nDownloading the data.\nThe data set is around just under 400MB compressed and can be downloaded through the shell script in the repository:\n\n```\n$ bash download.sh\n```\n\nIf you want to train the model on your own, I would advise using a CUDA-powered GPU. The training on a CPU would take\nseveral hours(6 to 8 give or take depending on your CPU). On a GPU (Gigabyte GeForce GTX 1080TI 11GB GDDR5X) the time\ngoes down to around 40 minutes.\n\nYou can tune the training parameters via the `config.yaml` file. **Before you start training, make sure you create the\ndirectory defined under `output_models`. The training script will not do that for you.**\n\n```\n$ python train.py --config=config.yaml\n```\n\n\n### Pre-trained model.\n\nThe pre-trained model can be downloaded from [here](https://www.dropbox.com/s/0bw5u7a0q2oh57s/pretrained_model.zip)\n**Training accuracy**\n![alt text](/images/epoch_acc.svg \"Training accuracy\")\n**Training loss**\n![alt text](/images/epoch_loss.svg \"Training loss\")\n\n**Sample resuls**\n\nRandom sample of uninfected cells, never used in the training:\n![uninfected](/images/Uninfected.png \"Uninfected\")\n\nRandom sample of parasitized cells, never used in the training:\n![parasitized](/images/Parasitized.png \"Parasitized\")\n\n**UPDATE**\n\nI got a message from a user (who shall remain anonymous due to request) who trained the same network on a completely different dataset: The [Chest X-Ray Pneumonia dataset](http://academictorrents.com/details/7208a86910cc518ae8feaa9021bf7f8565b97644) and got similar results (over 90% accuracy) with just 1000 images per class. His parameters were set as follows:\n\n```\nbatch_size: 60\nepochs: 35\nimage_size: [150, 150]\nlabels: [NORMAL, PNEUMONIA]\noutput_models: models/\nplot_training_data: true\nrandom_state: 42\ntest_size: 0.3\ntrain_images: chest_xray/train/\ntrain_size: 1000\nvalidation_steps: 15\nsteps_per_epoch: 60\n```\n\nThe models he trained are available [here](https://www.dropbox.com/s/2e2au2osagkiu4t/pneumonia.zip).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxegon%2Ftf2_malaria_cell_detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxegon%2Ftf2_malaria_cell_detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxegon%2Ftf2_malaria_cell_detection/lists"}