Online Onychomycosis Model - RESTful API
Offline Onychomycosis Model - BVLC caffemodel
- Internet access
1) Install Python 2.7
Download Anaconda2 64bit 2.7 (https://www.continuum.io/downloads#windows) and install.
Set installation path to "c:\anaconda2" or "c:\python27"
Be sure to check "Add anaconda to my PATH environment variable" during installation
2) Download api.zip and extract api.zip
3) Resolve dependencies (requests and matplotlib)
c:\api\> pip install --upgrade pip
c:\api\> pip install requests matplotlib
or
c:\api\> setup.bat
4) Run Python scripts (api.py, roc.py)
c:\api\> python api.py
c:\api\> python roc.py
# ResNet-152 alone ( ~$ python roc.py 1 )

# ResNet-152 + VGG-19; arithmetic mean ( ~$ python roc.py 0 ; ~$ python roc.py )

# ResNet-152 + VGG-19; feedforward neural networks ( ~$ python roc.py 2 )

- BVLC PyCaffe
1. Download the zip file. It contains,
1) Model Onychomycosis; Models trained with A1, A2, and E dataset + the feedforward neural networks model
2) Python example and batch files that generate ROC curves
3) Prebuilt 64bit windows pycaffe - "caffe" folder
2. Install BVLC PyCaffe
Tutorial : Install PyCaffe
3. Run examples
Fig3C-A1-ensemble.bat
Fig3C-A1-ResNet.bat
...
...
...
Fig4C-A2-ResNet.bat
Fig4C-E-ResNet.bat
Offline Onychomycosis Model - BVLC caffemodel
Online Onychomycosis Model - RESTful API
Requirements
- Python (version 2.x is better than 3.x)- Internet access
Download
- api.zip
How to use
1) Install Python 2.7
Download Anaconda2 64bit 2.7 (https://www.continuum.io/downloads#windows) and install.
Set installation path to "c:\anaconda2" or "c:\python27"
Be sure to check "Add anaconda to my PATH environment variable" during installation
2) Download api.zip and extract api.zip
3) Resolve dependencies (requests and matplotlib)
c:\api\> pip install --upgrade pip
c:\api\> pip install requests matplotlib
or
c:\api\> setup.bat
4) Run Python scripts (api.py, roc.py)
c:\api\> python api.py
c:\api\> python roc.py
# Source code - api.py
### ### Nail model API ### Han Seung Seog (whria78@gmail.com) / http://whria.net / http://medicalphoto.org ### 2017-3-5 ### import requests import pickle import os import sys # for python2 python3 compatibility try: import urllib.parse as myurl except ImportError: import urllib as myurl from io import BytesIO # for unicode support def custom_filename(x):return myurl.quote(x) def modelnail(url,username,image_path): url=url+'/api' data_={'user':username} file_={'file':(custom_filename(os.path.basename(image_path)),open(image_path,'rb').read())} res=requests.post(url,data=data_,files=file_) f=BytesIO(res.content) # for python2 python3 compatibility if sys.version_info[0] >= 3: result=pickle.load(f,encoding='bytes') else: result=pickle.load(f) return result def get_deploy(url): url=url+'/deploy' res=requests.get(url) f=BytesIO(res.content) result=pickle.load(f) return result ### main server ### server_url='http://nail.medicalphoto.org:8001' ### backup server ### #server_url='http://backup.medicalphoto.org:8001' username='HAN' ### Get list of indexes ### list_deploy=get_deploy(server_url) ### Run Model ### test_filename='test.jpg' if len(sys.argv)>1: test_filename=str(sys.argv[1]) if (os.path.exists(test_filename)==False): print (test_filename+' is not exist') sys.exit(0) result=modelnail(server_url,username,test_filename) success=result[0] model_result=result[1] if (success!=True): print (model_result) sys.exit(0) for k in range(0,len(list_deploy)): print ("\n") print ("## Model %d ##" % (k+1)) for i,deploy_ in enumerate(list_deploy[k]): print ("%s : %.4f" % (list_deploy[k][i],model_result[k][i]))
Example 1 - test.jpg

~$ python api.py or ~$ python3 api.py ## Model 1 ## (ResNet-152) onychomycosis : 0.0029 normalnail : 0.0016 naildystrophy : 0.9858 melanonychia : 0.0001 onycholysis : 0.0033 others : 0.0063 ## Model 2 ## (VGG-19) onychomycosis : 0.2237 normalnail : 0.0021 naildystrophy : 0.7443 melanonychia : 0.0004 onycholysis : 0.0228 others : 0.0067 ## Model 3 ## (Fine Image Selector) nail : 0.9871 (adequate value of fine image selector) focus : 0.0126 dumy : 0.0003 skinphoto : 0.0000 index : 0.0000 imagenet : 0.0000 ## Model 4 ## (ResNet-152 + VGG-19 + Feedforward network) onychomycosis : 0.1039 non_onychomycosis : 0.8961
Example 2 - Draw 1) ROC curve (test dataset = B1+C; training dataset = A1) 2) Threshold / Sensitivity / Specificity graph
We created ROC curves, using MatPlotLib (https://matplotlib.org). It will takes about 15 minutes to complete the tasks depending on network bandwidths.# ResNet-152 alone ( ~$ python roc.py 1 )


# ResNet-152 + VGG-19; arithmetic mean ( ~$ python roc.py 0 ; ~$ python roc.py )


# ResNet-152 + VGG-19; feedforward neural networks ( ~$ python roc.py 2 )


~$ python roc.py or ~$ python3 roc.py DX LIST : ... /home/ai/edrive/http/medicalphoto/nail/B1C dataset/C/onychomycosis/C_OM (51).JPG /home/ai/edrive/http/medicalphoto/nail/B1C dataset/C/onychomycosis/C_OM (31).JPG /home/ai/edrive/http/medicalphoto/nail/B1C dataset/C/onychomycosis/C_OM (32).JPG AUC : 94.86, MAX J score : 78.62 MAX sen / spe : 88.79 / 89.83 Threshold : 0.3263
Offline Onychomycosis Model - BVLC caffemodel
Requirements
- Python- BVLC PyCaffe
Download
- Figshare.com (3.7 Gigabytes)
How to use
1. Download the zip file. It contains,
1) Model Onychomycosis; Models trained with A1, A2, and E dataset + the feedforward neural networks model
2) Python example and batch files that generate ROC curves
3) Prebuilt 64bit windows pycaffe - "caffe" folder
2. Install BVLC PyCaffe
Tutorial : Install PyCaffe
3. Run examples
Fig3C-A1-ensemble.bat
Fig3C-A1-ResNet.bat
...
...
...
Fig4C-A2-ResNet.bat
Fig4C-E-ResNet.bat