-
Notifications
You must be signed in to change notification settings - Fork 130
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
Showing
1 changed file
with
306 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,306 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Populating the interactive namespace from numpy and matplotlib\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Using TensorFlow backend.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%pylab inline\n", | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"import keras" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Resnet & VGG16" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from keras.models import load_model\n", | ||
"res_mod = load_model('1152x896_s10_prt_addtopf2_1.h5', compile=False)\n", | ||
"vgg_mod = load_model('1152x896_s10_prt_addvgg20.h5', compile=False)\n", | ||
"hybrid_mod = load_model('1152x896_s10_prt_addvgg53.h5', compile=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Found 376 images belonging to 2 classes.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from dm_image import DMImageDataGenerator\n", | ||
"test_imgen = DMImageDataGenerator(featurewise_center=True)\n", | ||
"test_imgen.mean = 52.18\n", | ||
"test_generator = test_imgen.flow_from_directory(\n", | ||
" './full_test_1152x896', target_size=(1152, 896), target_scale=None,\n", | ||
" rescale_factor=0.003891,\n", | ||
" equalize_hist=False, dup_3_channels=True, \n", | ||
" classes=['neg', 'pos'], class_mode='categorical', batch_size=4, \n", | ||
" shuffle=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[ 0.86367945 0.86367945]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from dm_keras_ext import DMAucModelCheckpoint\n", | ||
"res_auc, res_y_true, res_y_pred = DMAucModelCheckpoint.calc_test_auc(\n", | ||
" test_generator, res_mod, test_samples=test_generator.nb_sample, return_y_res=True)\n", | ||
"print res_auc" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[ 0.82536263 0.82536263]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from dm_keras_ext import DMAucModelCheckpoint\n", | ||
"vgg_auc, vgg_y_true, vgg_y_pred = DMAucModelCheckpoint.calc_test_auc(\n", | ||
" test_generator, vgg_mod, test_samples=test_generator.nb_sample, return_y_res=True)\n", | ||
"print vgg_auc" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[ 0.84914548 0.84914548]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from dm_keras_ext import DMAucModelCheckpoint\n", | ||
"hybrid_auc, hybrid_y_true, hybrid_y_pred = DMAucModelCheckpoint.calc_test_auc(\n", | ||
" test_generator, hybrid_mod, test_samples=test_generator.nb_sample, return_y_res=True)\n", | ||
"print hybrid_auc" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"True\n", | ||
"True\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print np.array_equal(res_y_true, vgg_y_true)\n", | ||
"print np.array_equal(res_y_true, hybrid_y_true)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0.88507827086\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from sklearn.metrics import roc_auc_score\n", | ||
"all_mod_y_pred_avg = (res_y_pred[:,1] + vgg_y_pred[:,1] + hybrid_y_pred[:,1])/3\n", | ||
"print roc_auc_score(res_y_true[:,1], all_mod_y_pred_avg)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[ 0.87832831 0.87832831]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from dm_keras_ext import DMAucModelCheckpoint\n", | ||
"res_auc_aug, res_y_true_aug, res_y_pred_aug = DMAucModelCheckpoint.calc_test_auc(\n", | ||
" test_generator, res_mod, test_samples=test_generator.nb_sample, return_y_res=True, test_augment=True)\n", | ||
"print res_auc_aug" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[ 0.85919862 0.85919862]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from dm_keras_ext import DMAucModelCheckpoint\n", | ||
"vgg_auc_aug, vgg_y_true_aug, vgg_y_pred_aug = DMAucModelCheckpoint.calc_test_auc(\n", | ||
" test_generator, vgg_mod, test_samples=test_generator.nb_sample, return_y_res=True, test_augment=True)\n", | ||
"print vgg_auc_aug" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[ 0.88237829 0.88237829]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from dm_keras_ext import DMAucModelCheckpoint\n", | ||
"hybrid_auc_aug, hybrid_y_true_aug, hybrid_y_pred_aug = DMAucModelCheckpoint.calc_test_auc(\n", | ||
" test_generator, hybrid_mod, test_samples=test_generator.nb_sample, return_y_res=True, test_augment=True)\n", | ||
"print hybrid_auc_aug" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0.907827086026\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from sklearn.metrics import roc_auc_score\n", | ||
"all_mod_y_pred_avg_aug = (res_y_pred_aug[:,1] + vgg_y_pred_aug[:,1] + hybrid_y_pred_aug[:,1])/3\n", | ||
"print roc_auc_score(res_y_true_aug[:,1], all_mod_y_pred_avg_aug)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"source": [ | ||
"Done." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |