GFBO commited on
Commit
af73634
·
verified ·
1 Parent(s): 889e51f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -13
README.md CHANGED
@@ -46,31 +46,27 @@ from skimage.util import random_noise
46
  import numpy as np
47
  import matplotlib.pyplot as plt
48
 
49
- # Load the model from Hugging Face
50
  model_path = hf_hub_download(repo_id="BueormLLC/AID_small", filename="model.h5")
51
- autoencoder = tf.keras.models.load_model(model_path)
52
 
53
- # Function to add noise
 
54
  def add_noise(img, noise_type="gaussian"):
 
55
  if noise_type == "gaussian":
56
- noisy_img = random_noise(img, mode='gaussian', var=0.1)
57
  elif noise_type == "salt_pepper":
58
- noisy_img = random_noise(img, mode='s&p', amount=0.1)
59
  return np.clip(noisy_img, 0., 1.)
60
 
61
- # Example: Load an image, add noise, and denoise
62
  def predict_denoised_image(autoencoder, image):
63
- # Preprocess image (resize to 256x256, normalize to [0, 1])
64
  img_resized = tf.image.resize(image, (256, 256)) / 255.0
65
  img_array = np.expand_dims(img_resized, axis=0)
66
 
67
- # Add noise
68
  noisy_image = add_noise(img_resized)
69
 
70
- # Denoise the image
71
  denoised_image = autoencoder.predict(np.expand_dims(noisy_image, axis=0))
72
 
73
- # Plot results
74
  fig, ax = plt.subplots(1, 2, figsize=(10, 5))
75
  ax[0].imshow(noisy_image)
76
  ax[0].set_title("Noisy Image")
@@ -82,11 +78,9 @@ def predict_denoised_image(autoencoder, image):
82
 
83
  plt.show()
84
 
85
- # Load a test image (replace with your own image)
86
- test_image = tf.keras.preprocessing.image.load_img('your_image.jpg', target_size=(256, 256))
87
  test_image = tf.keras.preprocessing.image.img_to_array(test_image)
88
 
89
- # Run denoising prediction
90
  predict_denoised_image(autoencoder, test_image)
91
  ```
92
 
 
46
  import numpy as np
47
  import matplotlib.pyplot as plt
48
 
 
49
  model_path = hf_hub_download(repo_id="BueormLLC/AID_small", filename="model.h5")
 
50
 
51
+ autoencoder = tf.keras.models.load_model(model_path, custom_objects={'mse': tf.keras.losses.MeanSquaredError()})
52
+
53
  def add_noise(img, noise_type="gaussian"):
54
+ img_np = img.numpy() # Convertir el tensor a un arreglo NumPy
55
  if noise_type == "gaussian":
56
+ noisy_img = random_noise(img_np, mode='gaussian', var=0.1)
57
  elif noise_type == "salt_pepper":
58
+ noisy_img = random_noise(img_np, mode='s&p', amount=0.1)
59
  return np.clip(noisy_img, 0., 1.)
60
 
 
61
  def predict_denoised_image(autoencoder, image):
62
+ # Preprocesar imagen (redimensionar a 256x256, normalizar a [0, 1])
63
  img_resized = tf.image.resize(image, (256, 256)) / 255.0
64
  img_array = np.expand_dims(img_resized, axis=0)
65
 
 
66
  noisy_image = add_noise(img_resized)
67
 
 
68
  denoised_image = autoencoder.predict(np.expand_dims(noisy_image, axis=0))
69
 
 
70
  fig, ax = plt.subplots(1, 2, figsize=(10, 5))
71
  ax[0].imshow(noisy_image)
72
  ax[0].set_title("Noisy Image")
 
78
 
79
  plt.show()
80
 
81
+ test_image = tf.keras.preprocessing.image.load_img('image.jpg', target_size=(256, 256))
 
82
  test_image = tf.keras.preprocessing.image.img_to_array(test_image)
83
 
 
84
  predict_denoised_image(autoencoder, test_image)
85
  ```
86