diff --git a/acquisition.py b/acquisition.py index 504936d..0046470 100755 --- a/acquisition.py +++ b/acquisition.py @@ -23,18 +23,18 @@ def acquisition(pool_loader, train_loader, model, opts): # setting the number of the samples to be pooled if len(train_loader.dataset.indices) == 0: # initial acquisition - print 'initial selection: n_pool = ', opts.init_train_size + print('initial selection: n_pool = ', opts.init_train_size) n_pool = opts.init_train_size else: - print 'n_pool = ', opts.n_pool + print('n_pool = ', opts.n_pool) n_pool = opts.n_pool - print 'extracting features of the training dataset. ' + print('extracting features of the training dataset. ') train_features, train_labels = extract_features(train_loader_noshuffle, model) - print 'extracting features of the pooling dataset.' + print('extracting features of the pooling dataset.') pool_features, pool_labels = extract_features(pool_loader_noshuffle, model) - print 'selecting samples.' + print('selecting samples.') pooled_idx = ipm(train_features, pool_features, n_pool) pooled_idx_set = set([pool_loader_noshuffle.dataset.indices[i] for i in pooled_idx]) @@ -47,7 +47,7 @@ def acquisition(pool_loader, train_loader, model, opts): def extract_features(data_loader, model, label_only=False): if not label_only: - feature_extractor = nn.Sequential(*list(model.module.children())[:-2]) + feature_extractor = nn.Sequential(*list(model.module.children())[:-1]) feature_extractor = feature_extractor.cuda() feature_extractor = nn.DataParallel(feature_extractor, device_ids=None) feature_extractor.eval() @@ -62,7 +62,6 @@ def extract_features(data_loader, model, label_only=False): inputs = Variable(inputs) batch_features = feature_extractor(inputs).data.view(inputs.size(0), -1) - # TODO: convert to numpy more efficiently features.extend(batch_features.cpu().numpy()) if i % 100 == 0: diff --git a/main.py b/main.py index 928d1ff..debe114 100755 --- a/main.py +++ b/main.py @@ -50,6 +50,7 @@ json.dump(vars(opt), opt_file) torch.manual_seed(opt.manual_seed) + np.random.seed(opt.manual_seed) model, parameters = generate_model(opt) @@ -93,12 +94,12 @@ pool_idx_set = set(range(len(labeled_data))) elif opt.init_selection == 'random': # split data randomly - print 'initial data selection: random' + print('initial data selection: random') training_idx_set = set(np.random.permutation(range(len(labeled_data)))[:opt.init_train_size]) pool_idx_set = set(range(len(labeled_data))) - training_idx_set elif opt.init_selection == 'uniform_random': # select balanced dataset randomly - print 'initial data selection: uniform_random' + print('initial data selection: uniform_random') labeled_data_loader = torch.utils.data.DataLoader( labeled_data, batch_size=256, @@ -187,7 +188,7 @@ # initial selection if necessary clusters = [] if opt.init_selection == 'same': - print 'initial data selection: same' + print('initial data selection: same') acquisition(pool_loader, train_loader, model, opt) cycle_val_acc = [] @@ -195,10 +196,10 @@ while len(training_data) <= opt.max_train_size: print('=========================================') - print 'train dataset size: ', len(training_data) - print 'pool dataset size: ', len(pool_data) - print 'max train dataset size: ', opt.max_train_size - print '# pooled data per cycle: ', opt.n_pool + print('train dataset size: ', len(training_data)) + print('pool dataset size: ', len(pool_data)) + print('max train dataset size: ', opt.max_train_size) + print('# pooled data per cycle: ', opt.n_pool) print('Training') max_val_acc = 0 @@ -216,7 +217,7 @@ scheduler.step(validation_loss) cycle_val_acc.append(max_val_acc) - print cycle_val_acc + print(cycle_val_acc) if opt.test: spatial_transform = Compose([ @@ -242,7 +243,7 @@ subset='validation', verbose=True, top_k=1) ucf101.evaluate() cycle_test_acc.append(ucf101.hit_at_k) - print cycle_test_acc + print(cycle_test_acc) # pool new labeled data if len(training_data) + opt.n_pool > opt.max_train_size: diff --git a/opts.py b/opts.py index 7d324b6..38e2ffb 100755 --- a/opts.py +++ b/opts.py @@ -221,7 +221,7 @@ def parse_opts(): type=int, help='ResNeXt cardinality') parser.add_argument( - '--manual_seed', default=0, type=int, help='Manually set random seed') + '--manual_seed', default=1, type=int, help='Manually set random seed') # acqusition args parser.add_argument('--init_train_size', type=int, default=101) @@ -231,7 +231,5 @@ def parse_opts(): parser.add_argument('--n_pool', type=int, default=101) parser.add_argument('--max_train_size', type=int, default=404) - - args = parser.parse_args() return args \ No newline at end of file