Skip to content

Instantly share code, notes, and snippets.

@BloodAxe
Created June 9, 2020 11:04
Show Gist options
  • Save BloodAxe/0f87be23904761cfbf13b327de54e0af to your computer and use it in GitHub Desktop.
Save BloodAxe/0f87be23904761cfbf13b327de54e0af to your computer and use it in GitHub Desktop.
class RAMDataset(Dataset):
def __init__(image_fnames, targets):
self.targets = targets
self.images = []
for fname in tqdm(image_fnames, desc="Loading files in RAM"):
with open(fname, "rb") as f:
self.images.append(f.read())
def __len__(self):
return len(self.targets)
def __getitem__(self, index):
target = self.targets[index]
image, retval = cv2.imdecode(self.images[index], cv2.IMREAD_COLOR)
return image, target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment