def process(img): img = bytes_to_file(img) try: img_A, img_B = read_split_image(img) if augment: # augment the image by: # 1) enlarge the image # 2) random crop the image back to its original size # NOTE: image A and B needs to be in sync as how much # to be shifted w, h = img_A.shape multiplier = random.uniform(1.00, 1.05) # add an eps to prevent cropping issue nw = int(multiplier * w) + 1 nh = int(multiplier * h) + 1 shift_x = int(np.ceil(np.random.uniform(0.01, nw - w))) shift_y = int(np.ceil(np.random.uniform(0.01, nh - h))) img_A = shift_and_resize_image(img_A, shift_x, shift_y, nw, nh) img_B = shift_and_resize_image(img_B, shift_x, shift_y, nw, nh) img_A = normalize_image(img_A) img_B = normalize_image(img_B) merged = np.stack([img_A, img_B], axis=2) return merged finally: img.close()
super(NeverEndingLoopingProvider, self).__init__(obj_path) def get_random_embedding_iter(self, batch_size, embedding_ids): while True: # np.random.shuffle(self.data.examples) rand_iter = super(NeverEndingLoopingProvider, self) \ .get_random_embedding_iter(batch_size, embedding_ids) for labels, images in rand_iter: yield labels, images if __name__ == '__main__': from PIL import Image pkl_images = PickledImageProvider("../binary/train.obj") examples = pkl_images.examples print(len(examples)) b_img0 = examples[0][1] # idx, binary img0 = bytes_to_file(b_img0) img_A, img_B = read_split_image(img0) img = Image.fromarray(np.uint8(img_A), "RGB") # img.save('my.png') # mat = misc.imread(img0).astype(np.float) # side = int(mat.shape[1] / 2) # assert side * 2 == mat.shape[1] # img_A = mat[:, :side] # target # img = Image.fromarray(np.uint8(img_B)) img.show()