MCPcopy Index your code
hub / github.com/openai/guided-diffusion / __getitem__

Method __getitem__

guided_diffusion/image_datasets.py:103–123  ·  view source on GitHub ↗
(self, idx)

Source from the content-addressed store, hash-verified

101 return len(self.local_images)
102
103 def __getitem__(self, idx):
104 path = self.local_images[idx]
105 with bf.BlobFile(path, "rb") as f:
106 pil_image = Image.open(f)
107 pil_image.load()
108 pil_image = pil_image.convert("RGB")
109
110 if self.random_crop:
111 arr = random_crop_arr(pil_image, self.resolution)
112 else:
113 arr = center_crop_arr(pil_image, self.resolution)
114
115 if self.random_flip and random.random() < 0.5:
116 arr = arr[:, ::-1]
117
118 arr = arr.astype(np.float32) / 127.5 - 1
119
120 out_dict = {}
121 if self.local_classes is not None:
122 out_dict["y"] = np.array(self.local_classes[idx], dtype=np.int64)
123 return np.transpose(arr, [2, 0, 1]), out_dict
124
125
126def center_crop_arr(pil_image, image_size):

Callers

nothing calls this directly

Calls 3

random_crop_arrFunction · 0.85
center_crop_arrFunction · 0.85
loadMethod · 0.80

Tested by

no test coverage detected