Skip to content
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

Images being used with .predict() don't appear to be normalized the same way as the images pulled using get_x from the datasets (for feeding into predict_array). #535

Closed
nwertzberger opened this issue Jun 2, 2018 · 4 comments

Comments

@nwertzberger
Copy link

nwertzberger commented Jun 2, 2018

Hello,

I've been trying to track down why I get a different answer for:

learner.predict_array(dataset.val_dl.dataset.get_x(0)[None])

vs what i see in preds from running (learner.predict()) using the same dataset. I noticed the following:

  • When I look up predict_with_targs, it seems that it turns the dataloader into an iterator, and then shoves those values into the model via this:

      def predict_with_targs(m, dl):
          m.eval()
          if hasattr(m, 'reset'): m.reset()
          res = []
          for *x,y in iter(dl): res.append([get_prediction(m(*VV(x))),y])
          preda,targa = zip(*res)
          return to_np(torch.cat(preda)), to_np(torch.cat(targa))
    
  • When I pull out some data using this method, I notice that the resulting tensor is NOT normalized, but the dimensions are 3x128x128 (what my model expects):

      x = list(iter(data2.val_dl))[0]
      to_np(x[0][0,:,:,:])
      # This shows a tensor with lots of values bigger than 1 and smaller than -1
    
  • When I pull from the dataset using get_x, it IS normalized, but the dimensions are 128x128x3

Given that the other interfaces return normalized images, i think this might not be on purpose, but I'm no expert on what should or should not be normalized. I know that it not being normalized makes lime integration difficult, and, because the dimensions of the images pulled in each case is different, I have to transpose them as well, which seems awkward.

@nwertzberger nwertzberger changed the title Images being used with .predict() don't appear to be normalized. Images being used with .predict() don't appear to be normalized the same way as the images pulled using get_x from the datasets (for feeding into predict_array). Jun 4, 2018
@jph00
Copy link
Member

jph00 commented Jun 6, 2018

You should never call get_x directly. Instead just use the standard dataset indexer: dataset.val_ds[i]

@jph00 jph00 closed this as completed Jun 6, 2018
@nwertzberger
Copy link
Author

nwertzberger commented Jun 6, 2018 via email

@yanneta
Copy link

yanneta commented Jun 6, 2018 via email

@nwertzberger
Copy link
Author

nwertzberger commented Jun 6, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants