forked from aminshabani/house_diffusion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
json_fixer.py
83 lines (69 loc) · 2.28 KB
/
json_fixer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import json
import numpy as np
from glob import glob
import os
def reader(filename):
with open(filename) as f:
info = json.load(f)
rms_bbs = np.asarray(info['boxes'])
fp_eds = info['edges']
rms_type = info['room_type']
eds_to_rms = info['ed_rm']
s_r = 0
for rmk in range(len(rms_type)):
if rms_type[rmk] != 17:
s_r = s_r + 1
rms_bbs = np.array(rms_bbs) / 256.0
fp_eds = np.array(fp_eds) / 256.0
fp_eds = fp_eds[:, :4]
tl = np.min(rms_bbs[:, :2], 0)
br = np.max(rms_bbs[:, 2:], 0)
shift = (tl + br) / 2.0 - 0.5
rms_bbs[:, :2] -= shift
rms_bbs[:, 2:] -= shift
fp_eds[:, :2] -= shift
fp_eds[:, 2:] -= shift
tl -= shift
br -= shift
eds_to_rms_tmp = []
for l in range(len(eds_to_rms)):
eds_to_rms_tmp.append([eds_to_rms[l][0]])
return rms_type, fp_eds, rms_bbs, eds_to_rms, eds_to_rms_tmp
file_list = glob('rplan/*')
processed_files = 0
out_size = 64
length_edges = []
subgraphs = []
for line in file_list:
rms_type, fp_eds, rms_bbs, eds_to_rms, eds_to_rms_tmp = reader(line)
eds_to_rms_tmp = []
for l in range(len(eds_to_rms)):
eds_to_rms_tmp.append([eds_to_rms[l][0]])
rms_masks = []
im_size = 256
fp_mk = np.zeros((out_size, out_size))
nodes = rms_type
for k in range(len(nodes)):
eds = []
for l, e_map in enumerate(eds_to_rms_tmp):
if k in e_map:
eds.append(l)
for eds_poly in [eds]:
length_edges.append((line, np.array([fp_eds[l][:4] for l in eds_poly], dtype=object)))
processed_files += 1
if processed_files % 1000 == 0:
print(f"Processed {processed_files} files.")
print(f"Finished processing {processed_files} files.")
# Convert length_edges to a structured array to handle variable-length sequences
dtype = [('filename', 'U256'), ('edges', 'O')]
length_edges_structured = np.array(length_edges, dtype=dtype)
chk = [x['edges'].shape for x in length_edges_structured]
idx = [i for i, x in enumerate(chk) if len(x) != 2]
final = length_edges_structured[idx]['filename'].tolist()
final = [x.replace('\n', '') for x in final]
for fin in final:
try:
os.remove(fin)
except:
print(f"Failed to delete {fin}")
print("Verification: Basic check complete.")