This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
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
55483dc
commit cd2fd53
Showing
12 changed files
with
11 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Ensemble_bm.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"accelerator":"GPU"},"cells":[{"cell_type":"markdown","metadata":{"id":"hSxMF0ZdPDcH"},"source":["# Ensemble"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"cIAvz87XOUVp","executionInfo":{"status":"ok","timestamp":1613064579262,"user_tz":-60,"elapsed":4389,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"7d4ee369-85c9-457d-a2f7-14401d67109d"},"source":["!pip install import-ipynb"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Collecting import-ipynb\n"," Downloading https://files.pythonhosted.org/packages/63/35/495e0021bfdcc924c7cdec4e9fbb87c88dd03b9b9b22419444dc370c8a45/import-ipynb-0.1.3.tar.gz\n","Building wheels for collected packages: import-ipynb\n"," Building wheel for import-ipynb (setup.py) ... \u001b[?25l\u001b[?25hdone\n"," Created wheel for import-ipynb: filename=import_ipynb-0.1.3-cp36-none-any.whl size=2976 sha256=f299ae3c725d7c35898563a06c7c3956c8f4d51587311466c241d17099a775a2\n"," Stored in directory: /root/.cache/pip/wheels/b4/7b/e9/a3a6e496115dffdb4e3085d0ae39ffe8a814eacc44bbf494b5\n","Successfully built import-ipynb\n","Installing collected packages: import-ipynb\n","Successfully installed import-ipynb-0.1.3\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"F85lDRArPLLU","executionInfo":{"status":"ok","timestamp":1613064604387,"user_tz":-60,"elapsed":19101,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"17142c73-8c0c-4ba8-c168-d07e08fc7784"},"source":["from google.colab import drive\r\n","drive.mount('/content/gdrive')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Mounted at /content/gdrive\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"9RFsmJWwPL48","executionInfo":{"status":"ok","timestamp":1613064606065,"user_tz":-60,"elapsed":434,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"0f245a77-127c-4d55-a5b9-da339c0027c2"},"source":["%cd '/content/gdrive/MyDrive/Colab'"],"execution_count":null,"outputs":[{"output_type":"stream","text":["/content/gdrive/MyDrive/Colab\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"LGQ8qdIkPVR0","executionInfo":{"status":"ok","timestamp":1613064610849,"user_tz":-60,"elapsed":3043,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"5cb93c50-033c-4dd5-f5fa-2e93c18ad516"},"source":["import import_ipynb\r\n","import os\r\n","import sklearn.metrics as metrics\r\n","import Utils as utils\r\n","import tensorflow as tf\r\n","import numpy as np"],"execution_count":null,"outputs":[{"output_type":"stream","text":["importing Jupyter notebook from Utils.ipynb\n","Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount(\"/content/gdrive\", force_remount=True).\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"lHYNgo8GGMa6"},"source":["## Models"]},{"cell_type":"code","metadata":{"id":"ykpRXU2ZPcHN"},"source":["#Load best models\r\n","\r\n","scratch = tf.keras.models.load_model('/content/gdrive/MyDrive/Colab/bestmodels/Copia di scratch_bm_64.h5')\r\n","\r\n","inception = tf.keras.models.load_model('/content/gdrive/MyDrive/Colab/bestmodels/Copia di inception_bm_16.h5')\r\n","\r\n","vgg = tf.keras.models.load_model('/content/gdrive/MyDrive/Colab/bestmodels/Copia di vgg_bm_32.h5')"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"W8gky2Q4GOSv"},"source":["## Data preprocessing"]},{"cell_type":"code","metadata":{"id":"hUWbt7YEBUYR"},"source":["test_images, test_labels = utils.load_test()\r\n","test_dataset, test_lab = utils.binarize(test_images, test_labels, 'benign_malignant')"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"kfwHbP_7Eeg1"},"source":["#Scratch\r\n","test_scratch = utils.rescale(test_dataset)\r\n","test_scratch = np.expand_dims(test_scratch, axis=3)\r\n","\r\n","#Inception \r\n","\r\n","test_inception = utils.rescale(test_dataset)\r\n","test_inception = [np.stack((test_inception[i],)*3, axis=2) for i in range (len(test_inception))]\r\n","test_inception = np.array(test_inception)"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"0gqoBD1WGQNj"},"source":["## Evaluation"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"WeIwRs9xSZPc","executionInfo":{"status":"ok","timestamp":1613064724488,"user_tz":-60,"elapsed":9806,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"d72dc78d-201c-4f37-8af6-ab787234ce9f"},"source":["#Scratch\r\n","\r\n","predicted_s = scratch.predict(test_scratch, verbose=1)\r\n","pred_s = [0 if x <=0.5 else 1 for x in predicted_s]\r\n","\r\n","#Inception \r\n","predicted_i = inception.predict(test_inception, verbose=1)\r\n","pred_i = [0 if x <=0.5 else 1 for x in predicted_i]\r\n","\r\n","#Vgg\r\n","predicted_v = vgg.predict(test_inception, verbose=1)\r\n","pred_v = [0 if x <=0.5 else 1 for x in predicted_v]"],"execution_count":null,"outputs":[{"output_type":"stream","text":["11/11 [==============================] - 7s 16ms/step\n","11/11 [==============================] - 1s 24ms/step\n","11/11 [==============================] - 1s 73ms/step\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"drZwY0OueShA","executionInfo":{"status":"ok","timestamp":1613064726433,"user_tz":-60,"elapsed":420,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"23978bb8-225c-4a3c-aa09-f9c1838e6b83"},"source":["#Compute AUC Score\r\n","\r\n","score_scratch = metrics.roc_auc_score(test_lab, pred_s, average=\"weighted\")\r\n","score_inception = metrics.roc_auc_score(test_lab, pred_i, average=\"weighted\")\r\n","score_vgg = metrics.roc_auc_score(test_lab, pred_v, average=\"weighted\")\r\n","\r\n","print(\"Scratch Score: \", score_scratch)\r\n","print(\"Inception Score: \", score_inception)\r\n","print(\"VGG Score: \", score_vgg)\r\n"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Scratch Score: 0.6567732115677322\n","Inception Score: 0.7068844397611522\n","VGG Score: 0.6661983374312141\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"3w398TXsmai2","executionInfo":{"status":"ok","timestamp":1613064782379,"user_tz":-60,"elapsed":417,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"149171d6-0a08-4a94-a8ef-1c0683f57a1c"},"source":["predicted_s = np.reshape(predicted_s, -1)\r\n","predicted_i = np.reshape(predicted_i, -1)\r\n","predicted_v = np.reshape(predicted_v, -1)\r\n","\r\n","ensemble_results = 0.33* (predicted_s*score_scratch + predicted_i*score_inception + predicted_v*score_vgg)\r\n","ensemble_results = [0 if x <=0.5 else 1 for x in ensemble_results]\r\n","\r\n","utils.evaluate_classifier(test_lab, ensemble_results)\r\n"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Performances: \n","Accuracy: 0.6845238095238095\n","Precision: 0.7081065759637188\n","Recall: 0.6845238095238095\n","F1-score: 0.6031503710424082\n","AUC: 0.5569605432619131\n"],"name":"stdout"}]}]} |
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 @@ | ||
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Ensemble_mc.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"accelerator":"GPU"},"cells":[{"cell_type":"markdown","metadata":{"id":"hSxMF0ZdPDcH"},"source":["# Ensemble"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"cIAvz87XOUVp","executionInfo":{"status":"ok","timestamp":1613065166552,"user_tz":-60,"elapsed":5233,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"a29c371c-9235-430b-8270-7e2948d1f9d2"},"source":["!pip install import-ipynb"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Collecting import-ipynb\n"," Downloading https://files.pythonhosted.org/packages/63/35/495e0021bfdcc924c7cdec4e9fbb87c88dd03b9b9b22419444dc370c8a45/import-ipynb-0.1.3.tar.gz\n","Building wheels for collected packages: import-ipynb\n"," Building wheel for import-ipynb (setup.py) ... \u001b[?25l\u001b[?25hdone\n"," Created wheel for import-ipynb: filename=import_ipynb-0.1.3-cp36-none-any.whl size=2976 sha256=284595d83ff1d63c7e431a59c2a1fa16f084e9c4c3b22be5d2428dbcf496c2ba\n"," Stored in directory: /root/.cache/pip/wheels/b4/7b/e9/a3a6e496115dffdb4e3085d0ae39ffe8a814eacc44bbf494b5\n","Successfully built import-ipynb\n","Installing collected packages: import-ipynb\n","Successfully installed import-ipynb-0.1.3\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"F85lDRArPLLU","executionInfo":{"status":"ok","timestamp":1613065186963,"user_tz":-60,"elapsed":18654,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"2397a3aa-6171-4c33-ed46-36986cd429f1"},"source":["from google.colab import drive\r\n","drive.mount('/content/gdrive')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Mounted at /content/gdrive\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"9RFsmJWwPL48","executionInfo":{"status":"ok","timestamp":1613065188490,"user_tz":-60,"elapsed":435,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"337a701c-b30a-4a64-b438-2857865a6944"},"source":["%cd '/content/gdrive/MyDrive/Colab'"],"execution_count":null,"outputs":[{"output_type":"stream","text":["/content/gdrive/MyDrive/Colab\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"LGQ8qdIkPVR0","executionInfo":{"status":"ok","timestamp":1613065192840,"user_tz":-60,"elapsed":3034,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"36b17db6-3cab-4978-9e60-333abd19acee"},"source":["import import_ipynb\r\n","import os\r\n","import sklearn.metrics as metrics\r\n","import Utils as utils\r\n","import tensorflow as tf\r\n","import numpy as np"],"execution_count":null,"outputs":[{"output_type":"stream","text":["importing Jupyter notebook from Utils.ipynb\n","Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount(\"/content/gdrive\", force_remount=True).\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"7RkOjP7gF-jJ"},"source":["# Models"]},{"cell_type":"code","metadata":{"id":"ykpRXU2ZPcHN"},"source":["#Load best models\r\n","\r\n","scratch = tf.keras.models.load_model('/content/gdrive/MyDrive/Colab/bestmodels/Copia di scratch_mc_32.h5')\r\n","\r\n","inception = tf.keras.models.load_model('/content/gdrive/MyDrive/Colab/bestmodels/Copia di inception_mc_16_3.h5')\r\n","\r\n","vgg = tf.keras.models.load_model('/content/gdrive/MyDrive/Colab/bestmodels/Copia di vgg_mc_64_2.h5')"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"1GvFdKoAGCL9"},"source":["## Data preprocessing"]},{"cell_type":"code","metadata":{"id":"hUWbt7YEBUYR"},"source":["test_images, test_labels = utils.load_test()\r\n","test_dataset, test_lab = utils.binarize(test_images, test_labels, 'mass_calcification')"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"kfwHbP_7Eeg1"},"source":["#Scratch\r\n","test_scratch = utils.rescale(test_dataset)\r\n","test_scratch = np.expand_dims(test_scratch, axis=3)\r\n","\r\n","#Inception \r\n","\r\n","test_inception = utils.rescale(test_dataset)\r\n","test_inception = [np.stack((test_inception[i],)*3, axis=2) for i in range (len(test_inception))]\r\n","\r\n","test_inception = np.array(test_inception)"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"sLGc7X9rGF_k"},"source":["## Evaluation"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"WeIwRs9xSZPc","executionInfo":{"status":"ok","timestamp":1613065285986,"user_tz":-60,"elapsed":9935,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"e21ba781-9fc4-4cca-9e32-0cb7a750174d"},"source":["#Scratch\r\n","\r\n","predicted_s = scratch.predict(test_scratch, verbose=1)\r\n","pred_s = [0 if x <=0.5 else 1 for x in predicted_s]\r\n","\r\n","#Inception \r\n","predicted_i = inception.predict(test_inception, verbose=1)\r\n","pred_i = [0 if x <=0.5 else 1 for x in predicted_i]\r\n","\r\n","#Vgg\r\n","predicted_v = vgg.predict(test_inception, verbose=1)\r\n","pred_v = [0 if x <=0.5 else 1 for x in predicted_v]"],"execution_count":null,"outputs":[{"output_type":"stream","text":["11/11 [==============================] - 7s 17ms/step\n","11/11 [==============================] - 1s 24ms/step\n","11/11 [==============================] - 1s 73ms/step\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"drZwY0OueShA","executionInfo":{"status":"ok","timestamp":1613065291585,"user_tz":-60,"elapsed":533,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"c29c9fad-f208-4c12-b845-b6f82ca1f30f"},"source":["#Compute AUC Score\r\n","\r\n","score_scratch = metrics.roc_auc_score(test_lab, pred_s, average=\"weighted\")\r\n","score_inception = metrics.roc_auc_score(test_lab, pred_i, average=\"weighted\")\r\n","score_vgg = metrics.roc_auc_score(test_lab, pred_v, average=\"weighted\")\r\n","\r\n","print(\"Scratch Score: \", score_scratch)\r\n","print(\"Inception Score: \", score_inception)\r\n","print(\"VGG Score: \", score_vgg)\r\n"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Scratch Score: 0.8716685051417998\n","Inception Score: 0.9142974059708928\n","VGG Score: 0.8764188876632388\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"3w398TXsmai2","executionInfo":{"status":"ok","timestamp":1613065299933,"user_tz":-60,"elapsed":397,"user":{"displayName":"Lorenzo Barigliano","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GhJz2zmPaDWvwZTBDgVWH7MHpMbI7nlRMYGlzSK=s64","userId":"15301674381195144039"}},"outputId":"9473585c-d1ea-4468-fa0b-87f8ec72eeba"},"source":["predicted_s = np.reshape(predicted_s, -1)\r\n","predicted_i = np.reshape(predicted_i, -1)\r\n","predicted_v = np.reshape(predicted_v, -1)\r\n","\r\n","ensemble_results = 0.33* (predicted_s*score_scratch + predicted_i*score_inception + predicted_v*score_vgg)\r\n","ensemble_results = [0 if x <=0.5 else 1 for x in ensemble_results]\r\n","\r\n","utils.evaluate_classifier(test_lab, ensemble_results)\r\n"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Performances: \n","Accuracy: 0.9017857142857143\n","Precision: 0.9017615486365487\n","Recall: 0.9017857142857143\n","F1-score: 0.9017656111542661\n","AUC: 0.9011671351812973\n"],"name":"stdout"}]}]} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.