Base Dataloader
MovieDataSet
Bases: Dataset
A dataset class for handling movie data and corresponding neural responses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
movies
|
Float[ndarray | Tensor, 'n_channels n_frames h w']
|
The movie data. |
required |
responses
|
Float[ndarray, 'n_frames n_neurons']
|
The neural responses. |
required |
roi_ids
|
Optional[Float[ndarray, ' n_neurons']]
|
A list of ROI IDs. |
required |
roi_coords
|
Optional[Float[ndarray, 'n_neurons 2']]
|
A list of ROI coordinates. |
required |
group_assignment
|
Optional[Float[ndarray, ' n_neurons']]
|
A list of group assignments (cell types). |
required |
split
|
Literal['train', 'validation', 'val', 'test']
|
|
required |
chunk_size
|
int
|
The size of the chunks to split the data into. |
required |
Attributes:
Name | Type | Description |
---|---|---|
samples |
tuple
|
A tuple containing movie data and neural responses. |
test_responses_by_trial |
Optional[Dict[str, Any]]
|
|
roi_ids |
Optional[Float[ndarray, ' n_neurons']]
|
A list of region of interest (ROI) IDs. |
chunk_size |
int
|
The size of the chunks to split the data into. |
mean_response |
Tensor
|
The mean response per neuron. |
group_assignment |
Optional[Float[ndarray, ' n_neurons']]
|
A list of group assignments. |
roi_coords |
Optional[Float[ndarray, 'n_neurons 2']]
|
A list of ROI coordinates. |
Methods:
Name | Description |
---|---|
__getitem__ |
Returns a DataPoint object for the given index or slice. |
movies |
Returns the movie data. |
responses |
Returns the neural responses. |
__len__ |
Returns the number of chunks of clips and responses used for training. |
__str__ |
Returns a string representation of the dataset. |
__repr__ |
Returns a string representation of the dataset. |
Source code in openretina/data_io/base_dataloader.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
MovieSampler
Bases: Sampler
A custom sampler for selecting movie frames for training, validation, or testing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_indices
|
list[int]
|
List of starting indices for the movie sections to select. |
required |
split
|
Literal['train', 'validation', 'val', 'test']
|
The type of data split. |
required |
chunk_size
|
int
|
The size of each contiguous chunk of frames to select. |
required |
movie_length
|
int
|
The total length of the movie. |
required |
scene_length
|
Optional[int]
|
The length of each scene, if the movie is divided in any scenes. Defaults to None. |
required |
allow_over_boundaries
|
bool
|
Whether to allow selected chunks to go over scene boundaries. Defaults to False. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
indices |
list[int]
|
The starting indices for the movie sections to sample. |
split |
str
|
The type of data split. |
chunk_size |
int
|
The size of each chunk of frames. |
movie_length |
int
|
The total length of the movie. |
scene_length |
int
|
The length of each scene, if the movie is made up of scenes. |
allow_over_boundaries |
bool
|
Whether to allow chunks to go over scene boundaries. |
Methods:
Name | Description |
---|---|
__iter__ |
Returns an iterator over the sampled indices. |
__len__ |
Returns the number of starting indices (which will corresponds to the number of sampled clips). |
Source code in openretina/data_io/base_dataloader.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
NeuronDataSplit
Source code in openretina/data_io/base_dataloader.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
response_dict
property
Create and return a dictionary of neural responses for train, validation, and test datasets.
__init__(responses, val_clip_idx, num_clips, clip_length, key=None, **kwargs)
Initialize the NeuronData object. Boilerplate class to compute and store neuron data train/test/validation splits before feeding into a dataloader
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
dict
|
The key information for the neuron data, includes date, exp_num, experimenter, field_id, stim_id. |
None
|
responses
|
ResponsesTrainTestSplit
|
The train and test responses of neurons. |
required |
val_clip_idx
|
List[int]
|
The indices of validation clips. |
required |
num_clips
|
int
|
The number of clips. |
required |
clip_length
|
int
|
The length of each clip. |
required |
key
|
dict
|
Additional key information. |
None
|
Source code in openretina/data_io/base_dataloader.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
split_data_train_val()
Compute validation responses and updated train responses stripped from validation clips. Can deal with unsorted validation clip indices, and parallels the way movie validation clips are handled.
Returns:
Type | Description |
---|---|
tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: The updated train and validation responses. |
Source code in openretina/data_io/base_dataloader.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
gen_shifts_with_boundaries(clip_bounds, start_indices, clip_chunk_size=50)
Generate shifted indices based on clip bounds and start indices. Assumes that the original start indices are already within the clip bounds. If they are not, it changes the overflowing indexes to respect the closest bound.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clip_bounds
|
list
|
A list of clip bounds. |
required |
start_indices
|
list
|
A list of start indices. |
required |
clip_chunk_size
|
int
|
The size of each clip chunk. Defaults to 50. |
50
|
Returns:
Name | Type | Description |
---|---|---|
list |
list[int]
|
A list of shifted indices. |
Source code in openretina/data_io/base_dataloader.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
get_movie_dataloader(movie, responses, *, split, scene_length, chunk_size, batch_size, start_indices=None, roi_ids=None, roi_coords=None, group_assignment=None, drop_last=True, allow_over_boundaries=True, **kwargs)
Create a DataLoader for processing movie data and associated responses. This function prepares the dataset and sampler for training or evaluation based on the specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
movie
|
Float[ndarray | Tensor, 'n_channels n_frames h w']
|
The movie data represented as a multi-dimensional array or tensor. |
required |
responses
|
Float[ndarray, 'n_frames n_neurons']
|
The responses corresponding to the frames of the movie. |
required |
split
|
str | Literal['train', 'validation', 'val', 'test']
|
The dataset split to use (train, validation, or test). |
required |
scene_length
|
int
|
The length of the scene to be processed. |
required |
chunk_size
|
int
|
The size of each chunk to be extracted from the movie. |
required |
batch_size
|
int
|
The number of samples per batch. |
required |
start_indices
|
list[int] | None
|
The starting indices for each chunk. If None, will be computed. |
None
|
roi_ids
|
Float[ndarray, ' n_neurons'] | None
|
The region of interest IDs. If None, will not be used. |
None
|
roi_coords
|
Float[ndarray, 'n_neurons 2'] | None
|
The coordinates of the regions of interest. If None, will not be used. |
None
|
group_assignment
|
Float[ndarray, ' n_neurons'] | None
|
The group assignments (cell types) for the neurons. If None, will not be used. |
None
|
drop_last
|
bool
|
Whether to drop the last incomplete batch. Defaults to True. |
True
|
allow_over_boundaries
|
bool
|
Whether to allow chunks that exceed the scene boundaries. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments for the DataLoader. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
DataLoader |
DataLoader
|
A DataLoader instance configured with the specified dataset and sampler. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in openretina/data_io/base_dataloader.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
handle_missing_start_indices(movie_length, chunk_size, scene_length, split)
Handle missing start indices for different splits of the dataset.
Parameters: movies (np.ndarray or torch.Tensor): The movies data, as an array. chunk_size (int or None): The size of each chunk for training split. Required if split is "train". scene_length (int or None): The length of each scene. Required if split is "validation" or "val". split (str): The type of split, one of "train", "validation", "val", or "test".
Returns: dict or list: The generated or provided start indices for each movie.
Raises: AssertionError: If chunk_size is not provided for training split when start_indices is None. AssertionError: If scene_length is not provided for validation split when start_indices is None. NotImplementedError: If start_indices is None and split is not one of "train", "validation", "val", or "test".
Source code in openretina/data_io/base_dataloader.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
multiple_movies_dataloaders(neuron_data_dictionary, movies_dictionary, train_chunk_size=50, batch_size=32, seed=42, clip_length=100, num_val_clips=10, val_clip_indices=None, allow_over_boundaries=True)
Create multiple dataloaders for training, validation, and testing from given neuron and movie data. This function ensures that the neuron data and movie data are aligned and generates dataloaders for each session. It does not make assumptions about the movies in different sessions to be the same, the same length, composed of the same clips or in the same order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
neuron_data_dictionary
|
dict[str, ResponsesTrainTestSplit]
|
A dictionary containing neuron response data split for training and testing. |
required |
movies_dictionary
|
dict[str, MoviesTrainTestSplit]
|
A dictionary containing movie data split for training and testing. |
required |
train_chunk_size
|
int
|
The size of the chunks for training data. Defaults to 50. |
50
|
batch_size
|
int
|
The number of samples per batch. Defaults to 32. |
32
|
seed
|
int
|
The random seed for reproducibility. Defaults to 42. |
42
|
clip_length
|
int
|
The length of each clip. Defaults to 100. |
100
|
num_val_clips
|
int
|
The number of validation clips to draw. Defaults to 10. |
10
|
val_clip_indices
|
list[int]
|
The indices of validation clips to use. If provided, num_val_clips is ignored. Defaults to None. |
None
|
allow_over_boundaries
|
bool
|
Whether to allow selected chunks to go over scene boundaries. |
True
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict[str, dict[str, DataLoader]]
|
A dictionary containing dataloaders for training, validation, and testing for each session. |
Raises:
Type | Description |
---|---|
AssertionError
|
If the keys of neuron_data_dictionary and movies_dictionary do not match exactly. |
Source code in openretina/data_io/base_dataloader.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
|