I have the below Dataset and I am getting the following error while trying to access the data with dataloader,
TypeError: can’t convert np.ndarray of type numpy.object. The only supported types are: double, float, float16, int64, int32, and uint8._
Below is the code for custom dataset and dataloader
class TestDataset(Dataset):
def __init__(self, gt_file, root_dir, transform=None):
super(TestDataset, self).__init__()
self.ground_truth = pd.read_csv(gt_file, sep=";", header = None)
self.root_dir = root_dir
self.transform = transform
self.C = 3
self.W = 1360
self.H = 800
def __len__(self):
return len(self.ground_truth)
def __getitem__(self, idx):
img_name = os.path.join(self.root_dir,
self.ground_truth.iloc[idx, 0])
image = Image.open(img_name)
image = np.asarray(image).astype(np.float16)
image = image.reshape(self.C*self.W*self.H)
image = torch.from_numpy(image)
roi_points = self.ground_truth.iloc[idx, 1:-1].values.astype(np.float16)
class_id = self.ground_truth.iloc[idx, -1]
#sample = {'image': image, 'roi_points': roi_points, 'classId': [class_id]}
if self.transform is not None:
image = self.transform(image)
return image, torch.from_numpy(roi_points), torch.Tensor(np.float16(class_id))
# Dataloader call
data_transform = transforms.Compose([
transforms.ToTensor(),
])
test_data = TestDataset(gt_file='...',
root_dir='...', transform = data_transform)
dataloader = torch.utils.data.DataLoader(test_data,
batch_size=4, shuffle=True,
num_workers=1)