def __getitem__(self, index): # get img_path and trans img_path, trans = self.labels[index] # read img img = cv2.imread(img_path) # do aug if self.augmentation: img = pil2cv(self.process.aug_img(cv2pil(img))) return {'img': img, 'label': trans}
def __getitem__(self, index): # get img_path and trans img_path, trans = self.labels[index] # read img img = cv2.imread(img_path) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # do aug if self.augmentation: img = pil2cv(self.process.aug_img( cv2pil(img))) ## cv2格式的图片输入输出,但是图像増广用PIL库,所以需要 PIL 和 cv2 相互转换。 return {'img': img, 'label': trans}
def __getitem__(self, index): index = self.filtered_index_list[index] with self.env.begin(write=False) as txn: label_key = 'label-%09d'.encode() % index label = txn.get(label_key).decode('utf-8') img_key = 'image-%09d'.encode() % index imgbuf = txn.get(img_key) buf = six.BytesIO() buf.write(imgbuf) buf.seek(0) img = Image.open(buf).convert('RGB') # for color image # We only train and evaluate on alphanumerics (or pre-defined character set in rec_train.py) img = np.array(img) if self.augmentation: img = pil2cv(self.process.aug_img(cv2pil(img))) return {'img': img, 'label': label}