MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / gen_stack_patches

Function gen_stack_patches

tensorpack/utils/viz.py:206–262  ·  view source on GitHub ↗

Similar to :func:`stack_patches` but with a generator interface. It takes a much-longer list and yields stacked results one by one. For example, if ``patch_list`` contains 1000 images and ``nr_row==nr_col==10``, this generator yields 10 stacked images. Args: nr_row(int)

(patch_list,
                      nr_row=None, nr_col=None, border=None,
                      max_width=1000, max_height=1000,
                      bgcolor=255, viz=False, lclick_cb=None)

Source from the content-addressed store, hash-verified

204
205
206def gen_stack_patches(patch_list,
207 nr_row=None, nr_col=None, border=None,
208 max_width=1000, max_height=1000,
209 bgcolor=255, viz=False, lclick_cb=None):
210 """
211 Similar to :func:`stack_patches` but with a generator interface.
212 It takes a much-longer list and yields stacked results one by one.
213 For example, if ``patch_list`` contains 1000 images and ``nr_row==nr_col==10``,
214 this generator yields 10 stacked images.
215
216 Args:
217 nr_row(int), nr_col(int): rows and cols of each result.
218 max_width(int), max_height(int): Maximum allowed size of the
219 stacked image. If ``nr_row/nr_col`` are None, this number
220 will be used to infer the rows and cols. Otherwise the option is
221 ignored.
222 patch_list, border, viz, lclick_cb: same as in :func:`stack_patches`.
223
224 Yields:
225 np.ndarray: the stacked image.
226 """
227 # setup parameters
228 patch_list = _preprocess_patch_list(patch_list)
229 if lclick_cb is not None:
230 viz = True
231 ph, pw = patch_list.shape[1:3]
232
233 if border is None:
234 border = int(0.05 * min(ph, pw))
235 if nr_row is None:
236 nr_row = int(max_height / (ph + border))
237 if nr_col is None:
238 nr_col = int(max_width / (pw + border))
239 canvas = Canvas(ph, pw, nr_row, nr_col, patch_list.shape[-1], border, bgcolor)
240
241 nr_patch = nr_row * nr_col
242 start = 0
243
244 if lclick_cb is not None:
245 def lclick_callback(img, x, y):
246 idx = canvas.get_patchid_from_coord(x, y)
247 idx = idx + start
248 if idx < end:
249 lclick_cb(patch_list[idx], idx)
250 else:
251 lclick_callback = None
252
253 while True:
254 end = start + nr_patch
255 cur_list = patch_list[start:end]
256 if not len(cur_list):
257 return
258 canvas.draw_patches(cur_list)
259 if viz:
260 interactive_imshow(canvas.canvas, lclick_cb=lclick_callback)
261 yield canvas.canvas
262 start = end
263

Callers 1

viz.pyFile · 0.85

Calls 4

draw_patchesMethod · 0.95
_preprocess_patch_listFunction · 0.85
CanvasClass · 0.85
interactive_imshowFunction · 0.85

Tested by

no test coverage detected