#get the target images targets_cnt[target_ind][1] += 1 target_name = id_to_name[target_ind] target_data = [] #get one image for each target type for t_type,_ in enumerate(target_images[target_name]): #pick one image of this type img_ind = np.random.choice(np.arange( len(target_images[target_name][t_type]))) if preload_target_images: target_img = target_images[target_name][t_type][img_ind] else: target_img = cv2.imread(target_images[target_name][t_type][img_ind]) if np.random.rand() > .9 and vary_images: target_img = vary_image(target_img) #subtract means, give batch dimension, add to list if use_torch_vgg: target_img = ((target_img/255.0) - [0.485, 0.456, 0.406])/[0.229, 0.224, 0.225] else: target_img = target_img - means #target_img = np.expand_dims(target_img,axis=0) batch_target_data.append(target_img) batch_im_data.append(im_data) #batch_gt_boxes.append(gt_boxes) batch_gt_boxes.extend(gt_boxes)
target_path = '/net/bvisionserver3/playpen10/ammirato/Data/instance_detection_targets/AVD_BB_exact_few_and_other_BB_gen_160/' dest_path = '/net/bvisionserver3/playpen10/ammirato/Data/instance_detection_targets/AVD_BB_exact_few_and_other_BB_gen_160_varied/' target_types = ['target_0', 'target_1'] for t_type in target_types: b_path = os.path.join(target_path, t_type) dp_path = os.path.join(dest_path, t_type) img_names = os.listdir(b_path) for img_name in img_names: img = cv2.imread(os.path.join(b_path, img_name)) sep_ind = img_name.rfind('_') ext_ind = img_name.rfind('.') obj_name = img_name[:sep_ind] obj_index = int(img_name[sep_ind + 1:ext_ind]) cv2.imwrite(os.path.join(dp_path, img_name), img) for il in range(1, 101): new_img = vary_image(img) new_index = str(obj_index + il + 100) new_name = obj_name + '_' + new_index + '.jpg' cv2.imwrite(os.path.join(dp_path, new_name), new_img)