I’m running the data loader below which applies a filter to a microscopy image prior to training. In order to count the red and green. This code filters the red cells. Since I have applied this to the code I keep on getting the error message above. I have tried increasing the memory allocation to the maximum allowance possible but that didn’t help. Is there a way I could modify the filter so it isn’t causing this issue, please? Many thanks in advance
import os
import numpy as np
import torch
from PIL import Image
from torch.utils.data import Dataset
from torchvision import transforms, utils
#from torchvision.transforms import Grayscalei
import pandas as pd
import pdb
import cv2
class CellsDataset(Dataset):
# a very simple dataset
def __init__(self, root_dir, transform=None, return_filenames=False):
self.root = root_dir
self.transform = transform
self.return_filenames = return_filenames
self.files = [os.path.join(self.root,filename) for filename in os.listdir(self.root)]
self.files = [path for path in self.files
if os.path.isfile(path) and os.path.splitext(path)[1]=='.png']
def __len__(self):
return len(self.files)
def __getitem__(self, idx):
path = self.files[idx]
image = cv2.imread(path)
sample = image.copy()
# set blue and green channels to 0
sample[:, :, 0] = 0
sample[:, :, 1] = 0
channel.
if self.transform:
sample = self.transform(sample)
if self.return_filenames:
return sample, path
else: