davidtvs / PyTorch-ENet

PyTorch implementation of ENet
MIT License
389 stars 129 forks source link

Ignore index is not looping over indices #38

Closed HansBambel closed 4 years ago

HansBambel commented 4 years ago

Hey! First of all: Thank you for the repository! I have been looking for quite a while to get a nice (performant) way to calculate the meanIoU over batches.

I noticed that in iou.py you are looping ofer the indices that you want to set to 0, but you don't use the looping variable:

 for index in self.ignore_index:
    conf_matrix[:, self.ignore_index] = 0
    conf_matrix[self.ignore_index, :] = 0

It should be this instead, right?

 for index in self.ignore_index:
    conf_matrix[:, index] = 0
    conf_matrix[index, :] = 0
davidtvs commented 4 years ago

Hey Ya, that's a mistake. But it turns out that it still works as expected due to numpy's fancy/advanced indexing; turn out the for loop is not even needed the code can be simply:

conf_matrix[:, self.ignore_index] = 0
conf_matrix[self.ignore_index, :] = 0

self.ignore_index is always a tuple and fancy indexing will select the rows/columns inside the tuple.

Thanks for bringing it up! I removed the loop from the code.