chainer / chainercv

ChainerCV: a Library for Deep Learning in Computer Vision
MIT License
1.48k stars 306 forks source link

Honor the original data type in resize #928

Closed sergeant-wizard closed 4 years ago

sergeant-wizard commented 4 years ago

Hello I think this is a cool project.

I came across what looked like a bug when I was running the example for PSP:

https://github.com/chainer/chainercv/blob/b4647d3960d3e1e66834036c9f386a964813d5a6/examples/pspnet/train_multi.py#L96

specifically, numpy.unique(label) here would only output [-1 ,0], where more classes should be preserved after the resize.

The offending test case is added in this PR as test_resize_labels, in which an array of int type is passed to the resize method.

The fix is to use the default mode specified by PIL which will determine the mode automatically from the given data.

You may also decide to accept only float types for the resize method. In that case the PSP example needs a bug fix like transforms.resize(labels.astype(np.float32), and I would assert against violating types in the resize method.