Commit 00fdb263 authored by Yuxin Wu's avatar Yuxin Wu

refactor in viz. stack_patches now handles nonuniform patches as well.

parent d6a89f0b
...@@ -125,7 +125,7 @@ def sample(model_path): ...@@ -125,7 +125,7 @@ def sample(model_path):
pred = SimpleDatasetPredictor(pred, ds) pred = SimpleDatasetPredictor(pred, ds)
for o in pred.get_result(): for o in pred.get_result():
o = o[0] * 255.0 o = o[0] * 255.0
viz = next(build_patch_list(o, nr_row=10, nr_col=10)) viz = stack_patches(o, nr_row=10, nr_col=10)
viz = cv2.resize(viz, (800, 800)) viz = cv2.resize(viz, (800, 800))
interactive_imshow(viz) interactive_imshow(viz)
......
...@@ -121,7 +121,7 @@ def sample(model_path): ...@@ -121,7 +121,7 @@ def sample(model_path):
o, zs = o[0] + 1, o[1] o, zs = o[0] + 1, o[1]
o = o * 128.0 o = o * 128.0
o = o[:, :, :, ::-1] o = o[:, :, :, ::-1]
viz = next(build_patch_list(o, nr_row=10, nr_col=10, viz=True)) viz = stack_patches(o, nr_row=10, nr_col=10, viz=True)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -196,7 +196,7 @@ def sample(datadir, model_path): ...@@ -196,7 +196,7 @@ def sample(datadir, model_path):
pred = SimpleDatasetPredictor(pred, ds) pred = SimpleDatasetPredictor(pred, ds)
for o in pred.get_result(): for o in pred.get_result():
o = o[0][:, :, :, ::-1] o = o[0][:, :, :, ::-1]
next(build_patch_list(o, nr_row=3, nr_col=2, viz=True)) stack_patches(o, nr_row=3, nr_col=2, viz=True)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -192,24 +192,24 @@ def sample(model_path): ...@@ -192,24 +192,24 @@ def sample(model_path):
z_noise = np.random.uniform(-1, 1, (100, NOISE_DIM)) z_noise = np.random.uniform(-1, 1, (100, NOISE_DIM))
zc = np.concatenate((z_cat, z_uni * 0, z_uni * 0), axis=1) zc = np.concatenate((z_cat, z_uni * 0, z_uni * 0), axis=1)
o = pred(zc, z_noise)[0] o = pred(zc, z_noise)[0]
viz1 = next(build_patch_list(o, nr_row=10, nr_col=10)) viz1 = stack_patches(o, nr_row=10, nr_col=10)
viz1 = cv2.resize(viz1, (IMG_SIZE, IMG_SIZE)) viz1 = cv2.resize(viz1, (IMG_SIZE, IMG_SIZE))
# show effect of first continous variable with fixed noise # show effect of first continous variable with fixed noise
zc = np.concatenate((z_cat, z_uni, z_uni * 0), axis=1) zc = np.concatenate((z_cat, z_uni, z_uni * 0), axis=1)
o = pred(zc, z_noise * 0)[0] o = pred(zc, z_noise * 0)[0]
viz2 = next(build_patch_list(o, nr_row=10, nr_col=10)) viz2 = stack_patches(o, nr_row=10, nr_col=10)
viz2 = cv2.resize(viz2, (IMG_SIZE, IMG_SIZE)) viz2 = cv2.resize(viz2, (IMG_SIZE, IMG_SIZE))
# show effect of second continous variable with fixed noise # show effect of second continous variable with fixed noise
zc = np.concatenate((z_cat, z_uni * 0, z_uni), axis=1) zc = np.concatenate((z_cat, z_uni * 0, z_uni), axis=1)
o = pred(zc, z_noise * 0)[0] o = pred(zc, z_noise * 0)[0]
viz3 = next(build_patch_list(o, nr_row=10, nr_col=10)) viz3 = stack_patches(o, nr_row=10, nr_col=10)
viz3 = cv2.resize(viz3, (IMG_SIZE, IMG_SIZE)) viz3 = cv2.resize(viz3, (IMG_SIZE, IMG_SIZE))
viz = next(build_patch_list( viz = stack_patches(
[viz1, viz2, viz3], [viz1, viz2, viz3],
nr_row=1, nr_col=3, border=5, bgcolor=(255, 0, 0))) nr_row=1, nr_col=3, border=5, bgcolor=(255, 0, 0))
interactive_imshow(viz) interactive_imshow(viz)
......
...@@ -124,7 +124,7 @@ class AccumGradOptimizer(ProxyOptimizer): ...@@ -124,7 +124,7 @@ class AccumGradOptimizer(ProxyOptimizer):
An optimizer which accumulates gradients across :math:`k` :meth:`minimize` calls, An optimizer which accumulates gradients across :math:`k` :meth:`minimize` calls,
and apply them together in every :math:`k`th :meth:`minimize` call. and apply them together in every :math:`k`th :meth:`minimize` call.
This is equivalent to using a :math:`k` times larger batch size plus a This is equivalent to using a :math:`k` times larger batch size plus a
:math:`k` times larger learning rate, but use much less memory. :math:`k` times larger learning rate, but uses much less memory.
""" """
def __init__(self, opt, niter): def __init__(self, opt, niter):
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment