LewisBabong commited on
Commit
0ba33fd
ยท
verified ยท
1 Parent(s): e837b9b

Upload 3 files

Browse files
NTONGA_Babongs_FRANCOIS_TENSORFLOW_SN.ipynb ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stderr",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "2025-02-21 19:54:44.189059: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
13
+ "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "import os\n",
19
+ "import numpy as np\n",
20
+ "import tensorflow as tf\n",
21
+ "from tensorflow import keras\n",
22
+ "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
23
+ "from tensorflow.keras.applications import ResNet50\n",
24
+ "from tensorflow.keras.layers import Dense, GlobalAveragePooling2D\n",
25
+ "from tensorflow.keras.models import Model\n",
26
+ "from tensorflow.keras.optimizers import Adam"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": null,
32
+ "metadata": {},
33
+ "outputs": [],
34
+ "source": [
35
+ "# Dรฉfinition des chemins des images et des labels\n",
36
+ "data_dir = \"kidney_disease_classification/CT-KIDNEY-DATASET-Normal-Cyst-Tumor-Stone/CT-KIDNEY-DATASET-Normal-Cyst-Tumor-Stone\"\n",
37
+ "img_size = (224, 224)\n",
38
+ "batch_size = 32"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": 19,
44
+ "metadata": {},
45
+ "outputs": [
46
+ {
47
+ "name": "stdout",
48
+ "output_type": "stream",
49
+ "text": [
50
+ "Found 9959 images belonging to 4 classes.\n",
51
+ "Found 2487 images belonging to 4 classes.\n"
52
+ ]
53
+ }
54
+ ],
55
+ "source": [
56
+ "# Prรฉtraitement des images avec ImageDataGenerator\n",
57
+ "datagen = ImageDataGenerator(\n",
58
+ " rescale=1./255,\n",
59
+ " validation_split=0.2\n",
60
+ ")\n",
61
+ "\n",
62
+ "train_generator = datagen.flow_from_directory(\n",
63
+ " data_dir,\n",
64
+ " target_size=img_size,\n",
65
+ " batch_size=batch_size,\n",
66
+ " class_mode='categorical',\n",
67
+ " subset='training'\n",
68
+ ")\n",
69
+ "\n",
70
+ "val_generator = datagen.flow_from_directory(\n",
71
+ " data_dir,\n",
72
+ " target_size=img_size,\n",
73
+ " batch_size=batch_size,\n",
74
+ " class_mode='categorical',\n",
75
+ " subset='validation'\n",
76
+ ")"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 21,
82
+ "metadata": {},
83
+ "outputs": [],
84
+ "source": [
85
+ "# Chargement du modรจle ResNet50 en transfer learning\n",
86
+ "base_model = ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))\n",
87
+ "base_model.trainable = False"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 22,
93
+ "metadata": {},
94
+ "outputs": [],
95
+ "source": [
96
+ "# Ajout des couches de classification\n",
97
+ "x = GlobalAveragePooling2D()(base_model.output)\n",
98
+ "x = Dense(128, activation='relu')(x)\n",
99
+ "x = Dense(4, activation='softmax')(x)\n",
100
+ "\n",
101
+ "model = Model(inputs=base_model.input, outputs=x)"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": 23,
107
+ "metadata": {},
108
+ "outputs": [],
109
+ "source": [
110
+ "# Compilation du modรจle\n",
111
+ "model.compile(optimizer=Adam(learning_rate=0.001), loss='categorical_crossentropy', metrics=['accuracy'])"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": 24,
117
+ "metadata": {},
118
+ "outputs": [
119
+ {
120
+ "name": "stderr",
121
+ "output_type": "stream",
122
+ "text": [
123
+ "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/keras/src/trainers/data_adapters/py_dataset_adapter.py:121: UserWarning: Your `PyDataset` class should call `super().__init__(**kwargs)` in its constructor. `**kwargs` can include `workers`, `use_multiprocessing`, `max_queue_size`. Do not pass these arguments to `fit()`, as they will be ignored.\n",
124
+ " self._warn_if_super_not_called()\n"
125
+ ]
126
+ },
127
+ {
128
+ "name": "stdout",
129
+ "output_type": "stream",
130
+ "text": [
131
+ "Epoch 1/10\n",
132
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1701s\u001b[0m 5s/step - accuracy: 0.5352 - loss: 1.1548 - val_accuracy: 0.5665 - val_loss: 1.1305\n",
133
+ "Epoch 2/10\n",
134
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1719s\u001b[0m 6s/step - accuracy: 0.7341 - loss: 0.7263 - val_accuracy: 0.5794 - val_loss: 1.0655\n",
135
+ "Epoch 3/10\n",
136
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1640s\u001b[0m 5s/step - accuracy: 0.7898 - loss: 0.5801 - val_accuracy: 0.5726 - val_loss: 1.0368\n",
137
+ "Epoch 4/10\n",
138
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1649s\u001b[0m 5s/step - accuracy: 0.8287 - loss: 0.4765 - val_accuracy: 0.6064 - val_loss: 1.0409\n",
139
+ "Epoch 5/10\n",
140
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1581s\u001b[0m 5s/step - accuracy: 0.8593 - loss: 0.4083 - val_accuracy: 0.6164 - val_loss: 1.1470\n",
141
+ "Epoch 6/10\n",
142
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1518s\u001b[0m 5s/step - accuracy: 0.8684 - loss: 0.3721 - val_accuracy: 0.6228 - val_loss: 1.1132\n",
143
+ "Epoch 7/10\n",
144
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1501s\u001b[0m 5s/step - accuracy: 0.8858 - loss: 0.3224 - val_accuracy: 0.6409 - val_loss: 1.1094\n",
145
+ "Epoch 8/10\n",
146
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1378s\u001b[0m 4s/step - accuracy: 0.8951 - loss: 0.3011 - val_accuracy: 0.6530 - val_loss: 1.0900\n",
147
+ "Epoch 9/10\n",
148
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1372s\u001b[0m 4s/step - accuracy: 0.9095 - loss: 0.2659 - val_accuracy: 0.5682 - val_loss: 1.1625\n",
149
+ "Epoch 10/10\n",
150
+ "\u001b[1m312/312\u001b[0m \u001b[32mโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”\u001b[0m\u001b[37m\u001b[0m \u001b[1m1511s\u001b[0m 5s/step - accuracy: 0.9062 - loss: 0.2695 - val_accuracy: 0.6421 - val_loss: 1.1116\n"
151
+ ]
152
+ }
153
+ ],
154
+ "source": [
155
+ "# Entraรฎnement du modรจle\n",
156
+ "epochs = 10\n",
157
+ "history = model.fit(train_generator, validation_data=val_generator, epochs=epochs)"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": 25,
163
+ "metadata": {},
164
+ "outputs": [
165
+ {
166
+ "name": "stderr",
167
+ "output_type": "stream",
168
+ "text": [
169
+ "WARNING:absl:You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')` or `keras.saving.save_model(model, 'my_model.keras')`. \n"
170
+ ]
171
+ }
172
+ ],
173
+ "source": [
174
+ "# Sauvegarde du modรจle\n",
175
+ "model.save(\"babong_kidney_classification_model.h5\")"
176
+ ]
177
+ }
178
+ ],
179
+ "metadata": {
180
+ "kernelspec": {
181
+ "display_name": "Python 3",
182
+ "language": "python",
183
+ "name": "python3"
184
+ },
185
+ "language_info": {
186
+ "codemirror_mode": {
187
+ "name": "ipython",
188
+ "version": 3
189
+ },
190
+ "file_extension": ".py",
191
+ "mimetype": "text/x-python",
192
+ "name": "python",
193
+ "nbconvert_exporter": "python",
194
+ "pygments_lexer": "ipython3",
195
+ "version": "3.12.0"
196
+ }
197
+ },
198
+ "nbformat": 4,
199
+ "nbformat_minor": 2
200
+ }
babong_kidney_classification_model_Tensorflow.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83abc190c0c408c628859450b487144ead51bf7d5bfbd97e781ea9e9073df518
3
+ size 98095240
resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:66c8b43daff3fcc15bc4f30e3d2a167e21a14d9c9598a5394e5516471f4af504
3
+ size 94765736