remove to numpy image function
Browse files- app.py +5 -3
- inference.py +0 -19
app.py
CHANGED
|
@@ -29,7 +29,6 @@ import traceback
|
|
| 29 |
from inference import (
|
| 30 |
load_curia_dataset,
|
| 31 |
load_id_to_labels,
|
| 32 |
-
to_numpy_image,
|
| 33 |
infer_image,
|
| 34 |
)
|
| 35 |
|
|
@@ -363,7 +362,7 @@ def sample_dataset_example(
|
|
| 363 |
dataset = load_curia_dataset(subset)
|
| 364 |
index = pick_random_indices(dataset, target_id)
|
| 365 |
record = dataset[index]
|
| 366 |
-
image =
|
| 367 |
mask_array = record.get("mask")
|
| 368 |
|
| 369 |
meta = {
|
|
@@ -467,7 +466,10 @@ def handle_upload_preview(
|
|
| 467 |
return None, "Please upload an image.", "", pd.DataFrame(), gr.update(visible=False), None
|
| 468 |
|
| 469 |
try:
|
| 470 |
-
np_image =
|
|
|
|
|
|
|
|
|
|
| 471 |
|
| 472 |
# Apply windowing only for display, keep raw image for model inference
|
| 473 |
display = to_display_image(np_image)
|
|
|
|
| 29 |
from inference import (
|
| 30 |
load_curia_dataset,
|
| 31 |
load_id_to_labels,
|
|
|
|
| 32 |
infer_image,
|
| 33 |
)
|
| 34 |
|
|
|
|
| 362 |
dataset = load_curia_dataset(subset)
|
| 363 |
index = pick_random_indices(dataset, target_id)
|
| 364 |
record = dataset[index]
|
| 365 |
+
image = np.array(record["image"]).astype(np.float32)
|
| 366 |
mask_array = record.get("mask")
|
| 367 |
|
| 368 |
meta = {
|
|
|
|
| 466 |
return None, "Please upload an image.", "", pd.DataFrame(), gr.update(visible=False), None
|
| 467 |
|
| 468 |
try:
|
| 469 |
+
np_image = np.array(image).astype(np.float32)
|
| 470 |
+
if np_image.ndim == 3: # RGB image
|
| 471 |
+
# convert to grayscale
|
| 472 |
+
np_image = np_image.mean(axis=-1)
|
| 473 |
|
| 474 |
# Apply windowing only for display, keep raw image for model inference
|
| 475 |
display = to_display_image(np_image)
|
inference.py
CHANGED
|
@@ -143,25 +143,6 @@ def load_curia_dataset(subset: str) -> Any:
|
|
| 143 |
return ds["test"]
|
| 144 |
return ds
|
| 145 |
|
| 146 |
-
|
| 147 |
-
def to_numpy_image(image: Any) -> np.ndarray:
|
| 148 |
-
"""Convert dataset or user-provided imagery to a float32 numpy array."""
|
| 149 |
-
|
| 150 |
-
if isinstance(image, np.ndarray):
|
| 151 |
-
arr = image
|
| 152 |
-
elif isinstance(image, Image.Image):
|
| 153 |
-
arr = np.array(image)
|
| 154 |
-
else:
|
| 155 |
-
# Some datasets provide nested dicts or lists – attempt to coerce.
|
| 156 |
-
arr = np.array(image)
|
| 157 |
-
|
| 158 |
-
if arr.ndim == 3 and arr.shape[-1] == 3:
|
| 159 |
-
# Convert RGB to grayscale by averaging channels
|
| 160 |
-
arr = arr.mean(axis=-1)
|
| 161 |
-
|
| 162 |
-
return arr.astype(np.float32)
|
| 163 |
-
|
| 164 |
-
|
| 165 |
def infer_image(
|
| 166 |
image: np.ndarray,
|
| 167 |
head: str,
|
|
|
|
| 143 |
return ds["test"]
|
| 144 |
return ds
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
def infer_image(
|
| 147 |
image: np.ndarray,
|
| 148 |
head: str,
|