|
37 | 37 | "from tensorflow.keras.callbacks import EarlyStopping\n",
|
38 | 38 | "from tensorflow.keras.models import Sequential\n",
|
39 | 39 | "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
|
40 |
| - "from tensorflow.keras import layers\n", |
41 |
| - "from keras.applications import ConvNeXtTiny" |
| 40 | + "from tensorflow.keras import layers" |
42 | 41 | ]
|
43 | 42 | },
|
44 | 43 | {
|
|
49 | 48 | "___________________________________________________________________________________________________________________________________________________________________________________________________\n",
|
50 | 49 | "# Neural Network\n",
|
51 | 50 | "\n",
|
52 |
| - "Here we build a basic neural network to classify out images. The below code repurposed many aspects of previous projects I worked on with colleagues. Most of the neural network and metrics takes inspiration from [A plant disease classification project](https://github.com/DerikVo/DSI_project_4_plant_disease) and a single day [Hack-a-thon](https://github.com/DerikVo/NN_hackathon) to classify if an object was a hotdog or not a hotdog." |
| 51 | + "Here we build a basic neural network to classify out images. The below code repurposed many aspects of previous projects I worked on with colleagues. Most of the neural network and metrics takes inspiration from [A plant disease classification project](https://github.com/DerikVo/DSI_project_4_plant_disease) and a single day [Hack-a-thon](https://github.com/DerikVo/NN_hackathon) to classify if an object was a hotdog or not a hotdog.\n", |
| 52 | + "\n", |
| 53 | + "We opted to use a convolutional neural network because of its ability to capture important features by scanning through segments of an image. These features can be shapes and textures that distinguish the uniqueness of a type of tumor. Additionally these models can be used in transfer learning which will allow for more accuracy and less time spent on training the model. Furthermore, because pre-trained models are trained on a diverse set of data our model can be more robust to unseen data. " |
53 | 54 | ]
|
54 | 55 | },
|
55 | 56 | {
|
|
194 | 195 | "output_type": "stream",
|
195 | 196 | "text": [
|
196 | 197 | "Epoch 1/10\n",
|
197 |
| - "125/125 [==============================] - 87s 574ms/step - loss: 6.8223 - accuracy: 0.7800 - val_loss: 1.1457 - val_accuracy: 0.7775\n", |
| 198 | + "125/125 [==============================] - 43s 321ms/step - loss: 6.8280 - accuracy: 0.7810 - val_loss: 1.0524 - val_accuracy: 0.7558\n", |
198 | 199 | "Epoch 2/10\n",
|
199 |
| - "125/125 [==============================] - 50s 402ms/step - loss: 0.2138 - accuracy: 0.9258 - val_loss: 1.0864 - val_accuracy: 0.7079\n", |
| 200 | + "125/125 [==============================] - 44s 348ms/step - loss: 0.2021 - accuracy: 0.9373 - val_loss: 1.0493 - val_accuracy: 0.7336\n", |
200 | 201 | "Epoch 3/10\n",
|
201 |
| - "125/125 [==============================] - 54s 432ms/step - loss: 0.1285 - accuracy: 0.9575 - val_loss: 1.2109 - val_accuracy: 0.7623\n", |
| 202 | + "125/125 [==============================] - 43s 347ms/step - loss: 0.1155 - accuracy: 0.9605 - val_loss: 1.4395 - val_accuracy: 0.7407\n", |
202 | 203 | "Epoch 4/10\n",
|
203 |
| - "125/125 [==============================] - 81s 649ms/step - loss: 0.0572 - accuracy: 0.9820 - val_loss: 1.7071 - val_accuracy: 0.7407\n", |
| 204 | + "125/125 [==============================] - 44s 355ms/step - loss: 0.0583 - accuracy: 0.9837 - val_loss: 1.6265 - val_accuracy: 0.7342\n", |
204 | 205 | "Epoch 5/10\n",
|
205 |
| - "125/125 [==============================] - 55s 441ms/step - loss: 0.0271 - accuracy: 0.9905 - val_loss: 1.7876 - val_accuracy: 0.7815\n", |
| 206 | + "125/125 [==============================] - 42s 335ms/step - loss: 0.0385 - accuracy: 0.9872 - val_loss: 1.9628 - val_accuracy: 0.7482\n", |
206 | 207 | "Epoch 6/10\n",
|
207 |
| - "125/125 [==============================] - 82s 654ms/step - loss: 0.0348 - accuracy: 0.9902 - val_loss: 1.7913 - val_accuracy: 0.7523\n", |
| 208 | + "125/125 [==============================] - 43s 340ms/step - loss: 0.0331 - accuracy: 0.9887 - val_loss: 1.7622 - val_accuracy: 0.7734\n", |
208 | 209 | "Epoch 7/10\n",
|
209 |
| - "125/125 [==============================] - 81s 649ms/step - loss: 0.0084 - accuracy: 0.9985 - val_loss: 1.7633 - val_accuracy: 0.7687\n" |
| 210 | + "125/125 [==============================] - 43s 346ms/step - loss: 0.0187 - accuracy: 0.9948 - val_loss: 2.5243 - val_accuracy: 0.7418\n" |
210 | 211 | ]
|
211 | 212 | }
|
212 | 213 | ],
|
|
230 | 231 | "metadata": {},
|
231 | 232 | "source": [
|
232 | 233 | "### Interpretation:\n",
|
233 |
| - "Here we see that our training accuracy is about 99% while our validation is 76% which suggest our model is very overfit. We will need to either reduce features or add some regularization. The validation score is higher than our baseline, but the score is lower than [Munir)](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7794124/) and their team's study accuracy of 87% (N=154). However, this is simply a supportive tool to assist radiologist, and the radiologist response would continue to train the model.\n", |
| 234 | + "Here we see that our training accuracy is about 99% while our validation is 74% which suggest our model is very overfit. We will need to either reduce features or add some regularization. The validation score is higher than our baseline, but the score is lower than [Munir)](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7794124/) and their team's study accuracy of 87% (N=154). However, this is simply a supportive tool to assist radiologist, and the radiologist response would continue to train the model.\n", |
234 | 235 | "\n",
|
235 | 236 | "For out next iteration, lets try adding some regularization to see if it can reduce overfitting so our model can be more generalized."
|
236 | 237 | ]
|
|
293 | 294 | "output_type": "stream",
|
294 | 295 | "text": [
|
295 | 296 | "Epoch 1/10\n",
|
296 |
| - "125/125 [==============================] - 60s 458ms/step - loss: 21.2878 - accuracy: 0.6155 - val_loss: 6.0345 - val_accuracy: 0.6232\n", |
| 297 | + "125/125 [==============================] - 48s 380ms/step - loss: 21.2882 - accuracy: 0.6140 - val_loss: 6.0970 - val_accuracy: 0.5695\n", |
297 | 298 | "Epoch 2/10\n",
|
298 |
| - "125/125 [==============================] - 56s 449ms/step - loss: 4.9348 - accuracy: 0.7905 - val_loss: 5.2085 - val_accuracy: 0.5917\n", |
| 299 | + "125/125 [==============================] - 47s 375ms/step - loss: 4.9106 - accuracy: 0.8052 - val_loss: 5.2855 - val_accuracy: 0.6034\n", |
299 | 300 | "Epoch 3/10\n",
|
300 |
| - "125/125 [==============================] - 86s 683ms/step - loss: 3.9861 - accuracy: 0.8510 - val_loss: 4.1504 - val_accuracy: 0.7009\n", |
| 301 | + "125/125 [==============================] - 46s 370ms/step - loss: 3.9846 - accuracy: 0.8460 - val_loss: 4.1538 - val_accuracy: 0.7272\n", |
301 | 302 | "Epoch 4/10\n",
|
302 |
| - "125/125 [==============================] - 55s 441ms/step - loss: 3.2915 - accuracy: 0.8687 - val_loss: 3.8028 - val_accuracy: 0.7062\n", |
| 303 | + "125/125 [==============================] - 46s 366ms/step - loss: 3.3387 - accuracy: 0.8655 - val_loss: 3.8504 - val_accuracy: 0.7068\n", |
303 | 304 | "Epoch 5/10\n",
|
304 |
| - "125/125 [==============================] - 58s 460ms/step - loss: 2.8297 - accuracy: 0.8915 - val_loss: 3.3022 - val_accuracy: 0.7447\n", |
| 305 | + "125/125 [==============================] - 46s 368ms/step - loss: 2.8415 - accuracy: 0.8882 - val_loss: 3.4656 - val_accuracy: 0.7284\n", |
305 | 306 | "Epoch 6/10\n",
|
306 |
| - "125/125 [==============================] - 85s 678ms/step - loss: 2.4836 - accuracy: 0.8950 - val_loss: 2.9780 - val_accuracy: 0.7436\n", |
| 307 | + "125/125 [==============================] - 46s 367ms/step - loss: 2.4600 - accuracy: 0.9028 - val_loss: 2.9135 - val_accuracy: 0.7634\n", |
307 | 308 | "Epoch 7/10\n",
|
308 |
| - "125/125 [==============================] - 56s 445ms/step - loss: 2.2336 - accuracy: 0.9015 - val_loss: 2.7743 - val_accuracy: 0.7471\n", |
| 309 | + "125/125 [==============================] - 46s 365ms/step - loss: 2.2206 - accuracy: 0.9010 - val_loss: 2.6101 - val_accuracy: 0.7623\n", |
309 | 310 | "Epoch 8/10\n",
|
310 |
| - "125/125 [==============================] - 56s 443ms/step - loss: 2.0099 - accuracy: 0.9078 - val_loss: 2.5257 - val_accuracy: 0.7529\n", |
| 311 | + "125/125 [==============================] - 46s 368ms/step - loss: 1.9791 - accuracy: 0.9128 - val_loss: 2.5702 - val_accuracy: 0.7512\n", |
311 | 312 | "Epoch 9/10\n",
|
312 |
| - "125/125 [==============================] - 86s 684ms/step - loss: 1.8300 - accuracy: 0.9137 - val_loss: 2.6962 - val_accuracy: 0.7237\n", |
| 313 | + "125/125 [==============================] - 46s 366ms/step - loss: 1.8075 - accuracy: 0.9122 - val_loss: 2.3851 - val_accuracy: 0.7629\n", |
313 | 314 | "Epoch 10/10\n",
|
314 |
| - "125/125 [==============================] - 59s 473ms/step - loss: 1.7438 - accuracy: 0.9062 - val_loss: 2.4427 - val_accuracy: 0.7348\n" |
| 315 | + "125/125 [==============================] - 46s 367ms/step - loss: 1.6626 - accuracy: 0.9187 - val_loss: 2.3468 - val_accuracy: 0.7430\n" |
315 | 316 | ]
|
316 | 317 | }
|
317 | 318 | ],
|
|
337 | 338 | },
|
338 | 339 | "source": [
|
339 | 340 | "### Interpretation:\n",
|
340 |
| - "Here we see that our training accuracy is about 90% while our validation is 73% which suggest our model is still overfit, but not as much. The model does better than our baseline model's accuracy of 46% but is less than the accuracy in [Munir's team's](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7794124/) study which found the accuracy of two radiologist was 87%.\n", |
| 341 | + "Here we see that our training accuracy is about 91% while our validation is 74% which suggest our model is still overfit, but not as much. The model does better than our baseline model's accuracy of 46% but is less than the accuracy in [Munir's team's](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7794124/) study which found the accuracy of two radiologist was 87%.\n", |
341 | 342 | "\n",
|
342 |
| - "Since our validation score was higher without regularization we will stick with the first model. " |
343 |
| - ] |
344 |
| - }, |
345 |
| - { |
346 |
| - "cell_type": "code", |
347 |
| - "execution_count": 14, |
348 |
| - "id": "27c2a852-8f70-4fbe-9d78-0507ea65995e", |
349 |
| - "metadata": {}, |
350 |
| - "outputs": [], |
351 |
| - "source": [ |
352 |
| - "import sys\n", |
353 |
| - "sys.path.append('../modules/')\n", |
354 |
| - "import model as m\n", |
355 |
| - "from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix" |
| 343 | + "Since our validation scores are pretty similar we will have to evaluate the models on other metrics such as precision to see which model suits our needs." |
356 | 344 | ]
|
357 | 345 | },
|
358 | 346 | {
|
|
365 | 353 | "__________________________________________________________________________________________________________________________________________________________________________________________________________________\n",
|
366 | 354 | "# Conclusion:\n",
|
367 | 355 | "\n",
|
368 |
| - "It appears our neural networks have similar scores. These score better than our baseline of 46%, but does less than the accuracy (87%) of the radiologist found in the [Munir et al. (2021)](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7794124/) study. It should noted their sample size was 154 patients while this data set had over 7000 images; however, we need to keep in mind multiple images could be of the same patient.\n", |
| 356 | + "It appears our neural networks have similar scores. These score better than our baseline of 46%, but does less than the accuracy (87%) of the radiologists found in the [Munir et al. (2021)](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7794124/) study. It should noted their sample size was 154 patients while this data set had over 7000 images; however, we need to keep in mind multiple images could be of the same patient.\n", |
369 | 357 | "\n",
|
370 |
| - "A neural network implementing augmentation was attempted, but that was an issue with running out of memory. There was attempts at saving the images instead, but that was causing conflicts as well so augmentation was scrapped.\n", |
| 358 | + "A neural network implementing augmentation was attempted, but there was an issue with running out of memory. There was an attempt at saving the images instead, but that was causing conflicts as well so augmentation was scrapped. Using a pre-trained model was also tested, specifically MobileNet and NASNetMobile, but those models did not work with greyscale images so that idea was also scrapped. We wanted a lightweight pretrained model for the purposes of this classification problem, so that was the logic behind selecting those two models. In the future more research would need to be conducted on which pre-trained models can be combined with out model to improve accuracy, but due to team constraints that will have to be put on hold.\n", |
371 | 359 | "\n",
|
372 |
| - "We will now proceed to our [Modeling Evaluation Notebook](../Notebooks/04_Model_evaluation.ipynb) to evaluate our models even further." |
| 360 | + "We will now proceed to our [Modeling Evaluation Notebook](../Notebooks/04_Model_evaluation.ipynb) to evaluate our models on other metrics such as their precision scores." |
373 | 361 | ]
|
374 | 362 | }
|
375 | 363 | ],
|
|
0 commit comments