pytorch / tnt

A lightweight library for PyTorch training tools and utilities
https://pytorch.org/tnt/
Other
1.66k stars 271 forks source link

Incorrect assertation in torchnet/meter/confusionmeter.py #79

Closed niaoyu closed 2 years ago

niaoyu commented 6 years ago

Incorrect assertation will shown when the target shape is 1 (means only one input per batch).

line43-44: assert predicted.shape[0] == target.shape[0], \ 'number of targets and predicted outputs do not match'

Example: image

this will cause an error in my program

Zzmonica commented 6 years ago

I have the same bug as you've proposed, wish to see the way to solve it.

alexsax commented 6 years ago

The number of targets should match the size of your batch. I'm assuming that you're using a batch size of 1? I believe that ConfusionMeter expects a prediction of the shape NxK where N is the batch size. Even when using a batch size of one, predicted and `target should be 2D arrays.

Does this fix the problem?

predicted = np.array([predicted])
target = np.array([predicted])
Zzmonica commented 6 years ago

Actually,my batch size is 1,maybe thats the problem. Thanks for your answer!