print("Total of classes : %d" % CIFARNCLASS) print("Train info") print("Image : {}({}), Label : {}".format(train_image.shape, train_image.dtype, train_label.shape)) print("Val info") print("Image : {}({}), Label : {}".format(val_image.shape, val_image.dtype, val_label.shape)) print("Test info") print("Image : {}({}), Label : {}".format(test_image.shape, test_image.dtype, test_label.shape)) train_class_count = label_count(train_label, CIFARNCLASS) val_class_count = label_count(val_label, CIFARNCLASS) test_class_count = label_count(test_label, CIFARNCLASS) print("Train class mean : {}, std : {}".format(np.mean(train_class_count), np.std(train_class_count))) print("Val class mean : {}, std : {}".format(np.mean(val_class_count), np.std(val_class_count))) print("Test class mean : {}, std : {}".format(np.mean(test_class_count), np.std(test_class_count))) create_muldir(CIFARPROCESSED) write_npy(train_image, CIFARPROCESSED + 'train_image.npy') write_npy(train_label, CIFARPROCESSED + 'train_label.npy') write_npy(val_image, CIFARPROCESSED + 'val_image.npy') write_npy(val_label, CIFARPROCESSED + 'val_label.npy') write_npy(test_image, CIFARPROCESSED + 'test_image.npy') write_npy(test_label, CIFARPROCESSED + 'test_label.npy')
if args.ltype == 'npair': args.nsclass = args.nbatch // 2 #for args.lamb in [0.001, 0.003, 0.01] #for args.ma in [0.3, 1.0]: METRIC_PARAM = args.lamb if args.ltype == 'npair' else args.ma FILE_ID = params2id(args.dataset, args.nbatch, args.nsclass, args.conv, args.ltype, METRIC_PARAM, args.m, args.dtype, args.dptype) SAVE_DIR = RESULT_DIR + 'metric/save/%s/' % FILE_ID LOG_DIR = RESULT_DIR + 'metric/log/' CSV_DIR = RESULT_DIR + 'metric/csv/' PKL_DIR = RESULT_DIR + 'metric/pkl/' BOARD_DIR = RESULT_DIR + 'metric/board/%s/' % FILE_ID create_muldir(SAVE_DIR, BOARD_DIR, LOG_DIR, CSV_DIR, PKL_DIR) # load data datasetmanager = DATASETMANAGER_DICT[args.dataset] dm_train, dm_val, dm_test = datasetmanager(args.ltype, nsclass=args.nsclass) for v in [dm_train, dm_val, dm_test]: v.print_shape() model = DeepMetric(dm_train, dm_val, dm_test, LOG_DIR + FILE_ID + '.log', args) model.build() model.set_up_train() try: model.restore(save_dir=SAVE_DIR) except AttributeError:
type=str) args = parser.parse_args() if __name__ == '__main__': args.d = args.m FILE_ID = params2id(args.dataset, args.conv, args.ltype, args.m) QUERY_FILE_ID = params2id(args.dataset, '*', '*', args.conv, args.ltype, '*', args.m, '*', '*') CSV_DIR = RESULT_DIR + 'metric/csv/' PKL_DIR = RESULT_DIR + 'metric/pkl/' LOG_DIR = RESULT_DIR + 'metric/log/' SAVE_DIR = RESULT_DIR + 'metric/save/%s/' % FILE_ID create_muldir(PKL_DIR, CSV_DIR, LOG_DIR) copy_dst_csv = CSV_DIR + FILE_ID + '.csv' copy_dst_pkl = PKL_DIR + FILE_ID + '.pkl' if os.path.exists(SAVE_DIR): remove_dir(SAVE_DIR) if os.path.exists(copy_dst_csv): remove_file(copy_dst_csv) if os.path.exists(copy_dst_pkl): remove_file(copy_dst_pkl) pkl_files = glob.glob(PKL_DIR + QUERY_FILE_ID + '.pkl') print(pkl_files) if len(pkl_files) == 0: print("No such pkl files") sys.exit()
for i in range(len(val_label)): val_label_set[val_label[i]].append(i) new_val_idx = list() for i in range(1000): new_val_idx.extend(val_label_set[i][:50]) new_val_idx = np.array(new_val_idx) new_val_img = val_img[new_val_idx] new_val_label = val_label[new_val_idx] print("Train Image : {}({}, max={}, min={}), Label : {}".format( train_img.shape, train_img.dtype, np.max(train_img), np.min(train_img), train_label.shape)) print("Val Image : {}({}, max={}, min={}), Label : {}".format( new_val_img.shape, new_val_img.dtype, np.max(new_val_img), np.min(new_val_img), new_val_label.shape)) print("Test Image : {}({}, max={}, min={}), Label : {}".format( test_img.shape, test_img.dtype, np.max(test_img), np.min(test_img), test_label.shape)) create_muldir(IMAGENET32PROCESSED) write_npy(train_img, IMAGENET32PROCESSED + 'train_img.npy') write_npy(train_label, IMAGENET32PROCESSED + 'train_label.npy') write_npy(new_val_img, IMAGENET32PROCESSED + 'val_img.npy') write_npy(new_val_label, IMAGENET32PROCESSED + 'val_label.npy') write_npy(test_img, IMAGENET32PROCESSED + 'test_img.npy') write_npy(test_label, IMAGENET32PROCESSED + 'test_label.npy')