Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
-
import cv2
|
5 |
from huggingface_hub import hf_hub_download
|
|
|
6 |
|
7 |
# Descargar modelo desde Hugging Face
|
8 |
model_path = hf_hub_download(repo_id="Bmo411/DenoisingAutoencoder", filename="autoencoder_complete_model_Fourier.keras")
|
|
|
9 |
|
10 |
from tensorflow.keras.saving import register_keras_serializable
|
11 |
|
@@ -65,15 +67,28 @@ def Denoiser(imagen):
|
|
65 |
# Expandir dimensiones para que tenga el formato correcto para el modelo (batch_size, h, w, c)
|
66 |
noisy_image_input = np.expand_dims(noisy_image, axis=0)
|
67 |
|
|
|
|
|
|
|
68 |
# Predecir con el autoencoder
|
69 |
reconstructed = model.predict(noisy_image_input)[0] # Quitar batch_size
|
70 |
|
|
|
|
|
|
|
71 |
# Asegurarse de que la imagen restaurada est茅 en el rango [0, 255] para la visualizaci贸n
|
72 |
noisy_image = np.uint8(noisy_image * 255)
|
73 |
reconstructed = np.uint8(reconstructed * 255)
|
74 |
|
75 |
return noisy_image, reconstructed
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Crear interfaz en Gradio con dos salidas de imagen
|
78 |
demo = gr.Interface(
|
79 |
fn=Denoiser,
|
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
import numpy as np
|
4 |
+
import cv2
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
+
import time
|
7 |
|
8 |
# Descargar modelo desde Hugging Face
|
9 |
model_path = hf_hub_download(repo_id="Bmo411/DenoisingAutoencoder", filename="autoencoder_complete_model_Fourier.keras")
|
10 |
+
model = tf.keras.models.load_model(model_path)
|
11 |
|
12 |
from tensorflow.keras.saving import register_keras_serializable
|
13 |
|
|
|
67 |
# Expandir dimensiones para que tenga el formato correcto para el modelo (batch_size, h, w, c)
|
68 |
noisy_image_input = np.expand_dims(noisy_image, axis=0)
|
69 |
|
70 |
+
# Medir el tiempo de la predicci贸n
|
71 |
+
start_time = time.time()
|
72 |
+
|
73 |
# Predecir con el autoencoder
|
74 |
reconstructed = model.predict(noisy_image_input)[0] # Quitar batch_size
|
75 |
|
76 |
+
prediction_time = time.time() - start_time
|
77 |
+
print(f"Tiempo de predicci贸n: {prediction_time} segundos")
|
78 |
+
|
79 |
# Asegurarse de que la imagen restaurada est茅 en el rango [0, 255] para la visualizaci贸n
|
80 |
noisy_image = np.uint8(noisy_image * 255)
|
81 |
reconstructed = np.uint8(reconstructed * 255)
|
82 |
|
83 |
return noisy_image, reconstructed
|
84 |
|
85 |
+
# Verificar si TensorFlow est谩 utilizando la GPU
|
86 |
+
physical_devices = tf.config.list_physical_devices('GPU')
|
87 |
+
if physical_devices:
|
88 |
+
print("TensorFlow est谩 utilizando la GPU")
|
89 |
+
else:
|
90 |
+
print("TensorFlow no est谩 utilizando la GPU")
|
91 |
+
|
92 |
# Crear interfaz en Gradio con dos salidas de imagen
|
93 |
demo = gr.Interface(
|
94 |
fn=Denoiser,
|