def rand_spatial_coordinates(subject_id, win_sizes, img_sizes, n_samples):
if len(set(img_size[:N_SPATIAL] for img_size in img_sizes)) > 1:
tf.logging.fatal("Don"t know how to generate sampling "
"locations: Spatial dimensions of the "
"grouped input sources are not "
"consistent. {}".format(img_sizes))
raise NotImplementedError
// find spatial window location based on the largest spatial window
spatial_win_sizes = [win_size[:N_SPATIAL] for win_size in win_sizes]
spatial_win_sizes = np.asarray(spatial_win_sizes, dtype=np.int32)
max_spatial_win = np.max(spatial_win_sizes, axis=0)
max_coords = np.zeros((n_samples, N_SPATIAL), dtype=np.int32)
for i in range(0, N_SPATIAL):
max_coords[:, i] = np.random.randint(
0, max(img_sizes[0][i] - max_spatial_win[i], 1), n_samples)
// adjust max spatial coordinates based on each spatial window size
all_coordinates = []
for win_size in spatial_win_sizes:
subject_id = np.ones((n_samples,), dtype=np.int32) * subject_id
spatial_coords = np.zeros(
(n_samples, N_SPATIAL * 2), dtype=np.int32)
// shift starting coords of the window
// so that smaller windows are centred within the large windows
half_win_diff = np.floor((max_spatial_win - win_size) / 2.0)
spatial_coords[:, :N_SPATIAL] = \
max_coords[:, :N_SPATIAL] + half_win_diff[:N_SPATIAL]
spatial_coords[:, N_SPATIAL:] = \
spatial_coords[:, :N_SPATIAL] + win_size[:N_SPATIAL]
// include the subject id
spatial_coords = np.append(
subject_id[:, None], spatial_coords, axis=1)
all_coordinates.append(spatial_coords)
return all_coordinates
// def __init__(self,
After Change
0, max(uniq_spatial_size[i] - max_spatial_win[i], 1), n_samples)
// adjust max spatial coordinates based on each spatial window size
all_coordinates = {}
for mod in list(win_sizes):
win_size = win_sizes[mod][:N_SPATIAL]
subject_id = np.ones((n_samples,), dtype=np.int32) * subject_id
spatial_coords = np.zeros(
(n_samples, N_SPATIAL * 2), dtype=np.int32)
// shift starting coords of the window
// so that smaller windows are centred within the large windows
half_win_diff = np.floor((max_spatial_win - win_size) / 2.0)
spatial_coords[:, :N_SPATIAL] = \
max_coords[:, :N_SPATIAL] + half_win_diff[:N_SPATIAL]
spatial_coords[:, N_SPATIAL:] = \
spatial_coords[:, :N_SPATIAL] + win_size[:N_SPATIAL]
// include the subject id
spatial_coords = np.append(
subject_id[:, None], spatial_coords, axis=1)
all_coordinates[mod] = spatial_coords
return all_coordinates
// def __init__(self,