MCPcopy Create free account
hub / github.com/FreeformRobotics/OTS / ValDataset

Class ValDataset

dataset.py:206–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204
205
206class ValDataset(BaseDataset):
207 def __init__(self, root_dataset, odgt, opt, **kwargs):
208 super(ValDataset, self).__init__(odgt, opt, **kwargs)
209 self.root_dataset = root_dataset
210
211 def __getitem__(self, index):
212 this_record = self.list_sample[index]
213 # load image and label
214 image_path = os.path.join(self.root_dataset, this_record['fpath_img'])
215 segm_path = os.path.join(self.root_dataset, this_record['fpath_segm'])
216 img = Image.open(image_path).convert('RGB')
217 segm = Image.open(segm_path)
218 assert(segm.mode == "L")
219 assert(img.size[0] == segm.size[0])
220 assert(img.size[1] == segm.size[1])
221
222 ori_width, ori_height = img.size
223
224 img_resized_list = []
225 for this_short_size in self.imgSizes:
226 # calculate target height and width
227 scale = min(this_short_size / float(min(ori_height, ori_width)),
228 self.imgMaxSize / float(max(ori_height, ori_width)))
229 target_height, target_width = int(ori_height * scale), int(ori_width * scale)
230
231 # to avoid rounding in network
232 target_width = self.round2nearest_multiple(target_width, self.padding_constant)
233 target_height = self.round2nearest_multiple(target_height, self.padding_constant)
234
235 # resize images
236 img_resized = imresize(img, (target_width, target_height), interp='bilinear')
237
238 # image transform, to torch float tensor 3xHxW
239 img_resized = self.img_transform(img_resized)
240 img_resized = torch.unsqueeze(img_resized, 0)
241 img_resized_list.append(img_resized)
242
243 # segm transform, to torch long tensor HxW
244 segm = self.segm_transform(segm)
245 batch_segms = torch.unsqueeze(segm, 0)
246
247 output = dict()
248 output['img_ori'] = np.array(img)
249 output['img_data'] = [x.contiguous() for x in img_resized_list]
250 output['seg_label'] = batch_segms.contiguous()
251 output['info'] = this_record['fpath_img']
252 return output
253
254 def __len__(self):
255 return self.num_sample
256
257
258class TestDataset(BaseDataset):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected