Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 4 additions & 8 deletions postprocessing/dula/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 14 additions & 14 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
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
8 changes: 4 additions & 4 deletions utils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions visualization/floorplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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')

Expand Down
4 changes: 2 additions & 2 deletions visualization/grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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


Expand Down