|
64 | 64 | from voxelwise_tutorials.io import load_hdf5_array |
65 | 65 |
|
66 | 66 |
|
67 | | -def compute_luminance(run_name, size=(96, 96)): |
| 67 | +def compute_luminance(run_name, size=(96, 96), batch_size=100): |
68 | 68 |
|
69 | 69 | stimuli_file = os.path.join(directory, 'stimuli', run_name) |
70 | 70 |
|
71 | | - # get the list of batches in the stimuli file |
| 71 | + # get the number of images in the stimuli file |
72 | 72 | with h5py.File(stimuli_file, 'r') as f: |
73 | | - keys = list(f.keys()) |
74 | | - keys.sort() # sort the batches |
| 73 | + n_images = f['stimuli'].shape[0] |
75 | 74 |
|
76 | 75 | # compute the luminance on each batch |
77 | | - luminance = [] |
78 | | - for key in bar(keys, title=f'compute_luminance({run_name})'): |
| 76 | + luminance = np.zeros((n_images, *size)) |
| 77 | + for start in bar(range(0, n_images, batch_size), |
| 78 | + title=f'compute_luminance({run_name})'): |
79 | 79 | # load the batch of images |
80 | | - images = load_hdf5_array(stimuli_file, key=key) |
| 80 | + batch = slice(start, start + batch_size) |
| 81 | + images = load_hdf5_array(stimuli_file, key='stimuli', slice=batch) |
81 | 82 |
|
82 | 83 | # ``imagearray2luminance`` uses uint8 arrays |
83 | 84 | if images.dtype != 'uint8': |
84 | 85 | images = np.int_(np.clip(images, 0, 1) * 255).astype(np.uint8) |
85 | 86 |
|
86 | 87 | # convert RGB images to a single luminance channel |
87 | | - luminance.append(imagearray2luminance(images, size=size)) |
| 88 | + luminance[batch] = imagearray2luminance(images, size=size) |
88 | 89 |
|
89 | | - return np.concatenate(luminance) |
| 90 | + return luminance |
90 | 91 |
|
91 | 92 |
|
92 | 93 | luminance_train = np.concatenate( |
@@ -161,7 +162,8 @@ def compute_motion_energy(luminance, |
161 | 162 |
|
162 | 163 | save_hdf5_dataset( |
163 | 164 | os.path.join(features_directory, "motion_energy_recomputed.hdf"), |
164 | | - dataset=dict(X_train=motion_energy_train, X_test=motion_energy_test)) |
| 165 | + dataset=dict(X_train=motion_energy_train, X_test=motion_energy_test, |
| 166 | + run_onsets=np.arange(0, 3600, 300))) |
165 | 167 |
|
166 | 168 | ############################################################################### |
167 | 169 | # References |
|
0 commit comments