Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ import pandas as pd
|
|
11 |
from PIL import Image
|
12 |
import plotly.express as px
|
13 |
import time
|
|
|
|
|
|
|
14 |
|
15 |
theme = gr.themes.Soft(
|
16 |
primary_hue="purple",
|
@@ -156,35 +159,38 @@ def _update_progress(progress, value, desc=""):
|
|
156 |
# ---- PREDICT SINGLE ----
|
157 |
from tensorflow.keras.preprocessing import image
|
158 |
|
|
|
|
|
|
|
159 |
def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
160 |
print("🔍 DEBUG GRADIO - Début de la prédiction")
|
161 |
|
162 |
# Chargement et pré-traitement avec Keras (comme en local)
|
163 |
if isinstance(img_input, str):
|
164 |
# Chargement depuis un chemin
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
168 |
else:
|
169 |
-
# Cas d'upload via interface Gradio (img_input est
|
170 |
-
# Conversion en array puis rechargement avec Keras pour uniformiser
|
171 |
temp_path = "temp_debug_image.jpg"
|
172 |
-
img_input.save(temp_path)
|
173 |
-
img_raw_x = image.load_img(temp_path, target_size=(299, 299)
|
174 |
-
img_raw_r = image.load_img(temp_path, target_size=(224, 224)
|
175 |
-
img_raw_d = image.load_img(temp_path, target_size=(224, 224)
|
176 |
import os
|
177 |
-
os.remove(temp_path)
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
print(f"📸 Images loaded:")
|
180 |
-
print(f" Xception (299x299): {
|
181 |
-
print(f" ResNet (224x224): {
|
182 |
-
print(f" DenseNet (224x224): {
|
183 |
-
|
184 |
-
# Conversion en arrays
|
185 |
-
array_x = image.img_to_array(img_raw_x)
|
186 |
-
array_r = image.img_to_array(img_raw_r)
|
187 |
-
array_d = image.img_to_array(img_raw_d)
|
188 |
|
189 |
print(f"🔧 Arrays avant preprocessing:")
|
190 |
print(f" X shape: {array_x.shape}, dtype: {array_x.dtype}, range: [{array_x.min()}, {array_x.max()}]")
|
|
|
11 |
from PIL import Image
|
12 |
import plotly.express as px
|
13 |
import time
|
14 |
+
import os
|
15 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
16 |
+
|
17 |
|
18 |
theme = gr.themes.Soft(
|
19 |
primary_hue="purple",
|
|
|
159 |
# ---- PREDICT SINGLE ----
|
160 |
from tensorflow.keras.preprocessing import image
|
161 |
|
162 |
+
from tensorflow.keras.preprocessing import image
|
163 |
+
import numpy as np
|
164 |
+
|
165 |
def predict_single(img_input, weights=(0.45, 0.25, 0.3), normalize=True):
|
166 |
print("🔍 DEBUG GRADIO - Début de la prédiction")
|
167 |
|
168 |
# Chargement et pré-traitement avec Keras (comme en local)
|
169 |
if isinstance(img_input, str):
|
170 |
# Chargement depuis un chemin
|
171 |
+
img_path = img_input
|
172 |
+
img_raw_x = image.load_img(img_path, target_size=(299, 299))
|
173 |
+
img_raw_r = image.load_img(img_path, target_size=(224, 224))
|
174 |
+
img_raw_d = image.load_img(img_path, target_size=(224, 224))
|
175 |
else:
|
176 |
+
# Cas d'upload via interface Gradio (img_input est une image PIL)
|
|
|
177 |
temp_path = "temp_debug_image.jpg"
|
178 |
+
img_input.save(temp_path)
|
179 |
+
img_raw_x = image.load_img(temp_path, target_size=(299, 299))
|
180 |
+
img_raw_r = image.load_img(temp_path, target_size=(224, 224))
|
181 |
+
img_raw_d = image.load_img(temp_path, target_size=(224, 224))
|
182 |
import os
|
183 |
+
os.remove(temp_path)
|
184 |
+
|
185 |
+
# Conversion en arrays avec le même type de données que local (float32)
|
186 |
+
array_x = image.img_to_array(img_raw_x).astype(np.float32)
|
187 |
+
array_r = image.img_to_array(img_raw_r).astype(np.float32)
|
188 |
+
array_d = image.img_to_array(img_raw_d).astype(np.float32)
|
189 |
|
190 |
print(f"📸 Images loaded:")
|
191 |
+
print(f" Xception (299x299): {array_x.shape}")
|
192 |
+
print(f" ResNet (224x224): {array_r.shape}")
|
193 |
+
print(f" DenseNet (224x224): {array_d.shape}")
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
print(f"🔧 Arrays avant preprocessing:")
|
196 |
print(f" X shape: {array_x.shape}, dtype: {array_x.dtype}, range: [{array_x.min()}, {array_x.max()}]")
|