def vol_sr_slices(volpath, nb_input_slices, nb_slice_spacing, batch_size=1, ext='.npz', vol_rand_seed=None, nb_restart_cycle=None, name='vol_sr_slices', rand_slices=True, simulate_whole_sparse_vol=False, verbose=False):
    '\n    default generator for slice-wise super resolution\n    '

    def indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing):
        idx = start_indices[0]
        output_batch = np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol)], 0)
        input_batch = np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol):(nb_slice_spacing + 1)], 0)
        for idx in start_indices[1:]:
            out_sel = np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol)], 0)
            output_batch = np.vstack([output_batch, out_sel])
            input_batch = np.vstack([input_batch, np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol):(nb_slice_spacing + 1)], 0)])
        output_batch = np.reshape(output_batch, [batch_size, (- 1), output_batch.shape[(- 1)]])
        return (input_batch, output_batch)
    print('vol_sr_slices: SHOULD PROPERLY RANDOMIZE accross different subjects', file=sys.stderr)
    volfiles = _get_file_list(volpath, ext, vol_rand_seed)
    nb_files = len(volfiles)
    if (nb_restart_cycle is None):
        nb_restart_cycle = nb_files
    nb_slices_in_subvol = (((nb_input_slices - 1) * (nb_slice_spacing + 1)) + 1)
    fileidx = (- 1)
    while 1:
        fileidx = np.mod((fileidx + 1), nb_restart_cycle)
        if (verbose and (fileidx == 0)):
            print(('starting %s cycle' % name))
        try:
            vol_data = _load_medical_volume(os.path.join(volpath, volfiles[fileidx]), ext, verbose)
        except:
            debug_error_msg = '#files: %d, fileidx: %d, nb_restart_cycle: %d. error: %s'
            print((debug_error_msg % (len(volfiles), fileidx, nb_restart_cycle, sys.exc_info()[0])))
            raise
        nb_slices = vol_data.shape[2]
        nb_start_slices = ((nb_slices - nb_slices_in_subvol) + 1)
        if simulate_whole_sparse_vol:
            init_slice = 0
            if rand_slices:
                init_slice = np.random.randint(0, high=(nb_start_slices - 1))
            all_start_indices = list(range(init_slice, nb_start_slices, (nb_slice_spacing + 1)))
            for batch_start in range(0, len(all_start_indices), (batch_size * (nb_input_slices - 1))):
                start_indices = [all_start_indices[s] for s in range(batch_start, (batch_start + batch_size))]
                (input_batch, output_batch) = indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing)
                (yield (input_batch, output_batch))
        elif rand_slices:
            assert (not simulate_whole_sparse_vol)
            start_indices = np.random.choice(range(nb_start_slices), size=batch_size, replace=False)
            (input_batch, output_batch) = indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing)
            (yield (input_batch, output_batch))
        else:
            for batch_start in range(0, nb_start_slices, batch_size):
                start_indices = list(range(batch_start, (batch_start + batch_size)))
                (input_batch, output_batch) = indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing)
                (yield (input_batch, output_batch))
default generator for slice-wise super resolution
def vol_sr_slices(volpath, nb_input_slices, nb_slice_spacing, batch_size=1, ext='.npz', vol_rand_seed=None, nb_restart_cycle=None, name='vol_sr_slices', rand_slices=True, simulate_whole_sparse_vol=False, verbose=False):
    '\n    \n    '

    def indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing):
        idx = start_indices[0]
        output_batch = np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol)], 0)
        input_batch = np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol):(nb_slice_spacing + 1)], 0)
        for idx in start_indices[1:]:
            out_sel = np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol)], 0)
            output_batch = np.vstack([output_batch, out_sel])
            input_batch = np.vstack([input_batch, np.expand_dims(vol_data[:, :, idx:(idx + nb_slices_in_subvol):(nb_slice_spacing + 1)], 0)])
        output_batch = np.reshape(output_batch, [batch_size, (- 1), output_batch.shape[(- 1)]])
        return (input_batch, output_batch)
    print('vol_sr_slices: SHOULD PROPERLY RANDOMIZE accross different subjects', file=sys.stderr)
    volfiles = _get_file_list(volpath, ext, vol_rand_seed)
    nb_files = len(volfiles)
    if (nb_restart_cycle is None):
        nb_restart_cycle = nb_files
    nb_slices_in_subvol = (((nb_input_slices - 1) * (nb_slice_spacing + 1)) + 1)
    fileidx = (- 1)
    while 1:
        fileidx = np.mod((fileidx + 1), nb_restart_cycle)
        if (verbose and (fileidx == 0)):
            print(('starting %s cycle' % name))
        try:
            vol_data = _load_medical_volume(os.path.join(volpath, volfiles[fileidx]), ext, verbose)
        except:
            debug_error_msg = '#files: %d, fileidx: %d, nb_restart_cycle: %d. error: %s'
            print((debug_error_msg % (len(volfiles), fileidx, nb_restart_cycle, sys.exc_info()[0])))
            raise
        nb_slices = vol_data.shape[2]
        nb_start_slices = ((nb_slices - nb_slices_in_subvol) + 1)
        if simulate_whole_sparse_vol:
            init_slice = 0
            if rand_slices:
                init_slice = np.random.randint(0, high=(nb_start_slices - 1))
            all_start_indices = list(range(init_slice, nb_start_slices, (nb_slice_spacing + 1)))
            for batch_start in range(0, len(all_start_indices), (batch_size * (nb_input_slices - 1))):
                start_indices = [all_start_indices[s] for s in range(batch_start, (batch_start + batch_size))]
                (input_batch, output_batch) = indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing)
                (yield (input_batch, output_batch))
        elif rand_slices:
            assert (not simulate_whole_sparse_vol)
            start_indices = np.random.choice(range(nb_start_slices), size=batch_size, replace=False)
            (input_batch, output_batch) = indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing)
            (yield (input_batch, output_batch))
        else:
            for batch_start in range(0, nb_start_slices, batch_size):
                start_indices = list(range(batch_start, (batch_start + batch_size)))
                (input_batch, output_batch) = indices_to_batch(vol_data, start_indices, nb_slices_in_subvol, nb_slice_spacing)
                (yield (input_batch, output_batch))