Unable to access targets when building a custom Avalanche Classification Dataset #1283
-
Hi, I have a custom dataset, for which I have written a simple class extending the Torch Dataset class class CustomDataset(Dataset):
"""Dataset generator for the Custom dataset
"""
def __init__(self,
root: str,
split: str,
transform: Optional[Callable] = None,
):
self.root = root
self.split = split
self.transform = transform
self.targets = [
int(np.load(str(self.files[x]))['label']) for x in range(len(self.files))
]
def __len__(self):
"""
Returns the size of the dataset
"""
return len(self.targets)
def __getitem__(self, idx):
"""
Returns a batch of image, heatmap, labels as Torch tensors
"""
np_image = np.load(str(self.files[idx]))['image']
processed_np_image = preprocess_input(np_image)
image = torch.from_numpy(np.transpose(processed_np_image, (2, 0, 1)))
label = self.targets[idx]
if self.transform is not None:
image = self.transform(image)
return image, label Now, I want to use the AvalancheDataset class, so I do the following def initialize_dataset(root:str, split:str):
base_ds = CustomDataset(root=root, split=split)
return make_classification_dataset(base_ds) Finally, I want to access the targets train_ds = initialize_dataset(root=root, split="train")
print(train_ds.targets) I run into:
Interestingly, if I try My end goal is to build a custom nc benchmark with this dataset. I recognize that doing so internally handles the creation of an avalanche classification dataset, but I run into a different error there, which, after some debugging, I am fairly confident has to do with the error I have shared above. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Thanks for reporting the problem. This looks like a bug in the |
Beta Was this translation helpful? Give feedback.
@niniack update: the issue seems fixed on the master branch.