-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c5087e
commit 1ca3f29
Showing
10 changed files
with
2,301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Dependencies" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from shutil import copyfile" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Make Directories " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Seperate 40x, 100x, 200x, 400x images into seperate directories. \n", | ||
"# Each element of the below list is a path to the directory.\n", | ||
"directories = ['tf_files/breast_40', 'tf_files/breast_100', 'tf_files/breast_200', 'tf_files/breast_400']\n", | ||
"\n", | ||
"for directory in directories:\n", | ||
" # Make directory if it does not exist\n", | ||
" if not os.path.exists(directory):\n", | ||
" os.makedirs(directory)\n", | ||
"\n", | ||
" directory_b = directory+'/benign'\n", | ||
" directory_m = directory+'/malignant'\n", | ||
" # Make benign and malignant sub-directories for each directory if they do not exist\n", | ||
" if not os.path.exists(directory_b):\n", | ||
" os.makedirs(directory_b)\n", | ||
" if not os.path.exists(directory_m):\n", | ||
" os.makedirs(directory_m)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Copy Benign Files\n", | ||
"Change file paths to fit your setup" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"benign_types = os.listdir('/breast/benign/SOB')\n", | ||
"# Store the types. Example: 'adenosis', 'fibroadenoma', 'phyllodes_tumor', 'tubular_adenoma'.\n", | ||
"benign_types = [x for x in benign_types if x!= '.DS_Store']\n", | ||
"\n", | ||
"zooms = ['40', '100', '200', '400']\n", | ||
"\n", | ||
"# Copy files from benign to other folder\n", | ||
"for benign_type in benign_types:\n", | ||
" patients = os.listdir('/breast/benign/SOB/'+benign_type)\n", | ||
" patients = [x for x in patients if x!= '.DS_Store']\n", | ||
" \n", | ||
" for patient in patients:\n", | ||
" for zoom in zooms:\n", | ||
" images = os.listdir('/breast/benign/SOB/'+benign_type+'/'+patient+'/'+zoom+'X')\n", | ||
" images = [x for x in images if x!= '.DS_Store']\n", | ||
" for image in images:\n", | ||
" copyfile('/breast/benign/SOB/'+benign_type+'/'+patient+'/'+zoom+'X'+'/'+image, 'tf_files/breast_'+zoom+'/benign/'+image)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Copy Malignant Files" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"malignant_types = os.listdir('/breast/malignant/SOB')\n", | ||
"# Store the types. Example: 'ductal_carcinoma', 'lobular_carcinoma', 'mucinous_carcinoma', 'papillary_carcinoma'.\n", | ||
"malignant_types = [x for x in malignant_types if x!= '.DS_Store']\n", | ||
"\n", | ||
"zooms = ['40', '100', '200', '400']\n", | ||
"\n", | ||
"# Copy files from benign to other folder\n", | ||
"for malignant_type in malignant_types:\n", | ||
" patients = os.listdir('/breast/malignant/SOB/'+malignant_type)\n", | ||
" patients = [x for x in patients if x!= '.DS_Store']\n", | ||
" \n", | ||
" for patient in patients:\n", | ||
" for zoom in zooms:\n", | ||
" images = os.listdir('/breast/malignant/SOB/'+malignant_type+'/'+patient+'/'+zoom+'X')\n", | ||
" images = [x for x in images if x!= '.DS_Store']\n", | ||
" for image in images:\n", | ||
" copyfile('/breast/malignant/SOB/'+malignant_type+'/'+patient+'/'+zoom+'X'+'/'+image, 'tf_files/breast_'+zoom+'/malignant/'+image)\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Download Pre-Trained Version of Inception-v3 for Transfer Learning" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"! python classify.py" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Commands that can be used for retrain.py" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"! python retrain.py -h" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Train 9 classifiers for each magnification\n", | ||
"36 classifiers in total" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"zooms = [40, 100, 200, 400]\n", | ||
"test_percentages = [10, 20, 30, 40, 50, 60, 70, 80, 85]\n", | ||
"\n", | ||
"for zoom in zooms:\n", | ||
" for test_percentage in test_percentages:\n", | ||
" ! python retrain.py --summaries_dir=tf_files/{zoom}_{test_percentage} --output_graph=tf_files/breast{zoom}_graph_{test_percentage}.pb --output_labels=tf_files/breast{zoom}_labels_{test_percentage}.txt --testing_percentage={test_percentage} --image_dir=tf_files/breast_{zoom}\n", | ||
" \n", | ||
" \n", | ||
" " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Check training progress" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Replace tf_files/40_10 with the path to your summaries_sir\n", | ||
"! tensorboard --logdir tf_files/40_10" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.