Spaces:
Runtime error
Runtime error
Gaurav
commited on
Commit
·
f28db37
1
Parent(s):
326a837
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,16 @@ class LABEL_TYPE(Enum):
|
|
| 27 |
WALL = 0
|
| 28 |
FLOOR = 3
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def find_boundary(label_value, mask):
|
| 32 |
contours = find_contours(mask == label_value, 0.5, fully_connected="high")
|
|
@@ -76,6 +86,7 @@ def detect():
|
|
| 76 |
# Assuming base64_str is the string value without 'data:image/jpeg;base64,'
|
| 77 |
img = Image.open(io.BytesIO(base64.decodebytes(bytes(base64_str, "utf-8"))))
|
| 78 |
numpydata = np.asarray(img)
|
|
|
|
| 79 |
window_mask = find_boundary(LABEL_TYPE.WINDOW.value, mask)
|
| 80 |
floor_mask = find_boundary(LABEL_TYPE.FLOOR.value, mask)
|
| 81 |
window_contours = [np.fliplr(ctr).astype(np.int32) for ctr in window_mask]
|
|
|
|
| 27 |
WALL = 0
|
| 28 |
FLOOR = 3
|
| 29 |
|
| 30 |
+
def query_image(img):
|
| 31 |
+
target_size = (img.shape[0], img.shape[1])
|
| 32 |
+
inputs = preprocessor(images=img, return_tensors="pt")
|
| 33 |
+
with torch.no_grad():
|
| 34 |
+
outputs = model(**inputs)
|
| 35 |
+
outputs.class_queries_logits = outputs.class_queries_logits.cpu()
|
| 36 |
+
outputs.masks_queries_logits = outputs.masks_queries_logits.cpu()
|
| 37 |
+
results = preprocessor.post_process_segmentation(outputs=outputs, target_size=target_size)[0].cpu().detach()
|
| 38 |
+
results = torch.argmax(results, dim=0).numpy()
|
| 39 |
+
return results
|
| 40 |
|
| 41 |
def find_boundary(label_value, mask):
|
| 42 |
contours = find_contours(mask == label_value, 0.5, fully_connected="high")
|
|
|
|
| 86 |
# Assuming base64_str is the string value without 'data:image/jpeg;base64,'
|
| 87 |
img = Image.open(io.BytesIO(base64.decodebytes(bytes(base64_str, "utf-8"))))
|
| 88 |
numpydata = np.asarray(img)
|
| 89 |
+
mask = query_image(numpydata)
|
| 90 |
window_mask = find_boundary(LABEL_TYPE.WINDOW.value, mask)
|
| 91 |
floor_mask = find_boundary(LABEL_TYPE.FLOOR.value, mask)
|
| 92 |
window_contours = [np.fliplr(ctr).astype(np.int32) for ctr in window_mask]
|