Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,11 +77,17 @@ COLOR_MAPPING_RGB = {to_rgb(k): v for k, v in COLOR_MAPPING_.items()}
|
|
| 77 |
def map_colors_rgb(color: tuple) -> str:
|
| 78 |
return COLOR_MAPPING_RGB[color]
|
| 79 |
|
| 80 |
-
def get_segmentation_of_room(image: Image) -> tuple[np.ndarray, Image]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
# Semantic Segmentation
|
| 82 |
with torch.inference_mode():
|
| 83 |
-
semantic_inputs = processor(images=
|
| 84 |
-
semantic_inputs = {key: value.to(
|
| 85 |
semantic_outputs = model(**semantic_inputs)
|
| 86 |
# pass through image_processor for postprocessing
|
| 87 |
segmentation_maps = processor.post_process_semantic_segmentation(semantic_outputs, target_sizes=[image.size[::-1]])
|
|
|
|
| 77 |
def map_colors_rgb(color: tuple) -> str:
|
| 78 |
return COLOR_MAPPING_RGB[color]
|
| 79 |
|
| 80 |
+
def get_segmentation_of_room(image: Image) -> tuple[np.ndarray, Image.Image]:
|
| 81 |
+
|
| 82 |
+
# Ensure image is valid before processing
|
| 83 |
+
if not isinstance(image, Image.Image):
|
| 84 |
+
raise TypeError("Input 'image' must be a PIL Image object.")
|
| 85 |
+
|
| 86 |
+
|
| 87 |
# Semantic Segmentation
|
| 88 |
with torch.inference_mode():
|
| 89 |
+
semantic_inputs = processor(images=imag, return_tensors="pt", size={"height": 256, "width": 256})
|
| 90 |
+
semantic_inputs = {key: value.to(DEVICE) for key, value in semantic_inputs.items()}
|
| 91 |
semantic_outputs = model(**semantic_inputs)
|
| 92 |
# pass through image_processor for postprocessing
|
| 93 |
segmentation_maps = processor.post_process_semantic_segmentation(semantic_outputs, target_sizes=[image.size[::-1]])
|