I am attempting to train with my custom dataset which has the following value for numeric_hierarchy.
I double-checked I modified train.csv, test.csv, metafile, level_dict.py, and load_dataset.py for my needs.
{
0: [0, 1, 2, 3, 4, 5],
1: [6, 7, 8, 9],
2: [10, 11, 12, 13, 14],
3: [15, 16, 17, 18]
}
However, I am getting random KeyError in the bool_tensor portion of check_hierarchy() below.
def check_hierarchy(self, current_level, previous_level):
'''Check if the predicted class at level l is a children of the class predicted at level l-1 for the entire batch.
'''
#check using the dictionary whether the current level's prediction belongs to the superclass (prediction from the prev layer)
bool_tensor = [not current_level[i] in self.numeric_hierarchy[previous_level[i].item()] for i in range(previous_level.size()[0])]
return torch.FloatTensor(bool_tensor).to(self.device)
Traceback (most recent call last):
File "train.py", line 88, in <module>
dloss = HLN.calculate_dloss(prediction, [batch_y1, batch_y2])
File "/root/fashion-effnet/hier-resnet/model/hierarchical_loss.py", line 69, in calculate_dloss
D_l = self.check_hierarchy(current_lvl_pred, prev_lvl_pred)
File "/root/fashion-effnet/hier-resnet/model/hierarchical_loss.py", line 42, in check_hierarchy
bool_tensor = [not current_level[i] in self.numeric_hierarchy[previous_level[i].item()] for i in range(previous_level.size()[0])]
File "/root/fashion-effnet/hier-resnet/model/hierarchical_loss.py", line 42, in <listcomp>
bool_tensor = [not current_level[i] in self.numeric_hierarchy[previous_level[i].item()] for i in range(previous_level.size()[0])]
KeyError: 6
The value of KeyError changes every time (4, 9, 14, etc) and I can't make sense of it on how to fix this issue. Would really appreciate if anyone can provide help or insights!