Mikhael Johanes
commited on
Commit
·
0526506
1
Parent(s):
bef892f
clean up
Browse files- gist1/__pycache__/gpt.cpython-38.pyc +0 -0
- gist1/__pycache__/vqvae_gpt.cpython-38.pyc +0 -0
- gist1/gpt.py +0 -3
- gist1/vqvae_gpt.py +1 -8
- utils/__pycache__/isoutil.cpython-38.pyc +0 -0
- utils/__pycache__/misc.cpython-38.pyc +0 -0
- utils/isoutil.py +0 -419
- utils/misc.py +0 -42
gist1/__pycache__/gpt.cpython-38.pyc
CHANGED
Binary files a/gist1/__pycache__/gpt.cpython-38.pyc and b/gist1/__pycache__/gpt.cpython-38.pyc differ
|
|
gist1/__pycache__/vqvae_gpt.cpython-38.pyc
CHANGED
Binary files a/gist1/__pycache__/vqvae_gpt.cpython-38.pyc and b/gist1/__pycache__/vqvae_gpt.cpython-38.pyc differ
|
|
gist1/gpt.py
CHANGED
@@ -7,12 +7,9 @@
|
|
7 |
import torch
|
8 |
import torch.nn as nn
|
9 |
import torch.nn.functional as F
|
10 |
-
from torch.optim import Optimizer
|
11 |
from torch.optim.lr_scheduler import _LRScheduler
|
12 |
import numpy as np
|
13 |
|
14 |
-
import time
|
15 |
-
|
16 |
import copy
|
17 |
|
18 |
def new_gelu(x):
|
|
|
7 |
import torch
|
8 |
import torch.nn as nn
|
9 |
import torch.nn.functional as F
|
|
|
10 |
from torch.optim.lr_scheduler import _LRScheduler
|
11 |
import numpy as np
|
12 |
|
|
|
|
|
13 |
import copy
|
14 |
|
15 |
def new_gelu(x):
|
gist1/vqvae_gpt.py
CHANGED
@@ -4,9 +4,7 @@ import torch.nn.functional as F
|
|
4 |
from gist1.gpt import GPT
|
5 |
from gist1.vqvae import VQVAE
|
6 |
|
7 |
-
from utils.misc import
|
8 |
-
import os
|
9 |
-
import time
|
10 |
|
11 |
|
12 |
class VQVAETransformer(nn.Module):
|
@@ -44,11 +42,6 @@ class VQVAETransformer(nn.Module):
|
|
44 |
|
45 |
return model
|
46 |
|
47 |
-
def load_vqvae_weight(self, args):
|
48 |
-
VQVAE_path = args['vqvae_checkpoint']
|
49 |
-
self.vqvae.load_state_dict(torch.load(VQVAE_path))
|
50 |
-
self.vqvae.eval()
|
51 |
-
|
52 |
def load_transformer(self, args):
|
53 |
# seed= args['seed']
|
54 |
# torch.manual_seed(seed)
|
|
|
4 |
from gist1.gpt import GPT
|
5 |
from gist1.vqvae import VQVAE
|
6 |
|
7 |
+
from utils.misc import load_params
|
|
|
|
|
8 |
|
9 |
|
10 |
class VQVAETransformer(nn.Module):
|
|
|
42 |
|
43 |
return model
|
44 |
|
|
|
|
|
|
|
|
|
|
|
45 |
def load_transformer(self, args):
|
46 |
# seed= args['seed']
|
47 |
# torch.manual_seed(seed)
|
utils/__pycache__/isoutil.cpython-38.pyc
CHANGED
Binary files a/utils/__pycache__/isoutil.cpython-38.pyc and b/utils/__pycache__/isoutil.cpython-38.pyc differ
|
|
utils/__pycache__/misc.cpython-38.pyc
CHANGED
Binary files a/utils/__pycache__/misc.cpython-38.pyc and b/utils/__pycache__/misc.cpython-38.pyc differ
|
|
utils/isoutil.py
CHANGED
@@ -4,24 +4,11 @@ from matplotlib.patches import Polygon
|
|
4 |
from matplotlib.collections import PatchCollection
|
5 |
|
6 |
|
7 |
-
|
8 |
def pol2car(rho, pi, xi, yi):
|
9 |
x = rho * np.cos(pi) + xi
|
10 |
y = rho * np.sin(pi) + yi
|
11 |
return (x, y)
|
12 |
|
13 |
-
def car2pol(xi, yi):
|
14 |
-
rho = np.sqrt(xi**2 + yi**2)
|
15 |
-
phi = np.arctan2(yi, xi)
|
16 |
-
return (rho, phi)
|
17 |
-
|
18 |
-
def car2polnorm(xi, yi):
|
19 |
-
rho = np.sqrt(xi**2 + yi**2)
|
20 |
-
phi = np.arctan2(yi, xi)
|
21 |
-
phi %= 2*np.pi
|
22 |
-
phi /= 2*np.pi
|
23 |
-
return (rho, phi)
|
24 |
-
|
25 |
def plot_isovist(isovists, show_axis=False, s=0.1, figsize=(5,5)):
|
26 |
#transpose the matrix
|
27 |
# isovists = np.transpose(isovists, (isovists.ndim-1, isovists.ndim-2))
|
@@ -45,74 +32,6 @@ def plot_isovist(isovists, show_axis=False, s=0.1, figsize=(5,5)):
|
|
45 |
ax.scatter(x, y, s, 'black')
|
46 |
return fig
|
47 |
|
48 |
-
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
49 |
-
from matplotlib.figure import Figure
|
50 |
-
|
51 |
-
|
52 |
-
def isovist_to_img(isovist, show_axis=False, s=0.1, figsize=(5,5)):
|
53 |
-
points = []
|
54 |
-
xy = (0, 0)
|
55 |
-
res = np.pi/90
|
56 |
-
isovist = isovist + 0.5
|
57 |
-
for j, rho in enumerate(isovist):
|
58 |
-
if rho <= 2.0:
|
59 |
-
pt = pol2car(rho, j*res, xy[0], xy[1])
|
60 |
-
points.append(pt)
|
61 |
-
x = [i[0] for i in points]
|
62 |
-
y = [i[1] for i in points]
|
63 |
-
fig = plt.figure(figsize=figsize)
|
64 |
-
canvas = FigureCanvas(fig)
|
65 |
-
ax = fig.add_subplot(111)
|
66 |
-
ax.set_aspect('equal')
|
67 |
-
ax.set_xlim(-1,1)
|
68 |
-
ax.set_ylim(-1,1)
|
69 |
-
if not show_axis:
|
70 |
-
ax.axis('off')
|
71 |
-
ax.scatter(x, y, s, 'black')
|
72 |
-
|
73 |
-
canvas.draw()
|
74 |
-
image = np.fromstring(canvas.tostring_rgb(), dtype='uint8')
|
75 |
-
return image
|
76 |
-
|
77 |
-
def isovist_to_img_a(isovist, show_axis=False, s=0.1, figsize=(5,5)):
|
78 |
-
points = []
|
79 |
-
xy = (0, 0)
|
80 |
-
res = np.pi/128
|
81 |
-
isovist = isovist + 0.5
|
82 |
-
for j, rho in enumerate(isovist):
|
83 |
-
if rho <= 2.0:
|
84 |
-
pt = pol2car(rho, j*res, xy[0], xy[1])
|
85 |
-
points.append(pt)
|
86 |
-
x = [i[0] for i in points]
|
87 |
-
y = [i[1] for i in points]
|
88 |
-
fig = plt.figure(figsize=figsize)
|
89 |
-
canvas = FigureCanvas(fig)
|
90 |
-
ax = fig.add_subplot(111)
|
91 |
-
ax.set_aspect('equal')
|
92 |
-
ax.set_xlim(-1,1)
|
93 |
-
ax.set_ylim(-1,1)
|
94 |
-
if not show_axis:
|
95 |
-
ax.axis('off')
|
96 |
-
ax.scatter(x, y, s, 'black')
|
97 |
-
|
98 |
-
canvas.draw()
|
99 |
-
image = np.fromstring(canvas.tostring_rgb(), dtype='uint8')
|
100 |
-
return image
|
101 |
-
|
102 |
-
def isovist_to_cartesian(isovist, x, y, scale):
|
103 |
-
points = []
|
104 |
-
xy = (x, y)
|
105 |
-
res = np.pi/90
|
106 |
-
isovist = isovist * scale
|
107 |
-
for j, rho in enumerate(isovist):
|
108 |
-
if rho <= scale:
|
109 |
-
pt = pol2car(rho, j*res, xy[0], xy[1])
|
110 |
-
points.append(pt)
|
111 |
-
else:
|
112 |
-
pt = pol2car(scale, j*res, xy[0], xy[1])
|
113 |
-
points.append(pt)
|
114 |
-
points = np.stack(points)
|
115 |
-
return(points)
|
116 |
|
117 |
def isovist_to_cartesian_a(isovist, x, y, scale):
|
118 |
points = []
|
@@ -125,49 +44,6 @@ def isovist_to_cartesian_a(isovist, x, y, scale):
|
|
125 |
points = np.stack(points)
|
126 |
return(points)
|
127 |
|
128 |
-
def isovist_to_cartesian_b(isovist, x, y):
|
129 |
-
points = []
|
130 |
-
xy = (x, y)
|
131 |
-
res = np.pi*2
|
132 |
-
isovist = isovist
|
133 |
-
for j, rho in isovist:
|
134 |
-
pt = pol2car(rho, j*res, xy[0], xy[1])
|
135 |
-
points.append(pt)
|
136 |
-
points = np.stack(points)
|
137 |
-
return(points)
|
138 |
-
|
139 |
-
def isovist_to_cartesian_segment(isovist, x, y, scale):
|
140 |
-
points = []
|
141 |
-
segment = []
|
142 |
-
xy = (x, y)
|
143 |
-
res = np.pi/90
|
144 |
-
isovist = isovist * scale
|
145 |
-
p_rho = isovist[-1]
|
146 |
-
for j, rho in enumerate(isovist):
|
147 |
-
delta = abs(p_rho-rho)
|
148 |
-
if j == 0:
|
149 |
-
first_rho = rho
|
150 |
-
if rho < 0.98 * scale and delta < 0.05 * scale:
|
151 |
-
pt = pol2car(rho, j*res, xy[0], xy[1])
|
152 |
-
segment.append(pt)
|
153 |
-
else:
|
154 |
-
points.append(segment)
|
155 |
-
segment = []
|
156 |
-
p_rho = rho
|
157 |
-
if first_rho < 1.0 * scale and abs(rho-first_rho)< 0.05 * scale :
|
158 |
-
if len(points) > 0:
|
159 |
-
segment.extend(points[0])
|
160 |
-
points[0]=segment
|
161 |
-
else:
|
162 |
-
points.append(segment)
|
163 |
-
else:
|
164 |
-
points.append(segment)
|
165 |
-
segments = []
|
166 |
-
for i in range(len(points)):
|
167 |
-
if len(points[i])>0:
|
168 |
-
segment = np.stack(points[i])
|
169 |
-
segments.append(segment)
|
170 |
-
return(segments)
|
171 |
|
172 |
def isovist_to_cartesian_segment_a(isovist, x, y, scale, max=0.98, min = 0.1, d=0.1):
|
173 |
points = []
|
@@ -203,301 +79,6 @@ def isovist_to_cartesian_segment_a(isovist, x, y, scale, max=0.98, min = 0.1, d=
|
|
203 |
return(segments)
|
204 |
|
205 |
|
206 |
-
def isovist_to_cartesian_segment_b(isovist, x, y):
|
207 |
-
points = []
|
208 |
-
segment = []
|
209 |
-
xy = (x, y)
|
210 |
-
res = np.pi*2
|
211 |
-
isovist = isovist
|
212 |
-
p_rho = isovist[-1, 1]
|
213 |
-
_i = 0
|
214 |
-
for j, rho in isovist:
|
215 |
-
delta = abs(p_rho-rho)
|
216 |
-
if _i == 0:
|
217 |
-
first_rho = rho
|
218 |
-
if rho < 0.98 and delta < 0.1 :
|
219 |
-
pt = pol2car(rho, j*res, xy[0], xy[1])
|
220 |
-
segment.append(pt)
|
221 |
-
else:
|
222 |
-
points.append(segment)
|
223 |
-
segment = []
|
224 |
-
p_rho = rho
|
225 |
-
_i += 1
|
226 |
-
if first_rho < 0.98 and abs(rho-first_rho)< 0.1:
|
227 |
-
if len(points) > 0:
|
228 |
-
segment.extend(points[0])
|
229 |
-
points[0]=segment
|
230 |
-
else:
|
231 |
-
points.append(segment)
|
232 |
-
else:
|
233 |
-
points.append(segment)
|
234 |
-
segments = []
|
235 |
-
for i in range(len(points)):
|
236 |
-
if len(points[i])>0:
|
237 |
-
segment = np.stack(points[i])
|
238 |
-
segments.append(segment)
|
239 |
-
return(segments)
|
240 |
-
|
241 |
-
|
242 |
-
# plotting an isovist and return the numpy image
|
243 |
-
def plot_isovist_numpy(k, text=None, figsize=(8,8)):
|
244 |
-
fig, ax = plt.subplots(1,1, figsize=figsize, dpi=300)
|
245 |
-
|
246 |
-
#plot isovist
|
247 |
-
xy = isovist_to_cartesian_a(k, 0, 0, 1.0)
|
248 |
-
polygon = Polygon(xy, True)
|
249 |
-
p = PatchCollection([polygon])
|
250 |
-
p.set_facecolor('#dddddd')
|
251 |
-
p.set_edgecolor(None)
|
252 |
-
ax.add_collection(p)
|
253 |
-
|
254 |
-
# style
|
255 |
-
ax.set_aspect('equal')
|
256 |
-
lim = 1.2
|
257 |
-
ax.set_xlim(-lim,lim)
|
258 |
-
ax.set_ylim(-lim,lim)
|
259 |
-
ax.set_xticks([])
|
260 |
-
ax.set_yticks([])
|
261 |
-
ax.axis('off')
|
262 |
-
if text != None:
|
263 |
-
ax.set_title(text, size=5) # Title
|
264 |
-
fig.tight_layout()
|
265 |
-
|
266 |
-
# for plot with torchvision util
|
267 |
-
fig.canvas.draw()
|
268 |
-
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
|
269 |
-
w, h = fig.canvas.get_width_height()
|
270 |
-
im = data.reshape((int(h), int(w), -1))
|
271 |
-
im = im.transpose((2, 0, 1))
|
272 |
-
plt.close()
|
273 |
-
return im
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
# plotting isovist and boundary from and return the numpy image
|
278 |
-
def plot_isovist_boundary_numpy(isovist, boundary, figsize=(8,8)):
|
279 |
-
fig, ax = plt.subplots(1,1, figsize=figsize, dpi=300)
|
280 |
-
|
281 |
-
#plot isovist
|
282 |
-
xy = isovist_to_cartesian_a(isovist, 0, 0, 1.0)
|
283 |
-
polygon = Polygon(xy, True)
|
284 |
-
p = PatchCollection([polygon])
|
285 |
-
p.set_facecolor('#eeeeee')
|
286 |
-
p.set_edgecolor(None)
|
287 |
-
ax.add_collection(p)
|
288 |
-
|
289 |
-
|
290 |
-
#plot assumed boundary
|
291 |
-
edge_patches = []
|
292 |
-
segments = isovist_to_cartesian_segment_a(boundary, 0, 0, 1.0)
|
293 |
-
for segment in segments:
|
294 |
-
polygon = Polygon(segment, False)
|
295 |
-
edge_patches.append(polygon)
|
296 |
-
p = PatchCollection(edge_patches)
|
297 |
-
p.set_facecolor('none')
|
298 |
-
p.set_edgecolor('#000000')
|
299 |
-
p.set_linewidth(0.5)
|
300 |
-
ax.add_collection(p)
|
301 |
-
|
302 |
-
# style
|
303 |
-
ax.set_aspect('equal')
|
304 |
-
lim = 1.2
|
305 |
-
ax.set_xlim(-lim,lim)
|
306 |
-
ax.set_ylim(-lim,lim)
|
307 |
-
ax.set_xticks([])
|
308 |
-
ax.set_yticks([])
|
309 |
-
ax.axis('off')
|
310 |
-
|
311 |
-
# for plot with torchvision util
|
312 |
-
fig.canvas.draw()
|
313 |
-
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
|
314 |
-
w, h = fig.canvas.get_width_height()
|
315 |
-
im = data.reshape((int(h), int(w), -1))
|
316 |
-
im = im.transpose((2, 0, 1))
|
317 |
-
plt.close()
|
318 |
-
return im
|
319 |
-
|
320 |
-
|
321 |
-
# plotting two isovists (fill and edge) and return the numpy image
|
322 |
-
def plot_isovist_double_numpy(isovist1, isovist2, figsize=(8,8)):
|
323 |
-
fig, ax = plt.subplots(1,1, figsize=figsize, dpi=300)
|
324 |
-
|
325 |
-
#plot isovist1
|
326 |
-
xy = isovist_to_cartesian_a(isovist1, 0, 0, 1.0)
|
327 |
-
polygon = Polygon(xy, True)
|
328 |
-
p = PatchCollection([polygon])
|
329 |
-
p.set_facecolor('#dddddd')
|
330 |
-
p.set_edgecolor(None)
|
331 |
-
ax.add_collection(p)
|
332 |
-
|
333 |
-
#plot isovist2 as boundary
|
334 |
-
xy = isovist_to_cartesian_a(isovist2, 0, 0, 1.0)
|
335 |
-
polygon = Polygon(xy, True)
|
336 |
-
p = PatchCollection([polygon])
|
337 |
-
p.set_facecolor('none')
|
338 |
-
p.set_edgecolor('#000000')
|
339 |
-
p.set_linewidth(0.2)
|
340 |
-
ax.add_collection(p)
|
341 |
-
|
342 |
-
# style
|
343 |
-
ax.set_aspect('equal')
|
344 |
-
lim = 1.2
|
345 |
-
ax.set_xlim(-lim,lim)
|
346 |
-
ax.set_ylim(-lim,lim)
|
347 |
-
ax.set_xticks([])
|
348 |
-
ax.set_yticks([])
|
349 |
-
ax.axis('off')
|
350 |
-
|
351 |
-
# for plot with torchvision util
|
352 |
-
fig.canvas.draw()
|
353 |
-
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
|
354 |
-
w, h = fig.canvas.get_width_height()
|
355 |
-
im = data.reshape((int(h), int(w), -1))
|
356 |
-
im = im.transpose((2, 0, 1))
|
357 |
-
plt.close()
|
358 |
-
return im
|
359 |
-
|
360 |
-
|
361 |
-
# plotting two isovists (fill and edge) and return the numpy image
|
362 |
-
def plot_isovist_triple_numpy(isovists, locs, figsize=(8,8)):
|
363 |
-
isovist1, isovist2, isovist3 = isovists
|
364 |
-
loc1, loc2, loc3 = locs
|
365 |
-
|
366 |
-
fig, ax = plt.subplots(1,1, figsize=figsize, dpi=300)
|
367 |
-
|
368 |
-
#plot isovist1
|
369 |
-
xy = isovist_to_cartesian_a(isovist1, loc1[0], loc1[1], 1.0)
|
370 |
-
polygon = Polygon(xy, True)
|
371 |
-
p = PatchCollection([polygon])
|
372 |
-
p.set_facecolor('#ffdddd')
|
373 |
-
p.set_edgecolor(None)
|
374 |
-
ax.add_collection(p)
|
375 |
-
|
376 |
-
#plot isovist2
|
377 |
-
xy = isovist_to_cartesian_a(isovist2, loc2[0], loc2[1], 1.0)
|
378 |
-
polygon = Polygon(xy, True)
|
379 |
-
p = PatchCollection([polygon])
|
380 |
-
p.set_facecolor('#ddddff')
|
381 |
-
p.set_edgecolor(None)
|
382 |
-
ax.add_collection(p)
|
383 |
-
|
384 |
-
#plot isovist3 as boundary
|
385 |
-
xy = isovist_to_cartesian_a(isovist3, 0, 0, 1.0)
|
386 |
-
polygon = Polygon(xy, True)
|
387 |
-
p = PatchCollection([polygon])
|
388 |
-
p.set_facecolor('none')
|
389 |
-
p.set_edgecolor('#000000')
|
390 |
-
p.set_linewidth(0.2)
|
391 |
-
ax.add_collection(p)
|
392 |
-
|
393 |
-
ax.scatter([x[0] for x in locs], [x[1] for x in locs], c='k', s=8, marker='+')
|
394 |
-
|
395 |
-
annotation = ['x1', 'x2', 'y']
|
396 |
-
for i, anno in enumerate(annotation):
|
397 |
-
ax.annotate(anno, (locs[i][0]+0.1, locs[i][1]), size=8)
|
398 |
-
|
399 |
-
# style
|
400 |
-
ax.set_aspect('equal')
|
401 |
-
lim = 1.5
|
402 |
-
ax.set_xlim(-lim,lim)
|
403 |
-
ax.set_ylim(-lim,lim)
|
404 |
-
ax.set_xticks([])
|
405 |
-
ax.set_yticks([])
|
406 |
-
ax.axis('off')
|
407 |
-
|
408 |
-
# for plot with torchvision util
|
409 |
-
fig.canvas.draw()
|
410 |
-
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
|
411 |
-
w, h = fig.canvas.get_width_height()
|
412 |
-
im = data.reshape((int(h), int(w), -1))
|
413 |
-
im = im.transpose((2, 0, 1))
|
414 |
-
plt.close()
|
415 |
-
return im
|
416 |
-
|
417 |
-
# showing isovist sequence
|
418 |
-
def seq_show(locs, isovists, figsize=(8, 8)):
|
419 |
-
# walk trough the sequence
|
420 |
-
p_loc = np.array((0, 0))
|
421 |
-
b_segments = []
|
422 |
-
b_points = []
|
423 |
-
isovists_pts = []
|
424 |
-
res = np.pi/128
|
425 |
-
p_loc = np.array([0,0])
|
426 |
-
cartesian_locs = []
|
427 |
-
for loc, isovist in zip(locs, isovists):
|
428 |
-
rel_pos = np.asarray(pol2car(loc[0], loc[1]*2*np.pi, p_loc[0], p_loc[1]))
|
429 |
-
for j, rho in enumerate(isovist):
|
430 |
-
if rho < 0.98 :
|
431 |
-
pt = pol2car(rho, j*res, rel_pos[0], rel_pos[1])
|
432 |
-
b_points.append(pt)
|
433 |
-
segments = isovist_to_cartesian_segment_a(isovist, rel_pos[0], rel_pos[1], 1.0)
|
434 |
-
b_segments.extend(segments)
|
435 |
-
isovists_pts.append(isovist_to_cartesian_a(isovist, rel_pos[0], rel_pos[1], 1.0))
|
436 |
-
cartesian_locs.append(rel_pos)
|
437 |
-
p_loc = rel_pos
|
438 |
-
|
439 |
-
fig, ax = plt.subplots(1,1, figsize=figsize, dpi=96)
|
440 |
-
|
441 |
-
|
442 |
-
# isovists
|
443 |
-
isovist_poly = []
|
444 |
-
for isovist_pts in isovists_pts:
|
445 |
-
isovist_poly.append(Polygon(isovist_pts, True))
|
446 |
-
r = PatchCollection(isovist_poly)
|
447 |
-
r.set_facecolor('#000000')
|
448 |
-
r.set_edgecolor(None)
|
449 |
-
r.set_alpha(0.02)
|
450 |
-
ax.add_collection(r)
|
451 |
-
|
452 |
-
|
453 |
-
# isovist path
|
454 |
-
q = PatchCollection([Polygon(cartesian_locs, False)])
|
455 |
-
q.set_facecolor('none')
|
456 |
-
q.set_edgecolor('#cccccc')
|
457 |
-
q.set_linewidth(1.0)
|
458 |
-
q.set_linestyle('dashed')
|
459 |
-
ax.add_collection(q)
|
460 |
-
ax.scatter([x[0] for x in cartesian_locs], [x[1] for x in cartesian_locs], s = 6.0, c='red')
|
461 |
-
|
462 |
-
# boundaries
|
463 |
-
edge_patches = []
|
464 |
-
for segment in b_segments:
|
465 |
-
polygon = Polygon(segment, False)
|
466 |
-
edge_patches.append(polygon)
|
467 |
-
p = PatchCollection(edge_patches)
|
468 |
-
p.set_facecolor('none')
|
469 |
-
p.set_edgecolor('#000000')
|
470 |
-
p.set_linewidth(1.0)
|
471 |
-
ax.add_collection(p)
|
472 |
-
ax.scatter([x[0] for x in b_points], [x[1] for x in b_points], s = 0.05, c='k')
|
473 |
-
|
474 |
-
|
475 |
-
# style
|
476 |
-
ax.set_aspect('equal')
|
477 |
-
lim = 1.5
|
478 |
-
ax.set_xlim(-lim,lim)
|
479 |
-
ax.set_ylim(-lim,lim)
|
480 |
-
ax.set_xticks([])
|
481 |
-
ax.set_yticks([])
|
482 |
-
ax.axis('off')
|
483 |
-
|
484 |
-
return fig
|
485 |
-
|
486 |
-
|
487 |
-
# plotting isovist sequence
|
488 |
-
def plot_isovist_sequence(locs, isovists, figsize=(8,8)):
|
489 |
-
fig = seq_show(locs, isovists, figsize=figsize)
|
490 |
-
|
491 |
-
# for plot with torchvision util
|
492 |
-
fig.canvas.draw()
|
493 |
-
data = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
|
494 |
-
w, h = fig.canvas.get_width_height()
|
495 |
-
im = data.reshape((int(h), int(w), -1))
|
496 |
-
im = im.transpose((2, 0, 1))
|
497 |
-
plt.close()
|
498 |
-
return im
|
499 |
-
|
500 |
-
|
501 |
def index_to_loc_grid(idx, d):
|
502 |
if idx == 0:
|
503 |
return np.array((0., 0.), dtype=np.float32)
|
|
|
4 |
from matplotlib.collections import PatchCollection
|
5 |
|
6 |
|
|
|
7 |
def pol2car(rho, pi, xi, yi):
|
8 |
x = rho * np.cos(pi) + xi
|
9 |
y = rho * np.sin(pi) + yi
|
10 |
return (x, y)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def plot_isovist(isovists, show_axis=False, s=0.1, figsize=(5,5)):
|
13 |
#transpose the matrix
|
14 |
# isovists = np.transpose(isovists, (isovists.ndim-1, isovists.ndim-2))
|
|
|
32 |
ax.scatter(x, y, s, 'black')
|
33 |
return fig
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def isovist_to_cartesian_a(isovist, x, y, scale):
|
37 |
points = []
|
|
|
44 |
points = np.stack(points)
|
45 |
return(points)
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
def isovist_to_cartesian_segment_a(isovist, x, y, scale, max=0.98, min = 0.1, d=0.1):
|
49 |
points = []
|
|
|
79 |
return(segments)
|
80 |
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
def index_to_loc_grid(idx, d):
|
83 |
if idx == 0:
|
84 |
return np.array((0., 0.), dtype=np.float32)
|
utils/misc.py
CHANGED
@@ -1,56 +1,14 @@
|
|
1 |
import json
|
2 |
-
from os.path import join
|
3 |
import numpy as np
|
4 |
-
from PIL import Image
|
5 |
from utils.isoutil import *
|
6 |
-
import torch
|
7 |
-
import torchvision
|
8 |
import sys
|
9 |
|
10 |
|
11 |
-
class MeanTracker(object):
|
12 |
-
def __init__(self, name):
|
13 |
-
self.values = []
|
14 |
-
self.name = name
|
15 |
-
|
16 |
-
def add(self, val):
|
17 |
-
self.values.append(float(val))
|
18 |
-
|
19 |
-
def mean(self):
|
20 |
-
return np.mean(self.values)
|
21 |
-
|
22 |
-
def flush(self):
|
23 |
-
mean = self.mean()
|
24 |
-
self.values = []
|
25 |
-
return self.name, mean
|
26 |
-
|
27 |
-
def save_params(config, training_path):
|
28 |
-
save_dict_path = join(training_path, 'param.json')
|
29 |
-
with open(save_dict_path, 'w') as outfile:
|
30 |
-
json.dump(config,
|
31 |
-
outfile,
|
32 |
-
sort_keys=False,
|
33 |
-
indent=4,
|
34 |
-
separators=(',', ': '))
|
35 |
-
|
36 |
def load_params(config_file):
|
37 |
with open(config_file, 'r') as f:
|
38 |
data = json.load(f)
|
39 |
return data
|
40 |
|
41 |
-
|
42 |
-
def save_images(isovists, iter_num, title, sample_folder):
|
43 |
-
figs=[]
|
44 |
-
for i, x_ in enumerate(isovists):
|
45 |
-
x_ = np.squeeze(x_)
|
46 |
-
figs.append(plot_isovist_numpy(x_, figsize=(1,1)))
|
47 |
-
figs = torch.tensor(figs, dtype=torch.float)
|
48 |
-
nrow = int(np.sqrt(isovists.shape[0]))
|
49 |
-
im = torchvision.utils.make_grid(figs, normalize=True, range=(0, 255), nrow=nrow)
|
50 |
-
im = Image.fromarray(np.uint8(np.transpose(im.numpy(), (1, 2, 0))*255))
|
51 |
-
im.save(join(sample_folder, f'{title}_{iter_num:06}.jpg'))
|
52 |
-
|
53 |
-
|
54 |
def imshow(img):
|
55 |
npimg = img.numpy()
|
56 |
plt.figure(figsize = (30,30))
|
|
|
1 |
import json
|
|
|
2 |
import numpy as np
|
|
|
3 |
from utils.isoutil import *
|
|
|
|
|
4 |
import sys
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def load_params(config_file):
|
8 |
with open(config_file, 'r') as f:
|
9 |
data = json.load(f)
|
10 |
return data
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
def imshow(img):
|
13 |
npimg = img.numpy()
|
14 |
plt.figure(figsize = (30,30))
|