MCPcopy Create free account
hub / github.com/pytorch/tutorials / __getitem__

Function __getitem__

beginner_source/basics/data_tutorial.py:191–199  ·  view source on GitHub ↗
(self, idx)

Source from the content-addressed store, hash-verified

189# tensor image and corresponding label in a tuple.
190
191def __getitem__(self, idx):
192 img_path = os.path.join(self.img_dir, self.img_labels.iloc[idx, 0])
193 image = decode_image(img_path)
194 label = self.img_labels.iloc[idx, 1]
195 if self.transform:
196 image = self.transform(image)
197 if self.target_transform:
198 label = self.target_transform(label)
199 return image, label
200
201
202######################################################################

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected