ArrayMemoryError - How should I organize input data for CNN?


I am attempting to create a convolutional neural network for a regression task that takes in two frames of a video and outputs the relative distance moved between an object that is located in both frames. To start, I have 15 different videos (.mp4), so I am looping through each video, reading each frame with OpenCV, and appending the uint8 matrix of each frame to a numpy array. Then eventually I will convert this to a tensor and split into training and validation sets.

However, in the loop of the appending each frame to the numpy array, I get an ArrayMemoryError specifying that it is “Unable to allocate 30.7 GiB for an array with shape (61649, 498, 1072) and a type uint8”.

I understand that is a lot of data in one array (and I’ve read that CNNs perform better when data is stored as Float32 instead of uint8 which increases the memory also), so is there a better way to load/save the data so not all of it has to allocated at once? If so, can I still randomly split into training and validation sets for my CNN?

I apologize if this is rudimentary - this is my first time attempting to create a deep learning model, so still trying to figure out organization techniques!

Thank you for your help! Let me know if any other information is needed to better answer this question.