Spaces:
Sleeping
Sleeping
File size: 3,952 Bytes
299b96a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "FjDGwlCJYO2m"
},
"source": [
"### Model Inferences"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "DUXRPvLRxpJe"
},
"outputs": [],
"source": [
"import pandas as pd \n",
"import numpy as np\n",
"from tensorflow import keras\n",
"import tensorflow as tf\n",
"import pickle\n",
"from keras.models import load_model\n",
"from tensorflow.keras.preprocessing import image \n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "WOLLnPnAuzKm",
"outputId": "644f852b-b695-40d8-db1c-3a8e502ca316"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mounted at /content/drive\n"
]
}
],
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "9nTgKQUKu61s",
"outputId": "3105e278-99eb-468d-8890-4079916391b2"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/content/drive/MyDrive/cnn_model\n"
]
}
],
"source": [
"%cd /content/drive/MyDrive/cnn_model"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"id": "ij3PCeoCyU23"
},
"outputs": [],
"source": [
"def prediction(file):\n",
" img = tf.keras.utils.load_img(file, target_size=(224, 224))\n",
" x = tf.keras.utils.img_to_array(img)\n",
" x = np.expand_dims(x, axis=0)\n",
"\n",
" # Load the saved model\n",
" loaded_model = load_model('cnn_model.h5')\n",
"\n",
" # Predict the class probabilities\n",
" classes = loaded_model.predict(x)\n",
"\n",
" # Get the predicted class label\n",
" classes = np.ravel(classes) # convert to 1D array\n",
" idx = np.argmax(classes)\n",
" clas = ['adenocarcinoma', 'large.cell.carcinoma', 'normal', 'squamous.cell.carcinoma']\n",
"\n",
" # Print the predicted class label\n",
" print('Prediction is a {}'.format(clas[idx]))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "h4xpRFtUw-OR",
"outputId": "6af2e2d1-3f78-4a9a-a7b2-b8e83db72e6b"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1/1 [==============================] - 2s 2s/step\n",
"Prediction is a normal\n"
]
}
],
"source": [
"prediction('Adenocarcinoma-in-situ-Axial-contrast-enhanced-chest-CT-scan-with-lung-window.png')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "VG4syGUcYjSK"
},
"source": [
"Prediction wrong, the model should maintained for next utilization"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.7.16"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
|