Upload 4 files
Browse files- app.py +52 -0
- breast_cancer_detection_model3.h5 +3 -0
- cancer_detection_final.ipynb +826 -0
- requirements.txt.txt +1 -0
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import cv2 # Ensure you have opencv-python installed
|
4 |
+
from tensorflow.keras.models import load_model # Ensure you have TensorFlow installed
|
5 |
+
|
6 |
+
# Load your trained model
|
7 |
+
model = load_model(r"F:\pe udemy\PROJECTS\incomplete\cancer\breast_cancer_detection_model3.h5") # Update this path to your actual model file
|
8 |
+
|
9 |
+
# Define class names according to your model
|
10 |
+
class_names = ['benign', 'malignant', 'normal'] # Update this list if different
|
11 |
+
|
12 |
+
# Define the prediction function
|
13 |
+
def predict_cancer(images):
|
14 |
+
results = []
|
15 |
+
for img in images:
|
16 |
+
# Convert image to grayscale (if it's not already), resize, and normalize
|
17 |
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) # Convert to grayscale if not already
|
18 |
+
img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) # Resize to match model input
|
19 |
+
img = np.expand_dims(img, axis=-1) # Add channel dimension
|
20 |
+
img = img / 255.0 # Normalize
|
21 |
+
img = np.expand_dims(img, axis=0) # Add batch dimension
|
22 |
+
|
23 |
+
# Make prediction
|
24 |
+
prediction = model.predict(img)
|
25 |
+
class_idx = np.argmax(prediction[0])
|
26 |
+
class_name = class_names[class_idx]
|
27 |
+
probability = np.max(prediction[0])
|
28 |
+
results.append(f"{class_name} (Probability: {probability:.2f})")
|
29 |
+
|
30 |
+
return results
|
31 |
+
|
32 |
+
# Define Gradio interface
|
33 |
+
def classify_images(images):
|
34 |
+
if not isinstance(images, list): # Ensure `images` is a list of images
|
35 |
+
images = [images]
|
36 |
+
return predict_cancer(images)
|
37 |
+
|
38 |
+
# Define the Gradio interface
|
39 |
+
input_images = gr.Image(type='numpy', label='Upload Ultrasound Images')
|
40 |
+
output_labels = gr.Textbox(label='Predictions')
|
41 |
+
|
42 |
+
gr_interface = gr.Interface(
|
43 |
+
fn=classify_images,
|
44 |
+
inputs=input_images,
|
45 |
+
outputs=output_labels,
|
46 |
+
title="Breast Cancer Detection from Ultrasound Images",
|
47 |
+
description="Upload multiple breast ultrasound images to get predictions on whether they show benign, malignant, or normal conditions."
|
48 |
+
)
|
49 |
+
|
50 |
+
# Launch the Gradio app
|
51 |
+
if __name__ == "__main__":
|
52 |
+
gr_interface.launch()
|
breast_cancer_detection_model3.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:52cadf570c1291903515c9b2a825ac38781889f9164bbb4e3209892243dd7ba5
|
3 |
+
size 39706832
|
cancer_detection_final.ipynb
ADDED
@@ -0,0 +1,826 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"gpuType": "T4"
|
8 |
+
},
|
9 |
+
"kernelspec": {
|
10 |
+
"name": "python3",
|
11 |
+
"display_name": "Python 3"
|
12 |
+
},
|
13 |
+
"language_info": {
|
14 |
+
"name": "python"
|
15 |
+
},
|
16 |
+
"accelerator": "GPU"
|
17 |
+
},
|
18 |
+
"cells": [
|
19 |
+
{
|
20 |
+
"cell_type": "code",
|
21 |
+
"execution_count": 1,
|
22 |
+
"metadata": {
|
23 |
+
"colab": {
|
24 |
+
"base_uri": "https://localhost:8080/"
|
25 |
+
},
|
26 |
+
"id": "WSUey7APElVD",
|
27 |
+
"outputId": "105d40d0-6b44-4751-983f-a10c61aced01"
|
28 |
+
},
|
29 |
+
"outputs": [
|
30 |
+
{
|
31 |
+
"output_type": "stream",
|
32 |
+
"name": "stdout",
|
33 |
+
"text": [
|
34 |
+
"Mounted at /content/drive\n"
|
35 |
+
]
|
36 |
+
}
|
37 |
+
],
|
38 |
+
"source": [
|
39 |
+
"from google.colab import drive\n",
|
40 |
+
"drive.mount('/content/drive')"
|
41 |
+
]
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"cell_type": "code",
|
45 |
+
"source": [
|
46 |
+
"import zipfile\n",
|
47 |
+
"import os\n",
|
48 |
+
"\n",
|
49 |
+
"# Define the path to the zip file\n",
|
50 |
+
"zip_file_path = r\"/content/drive/MyDrive/new image set.zip\"\n",
|
51 |
+
"# Define the directory where you want to extract the files\n",
|
52 |
+
"extract_to_path = '/content/sample_data'\n",
|
53 |
+
"\n",
|
54 |
+
"# Create the directory if it doesn't exist\n",
|
55 |
+
"os.makedirs(extract_to_path, exist_ok=True)\n",
|
56 |
+
"\n",
|
57 |
+
"# Extract the zip file\n",
|
58 |
+
"with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:\n",
|
59 |
+
" zip_ref.extractall(extract_to_path)\n",
|
60 |
+
"\n",
|
61 |
+
"print(f'Files extracted to {extract_to_path}')\n"
|
62 |
+
],
|
63 |
+
"metadata": {
|
64 |
+
"colab": {
|
65 |
+
"base_uri": "https://localhost:8080/"
|
66 |
+
},
|
67 |
+
"id": "wFFWMZf0EpgC",
|
68 |
+
"outputId": "645ab679-03eb-4f43-9140-5b49486a5f44"
|
69 |
+
},
|
70 |
+
"execution_count": 2,
|
71 |
+
"outputs": [
|
72 |
+
{
|
73 |
+
"output_type": "stream",
|
74 |
+
"name": "stdout",
|
75 |
+
"text": [
|
76 |
+
"Files extracted to /content/sample_data\n"
|
77 |
+
]
|
78 |
+
}
|
79 |
+
]
|
80 |
+
},
|
81 |
+
{
|
82 |
+
"cell_type": "code",
|
83 |
+
"source": [],
|
84 |
+
"metadata": {
|
85 |
+
"id": "7mBWvK5oLUyw"
|
86 |
+
},
|
87 |
+
"execution_count": null,
|
88 |
+
"outputs": []
|
89 |
+
},
|
90 |
+
{
|
91 |
+
"cell_type": "code",
|
92 |
+
"source": [
|
93 |
+
"from tensorflow.keras.utils import to_categorical\n",
|
94 |
+
"\n",
|
95 |
+
"# Convert labels to one-hot encoded format\n",
|
96 |
+
"y_train = to_categorical(y_train, num_classes=3)\n",
|
97 |
+
"y_test = to_categorical(y_test, num_classes=3)\n"
|
98 |
+
],
|
99 |
+
"metadata": {
|
100 |
+
"id": "fujzpI9DMdS8"
|
101 |
+
},
|
102 |
+
"execution_count": 11,
|
103 |
+
"outputs": []
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"cell_type": "code",
|
107 |
+
"source": [
|
108 |
+
"!pip install gradio\n",
|
109 |
+
"\n"
|
110 |
+
],
|
111 |
+
"metadata": {
|
112 |
+
"colab": {
|
113 |
+
"base_uri": "https://localhost:8080/"
|
114 |
+
},
|
115 |
+
"id": "aNBOVK_clL5-",
|
116 |
+
"outputId": "2de76cb6-e5ef-47df-be71-f4af733edbde"
|
117 |
+
},
|
118 |
+
"execution_count": 6,
|
119 |
+
"outputs": [
|
120 |
+
{
|
121 |
+
"output_type": "stream",
|
122 |
+
"name": "stdout",
|
123 |
+
"text": [
|
124 |
+
"Collecting gradio\n",
|
125 |
+
" Using cached gradio-4.37.2-py3-none-any.whl (12.3 MB)\n",
|
126 |
+
"Collecting aiofiles<24.0,>=22.0 (from gradio)\n",
|
127 |
+
" Downloading aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
|
128 |
+
"Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.2.2)\n",
|
129 |
+
"Collecting fastapi (from gradio)\n",
|
130 |
+
" Downloading fastapi-0.111.0-py3-none-any.whl (91 kB)\n",
|
131 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.0/92.0 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
132 |
+
"\u001b[?25hCollecting ffmpy (from gradio)\n",
|
133 |
+
" Downloading ffmpy-0.3.2.tar.gz (5.5 kB)\n",
|
134 |
+
" Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
135 |
+
"Collecting gradio-client==1.0.2 (from gradio)\n",
|
136 |
+
" Downloading gradio_client-1.0.2-py3-none-any.whl (318 kB)\n",
|
137 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.2/318.2 kB\u001b[0m \u001b[31m10.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
138 |
+
"\u001b[?25hCollecting httpx>=0.24.1 (from gradio)\n",
|
139 |
+
" Downloading httpx-0.27.0-py3-none-any.whl (75 kB)\n",
|
140 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
141 |
+
"\u001b[?25hRequirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.23.4)\n",
|
142 |
+
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.4.0)\n",
|
143 |
+
"Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.4)\n",
|
144 |
+
"Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.5)\n",
|
145 |
+
"Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n",
|
146 |
+
"Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.25.2)\n",
|
147 |
+
"Collecting orjson~=3.0 (from gradio)\n",
|
148 |
+
" Downloading orjson-3.10.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (141 kB)\n",
|
149 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.1/141.1 kB\u001b[0m \u001b[31m9.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
150 |
+
"\u001b[?25hRequirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (24.1)\n",
|
151 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.3)\n",
|
152 |
+
"Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.4.0)\n",
|
153 |
+
"Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.7.4)\n",
|
154 |
+
"Collecting pydub (from gradio)\n",
|
155 |
+
" Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
|
156 |
+
"Collecting python-multipart>=0.0.9 (from gradio)\n",
|
157 |
+
" Downloading python_multipart-0.0.9-py3-none-any.whl (22 kB)\n",
|
158 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n",
|
159 |
+
"Collecting ruff>=0.2.2 (from gradio)\n",
|
160 |
+
" Downloading ruff-0.5.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.1 MB)\n",
|
161 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10.1/10.1 MB\u001b[0m \u001b[31m34.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
162 |
+
"\u001b[?25hCollecting semantic-version~=2.0 (from gradio)\n",
|
163 |
+
" Downloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
|
164 |
+
"Collecting tomlkit==0.12.0 (from gradio)\n",
|
165 |
+
" Downloading tomlkit-0.12.0-py3-none-any.whl (37 kB)\n",
|
166 |
+
"Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.3)\n",
|
167 |
+
"Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.12.2)\n",
|
168 |
+
"Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.7)\n",
|
169 |
+
"Collecting uvicorn>=0.14.0 (from gradio)\n",
|
170 |
+
" Downloading uvicorn-0.30.1-py3-none-any.whl (62 kB)\n",
|
171 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.4/62.4 kB\u001b[0m \u001b[31m10.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
172 |
+
"\u001b[?25hRequirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.0.2->gradio) (2023.6.0)\n",
|
173 |
+
"Collecting websockets<12.0,>=10.0 (from gradio-client==1.0.2->gradio)\n",
|
174 |
+
" Downloading websockets-11.0.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (129 kB)\n",
|
175 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m129.9/129.9 kB\u001b[0m \u001b[31m19.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
176 |
+
"\u001b[?25hRequirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.4)\n",
|
177 |
+
"Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (4.19.2)\n",
|
178 |
+
"Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.12.1)\n",
|
179 |
+
"Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (3.7.1)\n",
|
180 |
+
"Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (2024.6.2)\n",
|
181 |
+
"Collecting httpcore==1.* (from httpx>=0.24.1->gradio)\n",
|
182 |
+
" Downloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n",
|
183 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m12.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
184 |
+
"\u001b[?25hRequirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (3.7)\n",
|
185 |
+
"Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (1.3.1)\n",
|
186 |
+
"Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx>=0.24.1->gradio)\n",
|
187 |
+
" Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n",
|
188 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
189 |
+
"\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (3.15.4)\n",
|
190 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
|
191 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (4.66.4)\n",
|
192 |
+
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.2.1)\n",
|
193 |
+
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
|
194 |
+
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.53.0)\n",
|
195 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
|
196 |
+
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.2)\n",
|
197 |
+
"Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
|
198 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2023.4)\n",
|
199 |
+
"Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
|
200 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (0.7.0)\n",
|
201 |
+
"Requirement already satisfied: pydantic-core==2.18.4 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.18.4)\n",
|
202 |
+
"Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n",
|
203 |
+
"Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
|
204 |
+
"Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n",
|
205 |
+
"Collecting starlette<0.38.0,>=0.37.2 (from fastapi->gradio)\n",
|
206 |
+
" Downloading starlette-0.37.2-py3-none-any.whl (71 kB)\n",
|
207 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.9/71.9 kB\u001b[0m \u001b[31m9.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
208 |
+
"\u001b[?25hCollecting fastapi-cli>=0.0.2 (from fastapi->gradio)\n",
|
209 |
+
" Downloading fastapi_cli-0.0.4-py3-none-any.whl (9.5 kB)\n",
|
210 |
+
"Collecting ujson!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,>=4.0.1 (from fastapi->gradio)\n",
|
211 |
+
" Downloading ujson-5.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (53 kB)\n",
|
212 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.6/53.6 kB\u001b[0m \u001b[31m6.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
213 |
+
"\u001b[?25hCollecting email_validator>=2.0.0 (from fastapi->gradio)\n",
|
214 |
+
" Downloading email_validator-2.2.0-py3-none-any.whl (33 kB)\n",
|
215 |
+
"Collecting dnspython>=2.0.0 (from email_validator>=2.0.0->fastapi->gradio)\n",
|
216 |
+
" Downloading dnspython-2.6.1-py3-none-any.whl (307 kB)\n",
|
217 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.7/307.7 kB\u001b[0m \u001b[31m32.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
218 |
+
"\u001b[?25hRequirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n",
|
219 |
+
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n",
|
220 |
+
"Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.35.1)\n",
|
221 |
+
"Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.18.1)\n",
|
222 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
|
223 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
|
224 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.16.1)\n",
|
225 |
+
"Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx>=0.24.1->gradio) (1.2.1)\n",
|
226 |
+
"Collecting httptools>=0.5.0 (from uvicorn>=0.14.0->gradio)\n",
|
227 |
+
" Downloading httptools-0.6.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341 kB)\n",
|
228 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m341.4/341.4 kB\u001b[0m \u001b[31m38.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
229 |
+
"\u001b[?25hCollecting python-dotenv>=0.13 (from uvicorn>=0.14.0->gradio)\n",
|
230 |
+
" Downloading python_dotenv-1.0.1-py3-none-any.whl (19 kB)\n",
|
231 |
+
"Collecting uvloop!=0.15.0,!=0.15.1,>=0.14.0 (from uvicorn>=0.14.0->gradio)\n",
|
232 |
+
" Downloading uvloop-0.19.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB)\n",
|
233 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m63.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
234 |
+
"\u001b[?25hCollecting watchfiles>=0.13 (from uvicorn>=0.14.0->gradio)\n",
|
235 |
+
" Downloading watchfiles-0.22.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)\n",
|
236 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m58.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
237 |
+
"\u001b[?25hRequirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
|
238 |
+
"Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
|
239 |
+
"Building wheels for collected packages: ffmpy\n",
|
240 |
+
" Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
241 |
+
" Created wheel for ffmpy: filename=ffmpy-0.3.2-py3-none-any.whl size=5584 sha256=3035616028a0e3057fcfe21ff68584a08be5a66c1964ce9262eb7ba89e5db691\n",
|
242 |
+
" Stored in directory: /root/.cache/pip/wheels/bd/65/9a/671fc6dcde07d4418df0c592f8df512b26d7a0029c2a23dd81\n",
|
243 |
+
"Successfully built ffmpy\n",
|
244 |
+
"Installing collected packages: pydub, ffmpy, websockets, uvloop, ujson, tomlkit, semantic-version, ruff, python-multipart, python-dotenv, orjson, httptools, h11, dnspython, aiofiles, watchfiles, uvicorn, starlette, httpcore, email_validator, httpx, gradio-client, fastapi-cli, fastapi, gradio\n",
|
245 |
+
"Successfully installed aiofiles-23.2.1 dnspython-2.6.1 email_validator-2.2.0 fastapi-0.111.0 fastapi-cli-0.0.4 ffmpy-0.3.2 gradio-4.37.2 gradio-client-1.0.2 h11-0.14.0 httpcore-1.0.5 httptools-0.6.1 httpx-0.27.0 orjson-3.10.6 pydub-0.25.1 python-dotenv-1.0.1 python-multipart-0.0.9 ruff-0.5.0 semantic-version-2.10.0 starlette-0.37.2 tomlkit-0.12.0 ujson-5.10.0 uvicorn-0.30.1 uvloop-0.19.0 watchfiles-0.22.0 websockets-11.0.3\n"
|
246 |
+
]
|
247 |
+
}
|
248 |
+
]
|
249 |
+
},
|
250 |
+
{
|
251 |
+
"cell_type": "code",
|
252 |
+
"source": [
|
253 |
+
"import os\n",
|
254 |
+
"import cv2\n",
|
255 |
+
"import numpy as np\n",
|
256 |
+
"from sklearn.model_selection import train_test_split\n",
|
257 |
+
"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
|
258 |
+
"from tensorflow.keras.models import Sequential\n",
|
259 |
+
"from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout\n",
|
260 |
+
"import gradio as gr\n",
|
261 |
+
"import tensorflow as tf\n",
|
262 |
+
"from tensorflow.keras.utils import to_categorical\n",
|
263 |
+
"\n",
|
264 |
+
"# Define paths\n",
|
265 |
+
"dataset_folder = r\"/content/sample_data/Dataset_BUSI_with_GT\" # Path to the images folder\n",
|
266 |
+
"\n",
|
267 |
+
"# Define image size and class labels\n",
|
268 |
+
"IMG_SIZE = 128 # Image size for the model input\n",
|
269 |
+
"class_names = ['benign', 'malignant', 'normal']\n",
|
270 |
+
"class_mapping = {name: idx for idx, name in enumerate(class_names)}\n",
|
271 |
+
"\n",
|
272 |
+
"# Load images from each class folder\n",
|
273 |
+
"def load_images_from_folder(folder, class_label):\n",
|
274 |
+
" images = []\n",
|
275 |
+
" labels = []\n",
|
276 |
+
" for filename in os.listdir(folder):\n",
|
277 |
+
" img_path = os.path.join(folder, filename)\n",
|
278 |
+
" img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE) # Load in grayscale\n",
|
279 |
+
" if img is not None:\n",
|
280 |
+
" img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) # Resize image\n",
|
281 |
+
" img = np.expand_dims(img, axis=-1) # Add channel dimension\n",
|
282 |
+
" images.append(img)\n",
|
283 |
+
" labels.append(class_label)\n",
|
284 |
+
" return images, labels\n",
|
285 |
+
"\n",
|
286 |
+
"images = []\n",
|
287 |
+
"labels = []\n",
|
288 |
+
"\n",
|
289 |
+
"# Load images from each class folder\n",
|
290 |
+
"for class_name, class_label in class_mapping.items():\n",
|
291 |
+
" folder_path = os.path.join(dataset_folder, class_name)\n",
|
292 |
+
" imgs, lbls = load_images_from_folder(folder_path, class_label)\n",
|
293 |
+
" images.extend(imgs)\n",
|
294 |
+
" labels.extend(lbls)\n",
|
295 |
+
"\n",
|
296 |
+
"images = np.array(images)\n",
|
297 |
+
"labels = np.array(labels)\n",
|
298 |
+
"\n",
|
299 |
+
"# Convert labels to one-hot encoded format\n",
|
300 |
+
"y_train = to_categorical(labels, num_classes=3)\n",
|
301 |
+
"\n",
|
302 |
+
"# Split the dataset\n",
|
303 |
+
"X_train, X_test, y_train, y_test = train_test_split(images, y_train, test_size=0.2, random_state=42)\n",
|
304 |
+
"\n",
|
305 |
+
"# Data augmentation for training\n",
|
306 |
+
"train_datagen = ImageDataGenerator(\n",
|
307 |
+
" rescale=1./255,\n",
|
308 |
+
" shear_range=0.2,\n",
|
309 |
+
" zoom_range=0.2,\n",
|
310 |
+
" horizontal_flip=True\n",
|
311 |
+
")\n",
|
312 |
+
"\n",
|
313 |
+
"test_datagen = ImageDataGenerator(rescale=1./255)\n",
|
314 |
+
"\n",
|
315 |
+
"# Create Data Generators for training and testing\n",
|
316 |
+
"train_generator = train_datagen.flow(X_train, y_train, batch_size=32)\n",
|
317 |
+
"test_generator = test_datagen.flow(X_test, y_test, batch_size=32)\n",
|
318 |
+
"\n",
|
319 |
+
"# Define the CNN model\n",
|
320 |
+
"model = Sequential([\n",
|
321 |
+
" Conv2D(32, (3, 3), activation='relu', input_shape=(IMG_SIZE, IMG_SIZE, 1)), # Input is grayscale, hence single channel\n",
|
322 |
+
" MaxPooling2D((2, 2)),\n",
|
323 |
+
" Conv2D(64, (3, 3), activation='relu'),\n",
|
324 |
+
" MaxPooling2D((2, 2)),\n",
|
325 |
+
" Conv2D(128, (3, 3), activation='relu'),\n",
|
326 |
+
" MaxPooling2D((2, 2)),\n",
|
327 |
+
" Flatten(),\n",
|
328 |
+
" Dense(128, activation='relu'),\n",
|
329 |
+
" Dropout(0.5),\n",
|
330 |
+
" Dense(3, activation='softmax') # Three classes: Benign, Malignant, Normal\n",
|
331 |
+
"])\n",
|
332 |
+
"\n",
|
333 |
+
"model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n",
|
334 |
+
"model.summary()\n",
|
335 |
+
"\n",
|
336 |
+
"# Train the model\n",
|
337 |
+
"history = model.fit(\n",
|
338 |
+
" train_generator,\n",
|
339 |
+
" validation_data=test_generator,\n",
|
340 |
+
" epochs=25\n",
|
341 |
+
")\n",
|
342 |
+
"\n",
|
343 |
+
"# Save the model\n",
|
344 |
+
"model.save('breast_cancer_detection_model3.h5')\n",
|
345 |
+
"\n",
|
346 |
+
"# Define the prediction function\n",
|
347 |
+
"def predict_cancer(images):\n",
|
348 |
+
" results = []\n",
|
349 |
+
" for img in images:\n",
|
350 |
+
" # Ensure image is in RGB format and convert to grayscale\n",
|
351 |
+
" img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) # Convert to grayscale\n",
|
352 |
+
" img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) # Resize to match model input\n",
|
353 |
+
" img = np.expand_dims(img, axis=-1) # Add channel dimension\n",
|
354 |
+
" img = img / 255.0 # Normalize\n",
|
355 |
+
" img = np.expand_dims(img, axis=0) # Add batch dimension\n",
|
356 |
+
"\n",
|
357 |
+
" # Make prediction\n",
|
358 |
+
" prediction = model.predict(img)\n",
|
359 |
+
" class_idx = np.argmax(prediction[0])\n",
|
360 |
+
" class_name = class_names[class_idx]\n",
|
361 |
+
" probability = np.max(prediction[0])\n",
|
362 |
+
" results.append(f\"{class_name} (Probability: {probability:.2f})\")\n",
|
363 |
+
"\n",
|
364 |
+
" return results\n",
|
365 |
+
"\n",
|
366 |
+
"# Define Gradio interface\n",
|
367 |
+
"input_images = gr.Image(type='numpy', label='Upload Ultrasound Images', tool='editor', source='upload', shape=(IMG_SIZE, IMG_SIZE))\n",
|
368 |
+
"output_labels = gr.Textbox(label='Predictions')\n",
|
369 |
+
"\n",
|
370 |
+
"gr_interface = gr.Interface(\n",
|
371 |
+
" fn=predict_cancer,\n",
|
372 |
+
" inputs=input_images,\n",
|
373 |
+
" outputs=output_labels,\n",
|
374 |
+
" title=\"Breast Cancer Detection from Ultrasound Images\",\n",
|
375 |
+
" description=\"Upload multiple breast ultrasound images to get predictions on whether they show benign, malignant, or normal conditions.\"\n",
|
376 |
+
")\n",
|
377 |
+
"\n",
|
378 |
+
"# Launch the Gradio app\n",
|
379 |
+
"if __name__ == \"__main__\":\n",
|
380 |
+
" gr_interface.launch()\n"
|
381 |
+
],
|
382 |
+
"metadata": {
|
383 |
+
"colab": {
|
384 |
+
"base_uri": "https://localhost:8080/",
|
385 |
+
"height": 1000
|
386 |
+
},
|
387 |
+
"id": "14__binmQtHa",
|
388 |
+
"outputId": "f3e5b69d-c896-4a28-cc83-38f8c3463144"
|
389 |
+
},
|
390 |
+
"execution_count": 7,
|
391 |
+
"outputs": [
|
392 |
+
{
|
393 |
+
"output_type": "stream",
|
394 |
+
"name": "stdout",
|
395 |
+
"text": [
|
396 |
+
"Model: \"sequential\"\n",
|
397 |
+
"_________________________________________________________________\n",
|
398 |
+
" Layer (type) Output Shape Param # \n",
|
399 |
+
"=================================================================\n",
|
400 |
+
" conv2d (Conv2D) (None, 126, 126, 32) 320 \n",
|
401 |
+
" \n",
|
402 |
+
" max_pooling2d (MaxPooling2 (None, 63, 63, 32) 0 \n",
|
403 |
+
" D) \n",
|
404 |
+
" \n",
|
405 |
+
" conv2d_1 (Conv2D) (None, 61, 61, 64) 18496 \n",
|
406 |
+
" \n",
|
407 |
+
" max_pooling2d_1 (MaxPoolin (None, 30, 30, 64) 0 \n",
|
408 |
+
" g2D) \n",
|
409 |
+
" \n",
|
410 |
+
" conv2d_2 (Conv2D) (None, 28, 28, 128) 73856 \n",
|
411 |
+
" \n",
|
412 |
+
" max_pooling2d_2 (MaxPoolin (None, 14, 14, 128) 0 \n",
|
413 |
+
" g2D) \n",
|
414 |
+
" \n",
|
415 |
+
" flatten (Flatten) (None, 25088) 0 \n",
|
416 |
+
" \n",
|
417 |
+
" dense (Dense) (None, 128) 3211392 \n",
|
418 |
+
" \n",
|
419 |
+
" dropout (Dropout) (None, 128) 0 \n",
|
420 |
+
" \n",
|
421 |
+
" dense_1 (Dense) (None, 3) 387 \n",
|
422 |
+
" \n",
|
423 |
+
"=================================================================\n",
|
424 |
+
"Total params: 3304451 (12.61 MB)\n",
|
425 |
+
"Trainable params: 3304451 (12.61 MB)\n",
|
426 |
+
"Non-trainable params: 0 (0.00 Byte)\n",
|
427 |
+
"_________________________________________________________________\n",
|
428 |
+
"Epoch 1/25\n",
|
429 |
+
"40/40 [==============================] - 9s 64ms/step - loss: 0.9351 - accuracy: 0.5293 - val_loss: 0.7623 - val_accuracy: 0.6171\n",
|
430 |
+
"Epoch 2/25\n",
|
431 |
+
"40/40 [==============================] - 2s 49ms/step - loss: 0.7880 - accuracy: 0.6490 - val_loss: 0.6971 - val_accuracy: 0.7120\n",
|
432 |
+
"Epoch 3/25\n",
|
433 |
+
"40/40 [==============================] - 3s 63ms/step - loss: 0.7158 - accuracy: 0.6609 - val_loss: 0.6900 - val_accuracy: 0.7405\n",
|
434 |
+
"Epoch 4/25\n",
|
435 |
+
"40/40 [==============================] - 3s 74ms/step - loss: 0.6818 - accuracy: 0.6862 - val_loss: 0.6745 - val_accuracy: 0.7089\n",
|
436 |
+
"Epoch 5/25\n",
|
437 |
+
"40/40 [==============================] - 2s 49ms/step - loss: 0.6607 - accuracy: 0.6981 - val_loss: 0.6446 - val_accuracy: 0.7563\n",
|
438 |
+
"Epoch 6/25\n",
|
439 |
+
"40/40 [==============================] - 2s 48ms/step - loss: 0.6371 - accuracy: 0.7084 - val_loss: 0.6247 - val_accuracy: 0.7500\n",
|
440 |
+
"Epoch 7/25\n",
|
441 |
+
"40/40 [==============================] - 2s 49ms/step - loss: 0.5992 - accuracy: 0.7314 - val_loss: 0.6092 - val_accuracy: 0.7532\n",
|
442 |
+
"Epoch 8/25\n",
|
443 |
+
"40/40 [==============================] - 2s 48ms/step - loss: 0.5733 - accuracy: 0.7472 - val_loss: 0.5671 - val_accuracy: 0.7911\n",
|
444 |
+
"Epoch 9/25\n",
|
445 |
+
"40/40 [==============================] - 3s 68ms/step - loss: 0.5612 - accuracy: 0.7417 - val_loss: 0.5484 - val_accuracy: 0.7816\n",
|
446 |
+
"Epoch 10/25\n",
|
447 |
+
"40/40 [==============================] - 3s 71ms/step - loss: 0.5460 - accuracy: 0.7567 - val_loss: 0.5713 - val_accuracy: 0.7184\n",
|
448 |
+
"Epoch 11/25\n",
|
449 |
+
"40/40 [==============================] - 2s 48ms/step - loss: 0.5267 - accuracy: 0.7512 - val_loss: 0.5167 - val_accuracy: 0.8133\n",
|
450 |
+
"Epoch 12/25\n",
|
451 |
+
"40/40 [==============================] - 2s 50ms/step - loss: 0.4947 - accuracy: 0.7876 - val_loss: 0.5295 - val_accuracy: 0.7785\n",
|
452 |
+
"Epoch 13/25\n",
|
453 |
+
"40/40 [==============================] - 2s 49ms/step - loss: 0.4822 - accuracy: 0.7900 - val_loss: 0.4824 - val_accuracy: 0.7943\n",
|
454 |
+
"Epoch 14/25\n",
|
455 |
+
"40/40 [==============================] - 3s 65ms/step - loss: 0.4577 - accuracy: 0.8043 - val_loss: 0.5469 - val_accuracy: 0.7532\n",
|
456 |
+
"Epoch 15/25\n",
|
457 |
+
"40/40 [==============================] - 2s 49ms/step - loss: 0.4479 - accuracy: 0.8154 - val_loss: 0.4808 - val_accuracy: 0.8133\n",
|
458 |
+
"Epoch 16/25\n",
|
459 |
+
"40/40 [==============================] - 2s 49ms/step - loss: 0.4360 - accuracy: 0.8035 - val_loss: 0.6171 - val_accuracy: 0.7152\n",
|
460 |
+
"Epoch 17/25\n",
|
461 |
+
"40/40 [==============================] - 2s 47ms/step - loss: 0.4315 - accuracy: 0.8138 - val_loss: 0.6265 - val_accuracy: 0.7152\n",
|
462 |
+
"Epoch 18/25\n",
|
463 |
+
"40/40 [==============================] - 2s 48ms/step - loss: 0.4108 - accuracy: 0.8344 - val_loss: 0.6563 - val_accuracy: 0.7437\n",
|
464 |
+
"Epoch 19/25\n",
|
465 |
+
"40/40 [==============================] - 3s 76ms/step - loss: 0.4032 - accuracy: 0.8225 - val_loss: 0.4995 - val_accuracy: 0.7658\n",
|
466 |
+
"Epoch 20/25\n",
|
467 |
+
"40/40 [==============================] - 2s 48ms/step - loss: 0.3779 - accuracy: 0.8463 - val_loss: 0.4580 - val_accuracy: 0.8165\n",
|
468 |
+
"Epoch 21/25\n",
|
469 |
+
"40/40 [==============================] - 2s 47ms/step - loss: 0.3660 - accuracy: 0.8447 - val_loss: 0.4400 - val_accuracy: 0.8101\n",
|
470 |
+
"Epoch 22/25\n",
|
471 |
+
"40/40 [==============================] - 2s 48ms/step - loss: 0.3883 - accuracy: 0.8447 - val_loss: 0.4386 - val_accuracy: 0.8133\n",
|
472 |
+
"Epoch 23/25\n",
|
473 |
+
"40/40 [==============================] - 3s 71ms/step - loss: 0.3440 - accuracy: 0.8661 - val_loss: 0.4602 - val_accuracy: 0.8038\n",
|
474 |
+
"Epoch 24/25\n",
|
475 |
+
"40/40 [==============================] - 3s 66ms/step - loss: 0.3326 - accuracy: 0.8605 - val_loss: 0.4593 - val_accuracy: 0.7880\n",
|
476 |
+
"Epoch 25/25\n",
|
477 |
+
"40/40 [==============================] - 2s 48ms/step - loss: 0.3125 - accuracy: 0.8621 - val_loss: 0.4492 - val_accuracy: 0.8070\n"
|
478 |
+
]
|
479 |
+
},
|
480 |
+
{
|
481 |
+
"output_type": "stream",
|
482 |
+
"name": "stderr",
|
483 |
+
"text": [
|
484 |
+
"/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py:3103: UserWarning: You are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')`.\n",
|
485 |
+
" saving_api.save_model(\n"
|
486 |
+
]
|
487 |
+
},
|
488 |
+
{
|
489 |
+
"output_type": "error",
|
490 |
+
"ename": "TypeError",
|
491 |
+
"evalue": "Image.__init__() got an unexpected keyword argument 'tool'",
|
492 |
+
"traceback": [
|
493 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
494 |
+
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
495 |
+
"\u001b[0;32m<ipython-input-7-5cde0dc5990a>\u001b[0m in \u001b[0;36m<cell line: 115>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 114\u001b[0m \u001b[0;31m# Define Gradio interface\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 115\u001b[0;31m \u001b[0minput_images\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mImage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'numpy'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Upload Ultrasound Images'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtool\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'editor'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msource\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'upload'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshape\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mIMG_SIZE\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mIMG_SIZE\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 116\u001b[0m \u001b[0moutput_labels\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTextbox\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Predictions'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 117\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
496 |
+
"\u001b[0;32m/usr/local/lib/python3.10/dist-packages/gradio/component_meta.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 161\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 163\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 164\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 165\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
497 |
+
"\u001b[0;31mTypeError\u001b[0m: Image.__init__() got an unexpected keyword argument 'tool'"
|
498 |
+
]
|
499 |
+
}
|
500 |
+
]
|
501 |
+
},
|
502 |
+
{
|
503 |
+
"cell_type": "code",
|
504 |
+
"source": [
|
505 |
+
"# # Save the model\n",
|
506 |
+
"# model.save('breast_cancer_detection_model2.h5')"
|
507 |
+
],
|
508 |
+
"metadata": {
|
509 |
+
"id": "fBLBREI_UHr-"
|
510 |
+
},
|
511 |
+
"execution_count": 13,
|
512 |
+
"outputs": []
|
513 |
+
},
|
514 |
+
{
|
515 |
+
"cell_type": "code",
|
516 |
+
"source": [
|
517 |
+
"!pip install gradio tensorflow opencv-python-headless\n"
|
518 |
+
],
|
519 |
+
"metadata": {
|
520 |
+
"colab": {
|
521 |
+
"base_uri": "https://localhost:8080/"
|
522 |
+
},
|
523 |
+
"id": "9tkj3oGeUUyd",
|
524 |
+
"outputId": "f3a7a087-06d1-4179-9ff8-feea038d6a15"
|
525 |
+
},
|
526 |
+
"execution_count": 15,
|
527 |
+
"outputs": [
|
528 |
+
{
|
529 |
+
"output_type": "stream",
|
530 |
+
"name": "stdout",
|
531 |
+
"text": [
|
532 |
+
"Requirement already satisfied: gradio in /usr/local/lib/python3.10/dist-packages (4.37.2)\n",
|
533 |
+
"Requirement already satisfied: tensorflow in /usr/local/lib/python3.10/dist-packages (2.15.0)\n",
|
534 |
+
"Requirement already satisfied: opencv-python-headless in /usr/local/lib/python3.10/dist-packages (4.10.0.84)\n",
|
535 |
+
"Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2.1)\n",
|
536 |
+
"Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.2.2)\n",
|
537 |
+
"Requirement already satisfied: fastapi in /usr/local/lib/python3.10/dist-packages (from gradio) (0.111.0)\n",
|
538 |
+
"Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio) (0.3.2)\n",
|
539 |
+
"Requirement already satisfied: gradio-client==1.0.2 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.0.2)\n",
|
540 |
+
"Requirement already satisfied: httpx>=0.24.1 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.27.0)\n",
|
541 |
+
"Requirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.23.4)\n",
|
542 |
+
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.4.0)\n",
|
543 |
+
"Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.4)\n",
|
544 |
+
"Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.5)\n",
|
545 |
+
"Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n",
|
546 |
+
"Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.25.2)\n",
|
547 |
+
"Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.10.6)\n",
|
548 |
+
"Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (24.1)\n",
|
549 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.3)\n",
|
550 |
+
"Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.4.0)\n",
|
551 |
+
"Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.7.4)\n",
|
552 |
+
"Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.1)\n",
|
553 |
+
"Requirement already satisfied: python-multipart>=0.0.9 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.0.9)\n",
|
554 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n",
|
555 |
+
"Requirement already satisfied: ruff>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.5.0)\n",
|
556 |
+
"Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.10.0)\n",
|
557 |
+
"Requirement already satisfied: tomlkit==0.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.0)\n",
|
558 |
+
"Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.3)\n",
|
559 |
+
"Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.12.2)\n",
|
560 |
+
"Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.0.7)\n",
|
561 |
+
"Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.30.1)\n",
|
562 |
+
"Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.0.2->gradio) (2023.6.0)\n",
|
563 |
+
"Requirement already satisfied: websockets<12.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio-client==1.0.2->gradio) (11.0.3)\n",
|
564 |
+
"Requirement already satisfied: absl-py>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (1.4.0)\n",
|
565 |
+
"Requirement already satisfied: astunparse>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (1.6.3)\n",
|
566 |
+
"Requirement already satisfied: flatbuffers>=23.5.26 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (24.3.25)\n",
|
567 |
+
"Requirement already satisfied: gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (0.6.0)\n",
|
568 |
+
"Requirement already satisfied: google-pasta>=0.1.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (0.2.0)\n",
|
569 |
+
"Requirement already satisfied: h5py>=2.9.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (3.9.0)\n",
|
570 |
+
"Requirement already satisfied: libclang>=13.0.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (18.1.1)\n",
|
571 |
+
"Requirement already satisfied: ml-dtypes~=0.2.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (0.2.0)\n",
|
572 |
+
"Requirement already satisfied: opt-einsum>=2.3.2 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (3.3.0)\n",
|
573 |
+
"Requirement already satisfied: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (3.20.3)\n",
|
574 |
+
"Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from tensorflow) (67.7.2)\n",
|
575 |
+
"Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (1.16.0)\n",
|
576 |
+
"Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (2.4.0)\n",
|
577 |
+
"Requirement already satisfied: wrapt<1.15,>=1.11.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (1.14.1)\n",
|
578 |
+
"Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (0.37.0)\n",
|
579 |
+
"Requirement already satisfied: grpcio<2.0,>=1.24.3 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (1.64.1)\n",
|
580 |
+
"Requirement already satisfied: tensorboard<2.16,>=2.15 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (2.15.2)\n",
|
581 |
+
"Requirement already satisfied: tensorflow-estimator<2.16,>=2.15.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (2.15.0)\n",
|
582 |
+
"Requirement already satisfied: keras<2.16,>=2.15.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow) (2.15.0)\n",
|
583 |
+
"Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.4)\n",
|
584 |
+
"Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (4.19.2)\n",
|
585 |
+
"Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.12.1)\n",
|
586 |
+
"Requirement already satisfied: wheel<1.0,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from astunparse>=1.6.0->tensorflow) (0.43.0)\n",
|
587 |
+
"Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (3.7.1)\n",
|
588 |
+
"Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (2024.6.2)\n",
|
589 |
+
"Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (1.0.5)\n",
|
590 |
+
"Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (3.7)\n",
|
591 |
+
"Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio) (1.3.1)\n",
|
592 |
+
"Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.10/dist-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n",
|
593 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (3.15.4)\n",
|
594 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
|
595 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (4.66.4)\n",
|
596 |
+
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.2.1)\n",
|
597 |
+
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
|
598 |
+
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.53.0)\n",
|
599 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
|
600 |
+
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.2)\n",
|
601 |
+
"Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
|
602 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2023.4)\n",
|
603 |
+
"Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
|
604 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (0.7.0)\n",
|
605 |
+
"Requirement already satisfied: pydantic-core==2.18.4 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.18.4)\n",
|
606 |
+
"Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow) (2.27.0)\n",
|
607 |
+
"Requirement already satisfied: google-auth-oauthlib<2,>=0.5 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow) (1.2.0)\n",
|
608 |
+
"Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow) (3.6)\n",
|
609 |
+
"Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow) (0.7.2)\n",
|
610 |
+
"Requirement already satisfied: werkzeug>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.16,>=2.15->tensorflow) (3.0.3)\n",
|
611 |
+
"Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n",
|
612 |
+
"Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
|
613 |
+
"Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n",
|
614 |
+
"Requirement already satisfied: starlette<0.38.0,>=0.37.2 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (0.37.2)\n",
|
615 |
+
"Requirement already satisfied: fastapi-cli>=0.0.2 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (0.0.4)\n",
|
616 |
+
"Requirement already satisfied: ujson!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,>=4.0.1 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (5.10.0)\n",
|
617 |
+
"Requirement already satisfied: email_validator>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (2.2.0)\n",
|
618 |
+
"Requirement already satisfied: dnspython>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from email_validator>=2.0.0->fastapi->gradio) (2.6.1)\n",
|
619 |
+
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow) (5.3.3)\n",
|
620 |
+
"Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow) (0.4.0)\n",
|
621 |
+
"Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow) (4.9)\n",
|
622 |
+
"Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from google-auth-oauthlib<2,>=0.5->tensorboard<2.16,>=2.15->tensorflow) (1.3.1)\n",
|
623 |
+
"Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n",
|
624 |
+
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n",
|
625 |
+
"Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.35.1)\n",
|
626 |
+
"Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.18.1)\n",
|
627 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
|
628 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
|
629 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.16.1)\n",
|
630 |
+
"Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx>=0.24.1->gradio) (1.2.1)\n",
|
631 |
+
"Requirement already satisfied: httptools>=0.5.0 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.6.1)\n",
|
632 |
+
"Requirement already satisfied: python-dotenv>=0.13 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (1.0.1)\n",
|
633 |
+
"Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.19.0)\n",
|
634 |
+
"Requirement already satisfied: watchfiles>=0.13 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.22.0)\n",
|
635 |
+
"Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
|
636 |
+
"Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.16,>=2.15->tensorflow) (0.6.0)\n",
|
637 |
+
"Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<2,>=0.5->tensorboard<2.16,>=2.15->tensorflow) (3.2.2)\n"
|
638 |
+
]
|
639 |
+
}
|
640 |
+
]
|
641 |
+
},
|
642 |
+
{
|
643 |
+
"cell_type": "code",
|
644 |
+
"source": [
|
645 |
+
"# Define the prediction function\n",
|
646 |
+
"def predict_cancer(images):\n",
|
647 |
+
" results = []\n",
|
648 |
+
" for img in images:\n",
|
649 |
+
" # Convert image to grayscale (if it's not already), resize, and normalize\n",
|
650 |
+
" img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) # Resize to match model input\n",
|
651 |
+
" img = np.expand_dims(img, axis=-1) # Add channel dimension\n",
|
652 |
+
" img = img / 255.0 # Normalize\n",
|
653 |
+
" img = np.expand_dims(img, axis=0) # Add batch dimension\n",
|
654 |
+
"\n",
|
655 |
+
" # Make prediction\n",
|
656 |
+
" prediction = model.predict(img)\n",
|
657 |
+
" class_idx = np.argmax(prediction[0])\n",
|
658 |
+
" class_name = class_names[class_idx]\n",
|
659 |
+
" probability = np.max(prediction[0])\n",
|
660 |
+
" results.append(f\"{class_name} (Probability: {probability:.2f})\")\n",
|
661 |
+
"\n",
|
662 |
+
" return results\n",
|
663 |
+
"\n",
|
664 |
+
"# Define Gradio interface\n",
|
665 |
+
"def classify_images(images):\n",
|
666 |
+
" return predict_cancer(images)\n",
|
667 |
+
"\n",
|
668 |
+
"# # Update Gradio interface configuration\n",
|
669 |
+
"# input_images = gr.Image(type='numpy', label='Upload Ultrasound Images', source='upload', tool=None) # Removed `tool` argument and added `source='upload'`\n",
|
670 |
+
"# output_labels = gr.Textbox(label='Predictions')\n",
|
671 |
+
"\n",
|
672 |
+
"# Define Gradio interface\n",
|
673 |
+
"input_images = gr.Image(type='numpy', label='Upload Ultrasound Images')\n",
|
674 |
+
"output_labels = gr.Textbox(label='Predictions')\n",
|
675 |
+
"\n",
|
676 |
+
"gr_interface = gr.Interface(\n",
|
677 |
+
" fn=classify_images,\n",
|
678 |
+
" inputs=input_images,\n",
|
679 |
+
" outputs=output_labels,\n",
|
680 |
+
" title=\"Breast Cancer Detection from Ultrasound Images\",\n",
|
681 |
+
" description=\"Upload multiple breast ultrasound images to get predictions on whether they show benign, malignant, or normal conditions.\"\n",
|
682 |
+
")\n",
|
683 |
+
"\n",
|
684 |
+
"# Launch the Gradio app\n",
|
685 |
+
"if __name__ == \"__main__\":\n",
|
686 |
+
" gr_interface.launch()"
|
687 |
+
],
|
688 |
+
"metadata": {
|
689 |
+
"colab": {
|
690 |
+
"base_uri": "https://localhost:8080/",
|
691 |
+
"height": 646
|
692 |
+
},
|
693 |
+
"id": "u965ysX0UkCB",
|
694 |
+
"outputId": "e83b327a-1078-49cb-9583-e112dbab6f09"
|
695 |
+
},
|
696 |
+
"execution_count": 8,
|
697 |
+
"outputs": [
|
698 |
+
{
|
699 |
+
"output_type": "stream",
|
700 |
+
"name": "stdout",
|
701 |
+
"text": [
|
702 |
+
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
703 |
+
"\n",
|
704 |
+
"Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
|
705 |
+
"Running on public URL: https://fd6a25a058bd67fbe1.gradio.live\n",
|
706 |
+
"\n",
|
707 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
708 |
+
]
|
709 |
+
},
|
710 |
+
{
|
711 |
+
"output_type": "display_data",
|
712 |
+
"data": {
|
713 |
+
"text/plain": [
|
714 |
+
"<IPython.core.display.HTML object>"
|
715 |
+
],
|
716 |
+
"text/html": [
|
717 |
+
"<div><iframe src=\"https://fd6a25a058bd67fbe1.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
718 |
+
]
|
719 |
+
},
|
720 |
+
"metadata": {}
|
721 |
+
}
|
722 |
+
]
|
723 |
+
},
|
724 |
+
{
|
725 |
+
"cell_type": "code",
|
726 |
+
"source": [
|
727 |
+
"import gradio as gr\n",
|
728 |
+
"import numpy as np\n",
|
729 |
+
"import cv2 # Ensure you have opencv-python installed\n",
|
730 |
+
"from tensorflow.keras.models import load_model # Ensure you have TensorFlow installed\n",
|
731 |
+
"\n",
|
732 |
+
"# Load your trained model\n",
|
733 |
+
"model = load_model('/content/breast_cancer_detection_model3.h5') # Update this path to your actual model file\n",
|
734 |
+
"\n",
|
735 |
+
"# Define class names according to your model\n",
|
736 |
+
"class_names = ['benign', 'malignant', 'normal'] # Update this list if different\n",
|
737 |
+
"\n",
|
738 |
+
"# Define the prediction function\n",
|
739 |
+
"def predict_cancer(images):\n",
|
740 |
+
" results = []\n",
|
741 |
+
" for img in images:\n",
|
742 |
+
" # Convert image to grayscale (if it's not already), resize, and normalize\n",
|
743 |
+
" img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) # Convert to grayscale if not already\n",
|
744 |
+
" img = cv2.resize(img, (IMG_SIZE, IMG_SIZE)) # Resize to match model input\n",
|
745 |
+
" img = np.expand_dims(img, axis=-1) # Add channel dimension\n",
|
746 |
+
" img = img / 255.0 # Normalize\n",
|
747 |
+
" img = np.expand_dims(img, axis=0) # Add batch dimension\n",
|
748 |
+
"\n",
|
749 |
+
" # Make prediction\n",
|
750 |
+
" prediction = model.predict(img)\n",
|
751 |
+
" class_idx = np.argmax(prediction[0])\n",
|
752 |
+
" class_name = class_names[class_idx]\n",
|
753 |
+
" probability = np.max(prediction[0])\n",
|
754 |
+
" results.append(f\"{class_name} (Probability: {probability:.2f})\")\n",
|
755 |
+
"\n",
|
756 |
+
" return results\n",
|
757 |
+
"\n",
|
758 |
+
"# Define Gradio interface\n",
|
759 |
+
"def classify_images(images):\n",
|
760 |
+
" if not isinstance(images, list): # Ensure `images` is a list of images\n",
|
761 |
+
" images = [images]\n",
|
762 |
+
" return predict_cancer(images)\n",
|
763 |
+
"\n",
|
764 |
+
"# Define the Gradio interface\n",
|
765 |
+
"input_images = gr.Image(type='numpy', label='Upload Ultrasound Images')\n",
|
766 |
+
"output_labels = gr.Textbox(label='Predictions')\n",
|
767 |
+
"\n",
|
768 |
+
"gr_interface = gr.Interface(\n",
|
769 |
+
" fn=classify_images,\n",
|
770 |
+
" inputs=input_images,\n",
|
771 |
+
" outputs=output_labels,\n",
|
772 |
+
" title=\"Breast Cancer Detection from Ultrasound Images\",\n",
|
773 |
+
" description=\"Upload multiple breast ultrasound images to get predictions on whether they show benign, malignant, or normal conditions.\"\n",
|
774 |
+
")\n",
|
775 |
+
"\n",
|
776 |
+
"# Launch the Gradio app\n",
|
777 |
+
"if __name__ == \"__main__\":\n",
|
778 |
+
" gr_interface.launch()\n"
|
779 |
+
],
|
780 |
+
"metadata": {
|
781 |
+
"colab": {
|
782 |
+
"base_uri": "https://localhost:8080/",
|
783 |
+
"height": 646
|
784 |
+
},
|
785 |
+
"id": "uZYTW1LPW3pg",
|
786 |
+
"outputId": "107a6939-64f1-4e3c-cc13-e3af7d7c80c1"
|
787 |
+
},
|
788 |
+
"execution_count": 9,
|
789 |
+
"outputs": [
|
790 |
+
{
|
791 |
+
"output_type": "stream",
|
792 |
+
"name": "stdout",
|
793 |
+
"text": [
|
794 |
+
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
795 |
+
"\n",
|
796 |
+
"Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
|
797 |
+
"Running on public URL: https://134538bfc74bbc1b4e.gradio.live\n",
|
798 |
+
"\n",
|
799 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
800 |
+
]
|
801 |
+
},
|
802 |
+
{
|
803 |
+
"output_type": "display_data",
|
804 |
+
"data": {
|
805 |
+
"text/plain": [
|
806 |
+
"<IPython.core.display.HTML object>"
|
807 |
+
],
|
808 |
+
"text/html": [
|
809 |
+
"<div><iframe src=\"https://134538bfc74bbc1b4e.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
810 |
+
]
|
811 |
+
},
|
812 |
+
"metadata": {}
|
813 |
+
}
|
814 |
+
]
|
815 |
+
},
|
816 |
+
{
|
817 |
+
"cell_type": "code",
|
818 |
+
"source": [],
|
819 |
+
"metadata": {
|
820 |
+
"id": "C7XW8IqPVwzj"
|
821 |
+
},
|
822 |
+
"execution_count": null,
|
823 |
+
"outputs": []
|
824 |
+
}
|
825 |
+
]
|
826 |
+
}
|
requirements.txt.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio
|