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

Implementation of DoubleColoredMNIST #2

Closed
gessha opened this issue May 11, 2021 · 1 comment
Closed

Implementation of DoubleColoredMNIST #2

gessha opened this issue May 11, 2021 · 1 comment

Comments

@gessha
Copy link

gessha commented May 11, 2021

Hi!

Thank you so much for posting your code online! I was really fascinated by your work and I presented it recently at the computer vision seminar at Stony Brook University.

I was tinkering with the implementation of DoubleColoredMNIST because I want to use it in a related project and I noticed something strange: In the class implementation, colors are assigned to global tensors and every time an image is requested, the global color tensors get jittered instead of jittering a local copy. Is this the intended implementation or is this something unintended?

Reproduction code:

ds = DoubleColoredMNIST(train=True)

print(ds.background_colors[5].view(1, 3), ds.object_colors[5].view(1, 3))
# -> tensor([[0.8706, 0.7216, 0.5294]]) tensor([[0.3922, 0.5843, 0.9294]])

first_image = ds[0]
image, label = first_image['ims'], first_image['labels']

print(ds.background_colors[5].view(1, 3), ds.object_colors[5].view(1, 3))
# -> tensor([[0.8725, 0.7374, 0.5306]]) tensor([[0.3945, 0.5922, 0.9359]])

If you can notice, the tensors between the two calls get changed.

This issue comes from line 87 and line 91 in mnists/dataloader.py where I assume the intended action is to copy the color tensor. What happens instead is the local variables back_color and obj_color refer to the global color tensors and they get jittered instead.

# line 87:
back_color = self.background_colors[i]
...

# line 91:
obj_color = self.object_colors[i]

If you add .clone() to the end of assignment, you will avoid this problem.

# line 87:
back_color = self.background_colors[i].clone()

Let me know if this is actually a bug or feature of the implementation 😅

@xl-sr
Copy link
Contributor

xl-sr commented May 13, 2021

hey, thanks for your question and good catch! Somehow this clone got lost, it used to be there ... It should not change the end results, but jittering it locally is the intended behavior. The code is updated, thanks for spotting this bug :)

@xl-sr xl-sr closed this as completed May 13, 2021
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

2 participants