OCCLUSION_RESULT_CAT = [] for target_category in ['car']: #categories: plot_out_dir = plot_out_dir_level + target_category + '/' if not os.path.exists(plot_out_dir): os.makedirs(plot_out_dir) with torch.no_grad(): OCCLUSION_RESULT_TYPE = [] for occ_type in occ_types: # Load data test_imgs, test_labels, test_masks = getImg( 'test', categories_train, dataset, data_path, [target_category], occ_level, occ_type, bool_load_occ_mask=True) nsamples = np.floor(len(test_imgs) * nsamples_ratio).astype(np.int) test_imgs = test_imgs[:nsamples] test_labels = test_labels[:nsamples] test_masks = test_masks[:nsamples] test_imgset = Imgset(test_imgs, test_masks, test_labels, imgLoader, bool_square_images=False) test_loader = DataLoader(dataset=test_imgset, batch_size=1,
val_masks = [] # get training and validation images for occ_level in occ_levels_train: if occ_level == 'ZERO': occ_types = [''] train_fac = 0.9 else: occ_types = ['_white', '_noise', '_texture', ''] train_fac = 0.1 for occ_type in occ_types: imgs, labels, masks = getImg('train', categories_train, dataset, data_path, categories, occ_level, occ_type, bool_load_occ_mask=False) nimgs = len(imgs) for i in range(nimgs): if (random.randint(0, nimgs - 1) / nimgs) <= train_fac: train_imgs.append(imgs[i]) train_labels.append(labels[i]) train_masks.append(masks[i]) elif not bool_train_with_occluders: val_imgs.append(imgs[i]) val_labels.append(labels[i]) val_masks.append(masks[i]) print('Total imgs for train ' + str(len(train_imgs)))