Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
969f59e
1
Parent(s):
609acff
replaced load_image
Browse files- app.py +2 -2
- eval.py +1 -1
- main.py +2 -1
- sweeper.py +2 -1
- utils.py +30 -0
app.py
CHANGED
@@ -7,10 +7,10 @@ import gradio as gr
|
|
7 |
import jax
|
8 |
import numpy as np
|
9 |
import spaces
|
10 |
-
import zea
|
11 |
from PIL import Image
|
12 |
|
13 |
from main import Config, init, run
|
|
|
14 |
|
15 |
CONFIG_PATH = "configs/semantic_dps.yaml"
|
16 |
SLIDER_CONFIG_PATH = "configs/slider_params.yaml"
|
@@ -127,7 +127,7 @@ example_image_paths = [
|
|
127 |
for f in os.listdir(ASSETS_DIR)
|
128 |
if f.lower().endswith(".png")
|
129 |
]
|
130 |
-
example_images = [
|
131 |
examples = [[img] for img in example_images]
|
132 |
|
133 |
|
|
|
7 |
import jax
|
8 |
import numpy as np
|
9 |
import spaces
|
|
|
10 |
from PIL import Image
|
11 |
|
12 |
from main import Config, init, run
|
13 |
+
from utils import load_image
|
14 |
|
15 |
CONFIG_PATH = "configs/semantic_dps.yaml"
|
16 |
SLIDER_CONFIG_PATH = "configs/slider_params.yaml"
|
|
|
127 |
for f in os.listdir(ASSETS_DIR)
|
128 |
if f.lower().endswith(".png")
|
129 |
]
|
130 |
+
example_images = [load_image(p) for p in example_image_paths]
|
131 |
examples = [[img] for img in example_images]
|
132 |
|
133 |
|
eval.py
CHANGED
@@ -9,10 +9,10 @@ from PIL import Image
|
|
9 |
from scipy.ndimage import binary_erosion, distance_transform_edt
|
10 |
from scipy.stats import ks_2samp
|
11 |
from zea import log
|
12 |
-
from zea.io_lib import load_image
|
13 |
|
14 |
import fid_score
|
15 |
from plots import plot_metrics
|
|
|
16 |
|
17 |
|
18 |
def calculate_fid_score(denoised_image_dirs, ground_truth_dir):
|
|
|
9 |
from scipy.ndimage import binary_erosion, distance_transform_edt
|
10 |
from scipy.stats import ks_2samp
|
11 |
from zea import log
|
|
|
12 |
|
13 |
import fid_score
|
14 |
from plots import plot_metrics
|
15 |
+
from utils import load_image
|
16 |
|
17 |
|
18 |
def calculate_fid_score(denoised_image_dirs, ground_truth_dir):
|
main.py
CHANGED
@@ -28,6 +28,7 @@ from plots import create_animation, plot_batch_with_named_masks, plot_dehazed_re
|
|
28 |
from utils import (
|
29 |
apply_bottom_preservation,
|
30 |
extract_skeleton,
|
|
|
31 |
postprocess,
|
32 |
preprocess,
|
33 |
smooth_L1,
|
@@ -374,7 +375,7 @@ def main(
|
|
374 |
|
375 |
images = []
|
376 |
for path in paths:
|
377 |
-
image =
|
378 |
images.append(image)
|
379 |
images = ops.stack(images, axis=0)
|
380 |
|
|
|
28 |
from utils import (
|
29 |
apply_bottom_preservation,
|
30 |
extract_skeleton,
|
31 |
+
load_image,
|
32 |
postprocess,
|
33 |
preprocess,
|
34 |
smooth_L1,
|
|
|
375 |
|
376 |
images = []
|
377 |
for path in paths:
|
378 |
+
image = load_image(path)
|
379 |
images.append(image)
|
380 |
images = ops.stack(images, axis=0)
|
381 |
|
sweeper.py
CHANGED
@@ -23,6 +23,7 @@ from zea import init_device, log
|
|
23 |
|
24 |
from eval import evaluate
|
25 |
from main import init, run
|
|
|
26 |
|
27 |
|
28 |
def load_images_from_dir(input_folder):
|
@@ -31,7 +32,7 @@ def load_images_from_dir(input_folder):
|
|
31 |
|
32 |
images = []
|
33 |
for path in paths:
|
34 |
-
image =
|
35 |
images.append(image)
|
36 |
|
37 |
if len(images) == 0:
|
|
|
23 |
|
24 |
from eval import evaluate
|
25 |
from main import init, run
|
26 |
+
from utils import load_image
|
27 |
|
28 |
|
29 |
def load_images_from_dir(input_folder):
|
|
|
32 |
|
33 |
images = []
|
34 |
for path in paths:
|
35 |
+
image = load_image(path)
|
36 |
images.append(image)
|
37 |
|
38 |
if len(images) == 0:
|
utils.py
CHANGED
@@ -1,5 +1,8 @@
|
|
|
|
|
|
1 |
import numpy as np
|
2 |
from keras import ops
|
|
|
3 |
from skimage import filters, morphology
|
4 |
from zea.utils import translate
|
5 |
|
@@ -131,3 +134,30 @@ def extract_skeleton(images, input_range, sigma_pre=4, sigma_post=4, threshold=0
|
|
131 |
skeleton_masks = (skeleton_masks - min_val) / (max_val - min_val + 1e-8)
|
132 |
|
133 |
return ops.convert_to_tensor(skeleton_masks, dtype=images.dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
|
3 |
import numpy as np
|
4 |
from keras import ops
|
5 |
+
from PIL import Image
|
6 |
from skimage import filters, morphology
|
7 |
from zea.utils import translate
|
8 |
|
|
|
134 |
skeleton_masks = (skeleton_masks - min_val) / (max_val - min_val + 1e-8)
|
135 |
|
136 |
return ops.convert_to_tensor(skeleton_masks, dtype=images.dtype)
|
137 |
+
|
138 |
+
|
139 |
+
def load_image(filename, grayscale=True):
|
140 |
+
"""Load an image file and return a numpy array using PIL.
|
141 |
+
|
142 |
+
Args:
|
143 |
+
filename (str): The path to the image file.
|
144 |
+
grayscale (bool, optional): Whether to convert the image to grayscale. Defaults to True.
|
145 |
+
|
146 |
+
Returns:
|
147 |
+
numpy.ndarray: A numpy array of the image.
|
148 |
+
|
149 |
+
Raises:
|
150 |
+
FileNotFoundError: If the file does not exist.
|
151 |
+
"""
|
152 |
+
filename = Path(filename)
|
153 |
+
if not filename.exists():
|
154 |
+
raise FileNotFoundError(f"File {filename} does not exist")
|
155 |
+
|
156 |
+
img = Image.open(filename)
|
157 |
+
if grayscale:
|
158 |
+
img = img.convert("L")
|
159 |
+
else:
|
160 |
+
img = img.convert("RGB")
|
161 |
+
|
162 |
+
arr = np.array(img)
|
163 |
+
return arr
|