def patch(vol_data, patch_size, patch_stride=1, nb_labels_reshape=1, keep_vol_size=False, batch_size=1, collapse_2d=None, patch_rand=False, patch_rand_seed=None, variable_batch_size=False, infinite=False):
    '\n    generate patches from volume for keras package\n\n    Yields:\n        patch: nd array of shape [batch_size, *patch_size], unless resized via nb_labels_reshape\n    '
    assert (batch_size >= 1), 'batch_size should be at least 1'
    if (patch_size is None):
        patch_size = vol_data.shape
    for (pi, p) in enumerate(patch_size):
        if (p is None):
            patch_size[pi] = vol_data.shape[pi]
    batch_idx = (- 1)
    if variable_batch_size:
        batch_size = (yield)
    while True:
        gen = pl.patch_gen(vol_data, patch_size, stride=patch_stride, rand=patch_rand, rand_seed=patch_rand_seed)
        empty_gen = True
        for lpatch in gen:
            empty_gen = False
            lpatch = _categorical_prep(lpatch, nb_labels_reshape, keep_vol_size, patch_size)
            if (collapse_2d is not None):
                lpatch = np.squeeze(lpatch, (collapse_2d + 1))
            if (batch_idx == (- 1)):
                if (batch_size == 1):
                    patch_data_batch = lpatch
                else:
                    patch_data_batch = np.zeros([batch_size, *lpatch.shape[1:]])
                    patch_data_batch[0, :] = lpatch
            else:
                patch_data_batch[(batch_idx + 1), :] = lpatch
            batch_idx += 1
            if (batch_idx == (batch_size - 1)):
                batch_idx = (- 1)
                batch_size_y = (yield patch_data_batch)
                if variable_batch_size:
                    batch_size = batch_size_y
        assert (not empty_gen), ('generator was empty. vol size was %s' % ''.join([('%d ' % d) for d in vol_data.shape]))
        if (not infinite):
            if (batch_idx >= 0):
                patch_data_batch = patch_data_batch[:(batch_idx + 1), :]
                (yield patch_data_batch)
            break
generate patches from volume for keras package

Yields:
    patch: nd array of shape [batch_size, *patch_size], unless resized via nb_labels_reshape
def patch(vol_data, patch_size, patch_stride=1, nb_labels_reshape=1, keep_vol_size=False, batch_size=1, collapse_2d=None, patch_rand=False, patch_rand_seed=None, variable_batch_size=False, infinite=False):
    '\n    generate patches from volume for keras package\n\n    Yields:\n        patch: nd array of shape [batch_size, *patch_size], unless resized via nb_labels_reshape\n    '
    assert (batch_size >= 1), 'batch_size should be at least 1'
    if (patch_size is None):
        patch_size = vol_data.shape
    for (pi, p) in enumerate(patch_size):
        if (p is None):
            patch_size[pi] = vol_data.shape[pi]
    batch_idx = (- 1)
    if variable_batch_size:
        batch_size = (yield)
    while True:
        gen = pl.patch_gen(vol_data, patch_size, stride=patch_stride, rand=patch_rand, rand_seed=patch_rand_seed)
        empty_gen = True
        for lpatch in gen:
            empty_gen = False
            lpatch = _categorical_prep(lpatch, nb_labels_reshape, keep_vol_size, patch_size)
            if (collapse_2d is not None):
                lpatch = np.squeeze(lpatch, (collapse_2d + 1))
            if (batch_idx == (- 1)):
                if (batch_size == 1):
                    patch_data_batch = lpatch
                else:
                    patch_data_batch = np.zeros([batch_size, *lpatch.shape[1:]])
                    patch_data_batch[0, :] = lpatch
            else:
                patch_data_batch[(batch_idx + 1), :] = lpatch
            batch_idx += 1
            if (batch_idx == (batch_size - 1)):
                batch_idx = (- 1)
                batch_size_y = (yield patch_data_batch)
                if variable_batch_size:
                    batch_size = batch_size_y
        assert (not empty_gen), ('generator was empty. vol size was %s' % .join([('%d ' % d) for d in vol_data.shape]))
        if (not infinite):
            if (batch_idx >= 0):
                patch_data_batch = patch_data_batch[:(batch_idx + 1), :]
                (yield patch_data_batch)
            break