Skip to content

Commit

Permalink
re-import internal; fix missing tile_images.py (#427)
Browse files Browse the repository at this point in the history
* import rl-algs from 2e3a166 commit

* extra import of the baselines badge

* exported commit with identity test

* proper rng seeding in the test_identity

* import internal

* adding missing tile_images.py
  • Loading branch information
pzhokhov authored Jun 8, 2018
1 parent 36ee5d1 commit a6b1bc7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions baselines/common/tile_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np

def tile_images(img_nhwc):
"""
Tile N images into one big PxQ image
(P,Q) are chosen to be as close as possible, and if N
is square, then P=Q.
input: img_nhwc, list or array of images, ndim=4 once turned into array
n = batch index, h = height, w = width, c = channel
returns:
bigim_HWc, ndarray with ndim=3
"""
img_nhwc = np.asarray(img_nhwc)
N, h, w, c = img_nhwc.shape
H = int(np.ceil(np.sqrt(N)))
W = int(np.ceil(float(N)/H))
img_nhwc = np.array(list(img_nhwc) + [img_nhwc[0]*0 for _ in range(N, H*W)])
img_HWhwc = img_nhwc.reshape(H, W, h, w, c)
img_HhWwc = img_HWhwc.transpose(0, 2, 1, 3, 4)
img_Hh_Ww_c = img_HhWwc.reshape(H*h, W*w, c)
return img_Hh_Ww_c

0 comments on commit a6b1bc7

Please sign in to comment.