Exemplo n.º 1
0
    def __getitem__(self, index):
        try:
            # print(self.files[index])
            img = util.readRGB(self.files[index]).astype(np.float32)
            image_name = os.path.basename(self.files[index])
            orientation = self.orientation[image_name]
            if orientation == 'right':
                img = cv2.flip(img, 1)
            elif orientation == 'left':
                pass
            else:
                raise RuntimeError

            if self.crop_size[0] > 0:
                img = util.center_crop(img, self.crop_size, self.bias)
            if self.scale[0] > 0:
                img = scipy.misc.imresize(img, [self.scale[0], self.scale[1]])
            # img = img[self.crop_size[0]:shape[0] - self.crop_size[0], self.crop_size[1]:shape[1] - self.crop_size[1], :]
            img = self.transform(img)
            attribute = self.frame[self.frame['name'] == image_name]
            attribute = attribute.values[0][1:]
            attribute = tuple(attribute)
            return img, attribute
        except:
            rd_idx = np.random.randint(0, self.__len__())
            return self.__getitem__(rd_idx)
Exemplo n.º 2
0
 def __getitem__(self, index):
     print(self.files[index])
     img = util.readRGB(self.files[index]).astype(np.float32)
     image_name = os.path.basename(self.files[index])
     orientation = self.orientation[image_name]
     if orientation == 'right':
         img = cv2.flip(img, 1)
     elif orientation == 'left':
         pass
     if self.crop_size[0] > 0:
         img = util.center_crop(img, self.crop_size, self.bias)
     if self.scale[0] > 0:
         img = scipy.misc.imresize(img, [self.scale[0], self.scale[1]])
     img = self.transform(img)
     return img