Spaces:
Running on Zero
Running on Zero
Commit ·
ed21522
1
Parent(s): 8e9727a
chore: initialize git repository and add standard hook templates
Browse files
app.py
CHANGED
|
@@ -177,13 +177,10 @@ def draw_patches_on_image(image_arr, positions, x_offset, y_offset, h, w):
|
|
| 177 |
orig_pil = Image.fromarray(img)
|
| 178 |
draw = ImageDraw.Draw(temp_img)
|
| 179 |
|
| 180 |
-
orig_w, orig_h = orig_pil.size
|
| 181 |
-
ratio = min(TARGET_CANVAS_SIZE / orig_w, TARGET_CANVAS_SIZE / orig_h)
|
| 182 |
-
|
| 183 |
for i, (px, py) in enumerate(positions):
|
| 184 |
-
orig_y =
|
| 185 |
-
orig_x =
|
| 186 |
-
orig_px_size = PATCH_SIZE
|
| 187 |
|
| 188 |
box = (int(orig_y), int(orig_x), int(orig_y + orig_px_size), int(orig_x + orig_px_size))
|
| 189 |
|
|
@@ -284,14 +281,14 @@ def process_click_inference(x_orig, y_orig, original_image, state):
|
|
| 284 |
state['inference_params'] = transfer_inference_params(state['inference_params'], device)
|
| 285 |
|
| 286 |
orig_h, orig_w = state['original_image'].shape[:2]
|
| 287 |
-
|
| 288 |
|
| 289 |
-
canvas_y = int(x_orig
|
| 290 |
-
canvas_x = int(y_orig
|
| 291 |
|
| 292 |
# 1px flexible precision anchoring the patch directly onto the exact center click
|
| 293 |
-
px = max(0, min(int(canvas_x - PATCH_SIZE / 2),
|
| 294 |
-
py = max(0, min(int(canvas_y - PATCH_SIZE / 2),
|
| 295 |
|
| 296 |
cur_loc = state['cur_location'].to(device) if state['cur_location'] is not None else None
|
| 297 |
loc_tensor = torch.tensor([[px, py]], dtype=torch.long, device=device)
|
|
|
|
| 177 |
orig_pil = Image.fromarray(img)
|
| 178 |
draw = ImageDraw.Draw(temp_img)
|
| 179 |
|
|
|
|
|
|
|
|
|
|
| 180 |
for i, (px, py) in enumerate(positions):
|
| 181 |
+
orig_y = py - y_offset
|
| 182 |
+
orig_x = px - x_offset
|
| 183 |
+
orig_px_size = PATCH_SIZE
|
| 184 |
|
| 185 |
box = (int(orig_y), int(orig_x), int(orig_y + orig_px_size), int(orig_x + orig_px_size))
|
| 186 |
|
|
|
|
| 281 |
state['inference_params'] = transfer_inference_params(state['inference_params'], device)
|
| 282 |
|
| 283 |
orig_h, orig_w = state['original_image'].shape[:2]
|
| 284 |
+
canvas_size = max(orig_h, orig_w)
|
| 285 |
|
| 286 |
+
canvas_y = int(x_orig) + state['y_offset']
|
| 287 |
+
canvas_x = int(y_orig) + state['x_offset']
|
| 288 |
|
| 289 |
# 1px flexible precision anchoring the patch directly onto the exact center click
|
| 290 |
+
px = max(0, min(int(canvas_x - PATCH_SIZE / 2), canvas_size - PATCH_SIZE))
|
| 291 |
+
py = max(0, min(int(canvas_y - PATCH_SIZE / 2), canvas_size - PATCH_SIZE))
|
| 292 |
|
| 293 |
cur_loc = state['cur_location'].to(device) if state['cur_location'] is not None else None
|
| 294 |
loc_tensor = torch.tensor([[px, py]], dtype=torch.long, device=device)
|