args["overwrite_opts"]) networks[net_name], optimizers["opt_{}".format( net_name)] = utils.load_network(**net_kwargs[net_name]) # load the loss functions loss_info = setup_kwargs_loss(args, pt2=False) losses = {} for k in loss_info: losses[k] = model_utils.load_loss(loss_info[k]["name"], loss_info[k]["kwargs"]) if not os.path.exists(args["save_dir"]): os.makedirs(args["save_dir"]) print(args) model = trainer_module.Model(data_provider=dp, **networks, **optimizers, **losses, **trainer_kwargs) model.train() ####### # DONE TRAINING REFERENCE MODEL ####### embeddings_path = "{}/embeddings.pkl".format(args["save_dir"]) embeddings = model_utils.load_embeddings(embeddings_path, model.enc, dp)
model.load(opt.save_dir) model.train() ####### ### DONE TRAINING REFERENCE MODEL ####### ####### ### TRAIN STRUCTURE MODEL ####### embeddings_path = opt.save_dir + os.sep + 'embeddings.pkl' if opt.skip_pt1: embeddings = model_utils.load_embeddings(embeddings_path, None, dp, opt) else: embeddings = model_utils.load_embeddings(embeddings_path, model.enc, dp, opt) models = None optimizers = None dp.embeddings = embeddings dp.channelInds = opt.channels_pt2 opt.save_dir = os.path.join(opt.save_parent, opt.struct_dir) if not os.path.exists(opt.save_dir): os.makedirs(opt.save_dir) kwargs_model = setup_kwargs_model(opt)
logger.add((epoch, this_iter) + errors + (deltaT, )) if model_utils.maybe_save(model, epoch, epoch_next, models, optimizers, logger, zAll, dp, opt): zAll = list() ####### ### DONE TRAINING REFERENCE MODEL ####### ####### ### TRAIN STRUCTURE MODEL ####### embeddings_path = opt.save_dir + os.sep + 'embeddings.pkl' embeddings = model_utils.load_embeddings(embeddings_path, models['enc'], dp, opt) models = None optimizers = None def get_ref(self, inds, train_or_test='train'): inds = torch.LongTensor(inds) return self.embeddings[train_or_test][inds] dp.embeddings = embeddings # do this thing to bind the get_ref method to the dataprovider object import types dp.get_ref = types.MethodType(get_ref, dp)