Skip to content

Dictionary-based transformation for same transforms on images and labels #2827

Answered by rijobro
elahe-badali asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, every time you access an element in the dataset, the transforms will be randomised. Hence, in this code snippet:

img = train_dataset[sample_num]['image'].squeeze(0)
lbl = train_dataset[sample_num]['label'].squeeze(0)

there is a different random state between the img and lbl, and therefore different transforms are applied to them. If you instead do:

data = train_dataset[sample_num] 
img = data['image'].squeeze(0)
lbl = data['label'].squeeze(0)

this will hopefully sort your problem.

Replies: 1 comment 15 replies

Comment options

You must be logged in to vote
15 replies
@elahe-badali
Comment options

@rijobro
Comment options

@elahe-badali
Comment options

@rijobro
Comment options

@elahe-badali
Comment options

Answer selected by elahe-badali
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants