def __getitem__(self, idx): # print(os.getcwd()) # print(path_test) path_test = os.path.join(os.getcwd(),'Chexpert/data/nas',self._image_paths[idx]) # print(path_test) # print(self._image_paths[idx]) # testing = cv2.imread() # image = cv2.imread(self._image_paths[idx], 0) image = cv2.imread(path_test, 0) # print(image) image = Image.fromarray(image) if self._mode == 'train': image = GetTransforms(image, type=self.cfg.use_transforms_type) image = np.array(image) if self.cfg.use_equalizeHist: image = cv2.equalizeHist(image) image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB).astype(np.float32) # changed the resolution of the img from 512 to 640 all around to see if produces better results # chaged the interpolation method from INTER_LINEAR to INTER_AREA which resamples using pixel area relation. # possibly better results with inter_area if no zooming is applied if self.cfg.fix_ratio: image = self._fix_ratio(image) else: image = cv2.resize(image, dsize=(self.cfg.width, self.cfg.height), interpolation=cv2.INTER_AREA) # chaged the smoothing of the image: # changed from gaussian_blur to bilateralFiltering, which is a better version, which simplifies the img but preserve edges # it can run a little slower than gaussian_blur since it a more complex process, but might improve results # left the if statement unchanged, just to filter the same imgs than before. if self.cfg.gaussian_blur > 0: image = cv2.bilateralFilter(image, 9, 75, 75) # normalization image -= self.cfg.pixel_mean # vgg and resnet do not use pixel_std, densenet and inception use. if self.cfg.use_pixel_std: image /= self.cfg.pixel_std # normal image tensor : H x W x C # torch image tensor : C X H X W image = image.transpose((2, 0, 1)) labels = np.array(self._labels[idx]).astype(np.float32) path = self._image_paths[idx] if self._mode == 'train' or self._mode == 'dev': return (image, labels) elif self._mode == 'test': return (image, path) elif self._mode == 'heatmap': return (image, path, labels) else: raise Exception('Unknown mode : {}'.format(self._mode))
def __getitem__(self, idx): # print(os.getcwd()) # print(path_test) path_test = os.path.join(os.getcwd(), 'Chexpert/data/nas', self._image_paths[idx]) # print(path_test) # print(self._image_paths[idx]) # testing = cv2.imread() # image = cv2.imread(self._image_paths[idx], 0) image = cv2.imread(path_test, 0) # print(image) image = Image.fromarray(image) # print('working,----------------------------------') if self._mode == 'train': image = GetTransforms(image, type=self.cfg.use_transforms_type) image = np.array(image) if self.cfg.use_equalizeHist: image = cv2.equalizeHist(image) image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB).astype(np.float32) if self.cfg.fix_ratio: image = self._fix_ratio(image) else: image = cv2.resize(image, dsize=(self.cfg.width, self.cfg.height), interpolation=cv2.INTER_LINEAR) if self.cfg.gaussian_blur > 0: image = cv2.GaussianBlur( image, (self.cfg.gaussian_blur, self.cfg.gaussian_blur), 0) # normalization image -= self.cfg.pixel_mean # vgg and resnet do not use pixel_std, densenet and inception use. if self.cfg.use_pixel_std: image /= self.cfg.pixel_std # normal image tensor : H x W x C # torch image tensor : C X H X W image = image.transpose((2, 0, 1)) labels = np.array(self._labels[idx]).astype(np.float32) path = self._image_paths[idx] if self._mode == 'train' or self._mode == 'dev': return (image, labels) elif self._mode == 'test': return (image, path) elif self._mode == 'heatmap': return (image, path, labels) else: raise Exception('Unknown mode : {}'.format(self._mode))