From a2e80d13fecbe53ebe52963f2e1a1637c3710e7f Mon Sep 17 00:00:00 2001 From: EnriqueSolarte Date: Wed, 18 Sep 2024 23:04:07 +0800 Subject: [PATCH 1/5] fix error for np.int and np.float --- utils/conversion.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/conversion.py b/utils/conversion.py index 906d5f6..03e8f0e 100644 --- a/utils/conversion.py +++ b/utils/conversion.py @@ -52,7 +52,7 @@ def get_lon(w, is_np, b=None): def pixel2uv(pixel, w=1024, h=512, axis=None): - pixel = pixel.astype(np.float) if isinstance(pixel, np.ndarray) else pixel.float() + pixel = pixel.astype(np.float64) if isinstance(pixel, np.ndarray) else pixel.float() # +0.5 will make left/right and up/down coordinates symmetric if axis is None: u = (pixel[..., 0:1] + 0.5) / w @@ -203,19 +203,19 @@ def uv2pixel(uv, w=1024, h=512, axis=None, need_round=True): elif axis == 0: pu = uv * w - 0.5 if need_round: - pu = pu.round().astype(np.int) if isinstance(uv, np.ndarray) else pu.round().int() + pu = pu.round().astype(np.int64) if isinstance(uv, np.ndarray) else pu.round().int() return pu elif axis == 1: pv = uv * h - 0.5 if need_round: - pv = pv.round().astype(np.int) if isinstance(uv, np.ndarray) else pv.round().int() + pv = pv.round().astype(np.int64) if isinstance(uv, np.ndarray) else pv.round().int() return pv else: assert False, "axis error" lst = [pu, pv] if need_round: - pixel = np.concatenate(lst, axis=-1).round().astype(np.int) if isinstance(uv, np.ndarray) else torch.cat(lst, + pixel = np.concatenate(lst, axis=-1).round().astype(np.int64) if isinstance(uv, np.ndarray) else torch.cat(lst, dim=-1).round().int() else: pixel = np.concatenate(lst, axis=-1) if isinstance(uv, np.ndarray) else torch.cat(lst, dim=-1) From 620613cf024a741bad4aac52d1ab229db577ee43 Mon Sep 17 00:00:00 2001 From: Don Mahurin <2797413+dmahurin@users.noreply.github.com> Date: Tue, 2 Sep 2025 08:30:31 -0700 Subject: [PATCH 2/5] Update package versions. --- requirements.txt | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1c823f2..57700d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,15 @@ -numpy==1.21.0 -torch==1.7.1 -torchvision==0.8.2 +numpy==2.2.6 +torch==2.7.1 +torchvision==0.22.1 yacs==0.1.8 -einops==0.3.0 -opencv-python==4.5.3.56 -pylsd-nova==1.2.0 -tqdm==4.64.0 -scipy==1.8.1 -termcolor==1.1.0 -shapely==1.8.2 -imageio==2.19.2 -open3d==0.15.2 -gdown==4.4.0 -gradio==3.0.5 \ No newline at end of file +einops==0.8.0 +opencv-python==4.12.0.88 +pylsd-nova==1.2.1 +tqdm==4.67.1 +scipy==1.14.1 +termcolor==3.0.1 +shapely==2.1.0 +imageio==2.37.0 +open3d==0.19.0 +gdown==5.2.0 +gradio==5.27.0 From 3339a677e2ab3cd572b3304e39433cb64ba36509 Mon Sep 17 00:00:00 2001 From: Don Mahurin <2797413+dmahurin@users.noreply.github.com> Date: Tue, 2 Sep 2025 08:49:10 -0700 Subject: [PATCH 3/5] Convert np float to native float to allow serialization --- inference.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/inference.py b/inference.py index 175038d..dfffc74 100644 --- a/inference.py +++ b/inference.py @@ -160,11 +160,22 @@ def show_alpha_floorplan(dt_xyz, side_l=512, border_color=None): return dt_floorplan +class NpEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, np.integer): + return int(obj) + if isinstance(obj, np.floating): + return float(obj) + if isinstance(obj, np.ndarray): + return obj.tolist() + return json.JSONEncoder.default(self, obj) + + def save_pred_json(xyz, ration, save_path): # xyz[..., -1] = -xyz[..., -1] json_data = xyz2json(xyz, ration) with open(save_path, 'w') as f: - f.write(json.dumps(json_data, indent=4) + '\n') + f.write(json.dumps(json_data, indent=4, cls=NpEncoder) + '\n') return json_data From 967fa86eb7cec80035e1d01c084d907afaea42f7 Mon Sep 17 00:00:00 2001 From: Don Mahurin <2797413+dmahurin@users.noreply.github.com> Date: Tue, 2 Sep 2025 08:54:33 -0700 Subject: [PATCH 4/5] change np.float and np.int to np.float64 and np.int64 --- visualization/floorplan.py | 6 +++--- visualization/grad.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/visualization/floorplan.py b/visualization/floorplan.py index 2c38e9f..af42efb 100644 --- a/visualization/floorplan.py +++ b/visualization/floorplan.py @@ -29,7 +29,7 @@ def draw_floorplan(xz, fill_color=None, border_color=None, side_l=512, show_radi if fill_color is None: fill_color = [1] - board = np.zeros([side_l, side_l, len(fill_color)], dtype=np.float) + board = np.zeros([side_l, side_l, len(fill_color)], dtype=np.float64) if show_radius is None: show_radius = np.linalg.norm(xz, axis=-1).max() @@ -43,7 +43,7 @@ def draw_floorplan(xz, fill_color=None, border_color=None, side_l=512, show_radi # |------------u xz[:, 1] = -xz[:, 1] xz += side_l // 2 # moving to center - xz = xz.astype(np.int) + xz = xz.astype(np.int64) cv2.fillPoly(board, [xz], fill_color) if border_color: cv2.drawContours(board, [xz], 0, border_color, 2) @@ -101,7 +101,7 @@ def draw_iou_floorplan(dt_xz, gt_xz, show_radius=None, show=False, side_l=512, gt_floorplan = Image.fromarray((gt_floorplan * 255).astype(np.uint8), mode='RGBA') iou_floorplan = Image.alpha_composite(gt_floorplan, dt_floorplan) - back = np.zeros([side_l, side_l, len(fill_color)], dtype=np.float) + back = np.zeros([side_l, side_l, len(fill_color)], dtype=np.float64) back[..., :] = [0.8, 0.8, 0.8, 1] back = Image.fromarray((back * 255).astype(np.uint8), mode='RGBA') diff --git a/visualization/grad.py b/visualization/grad.py index fdc0a25..56ae3a2 100644 --- a/visualization/grad.py +++ b/visualization/grad.py @@ -22,7 +22,7 @@ def convert_img(value, h, need_nor=True, cmap=None): elif cmap == cv2.COLORMAP_PLASMA: grad_img = cv2.applyColorMap((grad_img * 255).astype(np.uint8), colormap=cmap) grad_img = grad_img[..., ::-1] - grad_img = grad_img.astype(np.float) / 255.0 + grad_img = grad_img.astype(np.float64) / 255.0 elif cmap == 'HSV': grad_img = np.round(grad_img * 1000) / 1000.0 grad_img = grad_img[..., np.newaxis].repeat(3, axis=-1) @@ -31,7 +31,7 @@ def convert_img(value, h, need_nor=True, cmap=None): grad_img[..., 2] = 255 grad_img = grad_img.astype(np.uint8) grad_img = cv2.cvtColor(grad_img, cv2.COLOR_HSV2RGB) - grad_img = grad_img.astype(np.float) / 255.0 + grad_img = grad_img.astype(np.float64) / 255.0 return grad_img From 39da56c4d5b34e3a551313df87a5491c5b79c6ea Mon Sep 17 00:00:00 2001 From: Don Mahurin <2797413+dmahurin@users.noreply.github.com> Date: Tue, 2 Sep 2025 08:56:15 -0700 Subject: [PATCH 5/5] Update for current syntax of cv2.findContour and cv2.contourArea --- postprocessing/dula/layout.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/postprocessing/dula/layout.py b/postprocessing/dula/layout.py index c5ff71f..b734b0f 100644 --- a/postprocessing/dula/layout.py +++ b/postprocessing/dula/layout.py @@ -155,15 +155,11 @@ def fit_layout(floor_xz, need_cube=False, show=False, block_eps=5): plt.show() pred = np.uint8(ans) - pred_polys = cv2.findContours(pred, 1, 3) - if isinstance(pred_polys, tuple): - if len(pred_polys) == 3: - pred_polys = pred_polys[1] - else: - pred_polys = pred_polys[0] - pred_polys.sort(key=lambda x: cv2.contourArea(x), reverse=True) - pred_poly = pred_polys[0] + + pred_polys, hierarchy = cv2.findContours(pred, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) + pred_polys = sorted(pred_polys, key=cv2.contourArea) + pred_poly = pred_polys[-1] # findContours may produce errors, which are enforced here for i in range(len(pred_poly)): p1 = pred_poly[i][0]