sampler=val_sampler) logger('>> N samples: Train: %d + Val: %d' % (len(idxs_train), len(idxs_val))) # Test sets dset_sg = ParquetDataset( 'IMG/DoublePi0Pt10To100_m0To1600_pythia8_ReAOD_PU2017_MINIAODSIM_wrapfix.tzfixed_wgts.val.parquet', 1) sg_loader = DataLoader(dataset=dset_sg, batch_size=256, num_workers=10) dset_bg = ParquetDataset( 'IMG/DoublePhotonPt10To100_pythia8_ReAOD_PU2017_MINIAODSIM_wrapfix.tzfixed_m0Neg%dTo0_wgts.val.parquet' % args.neg_mass, 0) bg_loader = DataLoader(dataset=dset_bg, batch_size=256, num_workers=10) logger('>> N test samples: sg: %d + bg: %d' % (len(dset_sg), len(dset_bg))) import torch_resnet_concat as networks resnet = networks.ResNet(2, resblocks, [16, 32]) resnet.cuda() optimizer = optim.Adam(resnet.parameters(), lr=lr_init) #lr_scheduler = optim.lr_scheduler.MultiStepLR(optimizer, milestones=[10,20], gamma=0.5) def do_eval(resnet, val_loader, mae_best, epoch, sample, tgt_label): global expt_name loss_ = 0. m_pred_, m_true_, mae_, pt_, wgts_ = [], [], [], [], [] iphi_, ieta_ = [], [] label_ = [] now = time.time() for i, data in enumerate(val_loader): X, m0, pt, wgts = data['Xtz_aod'].cuda(), data['m'].cuda( ), data['pt'], data['w']
# !! NOTE: at fill time, need to check that ggtree.nPho corresponds to # no. of presumed photon objects to be regressed, i.e.: # ggtree.nPho == len(imgtree.SC_ieta) or len(imgtree.SC_iphi) # The `ma` branch still needs to be initialized with an array of some # arbitrarily large allocation `nPhoMax` which then gets reduced at fill time. nPhoMax = 20 #ma = array('f', nPhoMax*[0.]) ma = np.zeros(nPhoMax, dtype='float32') tree_out.Branch('ma', ma, 'ma[nPho]/F') #''' # Load mass regressor for inference print('Loading regressor model') import torch_resnet_concat as networks model_file = 'Models/model_epoch80_mae0.1906.pkl' resnet = networks.ResNet(2, 3, [16, 32], 128, 0).cuda() resnet.load_state_dict(torch.load(model_file)['model']) resnet.eval() print(model_file) #''' eb_scale = 25. m0_scale = 1.6 def transform_y(y): return y / m0_scale def inv_transform(y): return y * m0_scale