-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
image.scale vs OpenCV resize #188
Comments
@achalddave it looks like one of them uses "floor" to determine some sizes, and the other uses "ceil". |
i dont think we explicitly tried to match opencv, so this is probably expected |
👍 It seemed to throw off the relative rankings of class labels from a pretrained network, so I figured I'd check. I suppose anyone trying to replicate a Caffe model's results exactly can always use the torch opencv library. |
was it a HUGE difference, or was it minor? :) |
I want to say it's minor. I ran the network on images loaded using OpenCV and using Torch. In both cases, I used the image library's 'crop' function. The top 10 categories look relatively different, but their scores are all fairly low (<0.08 [not shown in output below]), so that might be why.
|
Adversarial sample by size flooring :P |
This might be more relevant now. |
@senthilps8 if you look at the image after cv2 resize, you might see that it is scaled very differently than the image out of image.scale. Just do this for both images: print(img.mean(), img.std(), img.min(), img.max()) Try renormalize the image out of cv2.resize to have the same range as the one out of image.scale. |
@soumith Are you referring to the difference of torch image belonging to [0,1] and cv2 images belonging to [0,255]? If so, I forgot to mention that I divide the cv2 images by 255.0 for normalizing. If not, is there a normalization step in image.scale that I'm not aware of? Here's a snippet of the preprocessing I use for cv2 (I've also tried all the other modes of interpolation). iminput = cv2.imread(imPath);
iminput = cv2.resize(iminput, (inputSize,inputSize), interpolation=cv2.INTER_LINEAR)
iminput = iminput.swapaxes(0,2).swapaxes(1,2)
iminput = (iminput/255.0)*2.0 - 1
iminput = iminput[-1::-1,:,:] Also, I did try printing out the min, max, etc as you suggested. |
It seems that OpenCV and this library's resize methods give different results, even though both use bilinear interpolation by default. It may be useful to point this out if this is expected.
I posted code and the example images in this Gist: https://gist.github.com/achalddave/d9e7a6416996c648c6e75355e3f87df1
The text was updated successfully, but these errors were encountered: