def load_net(self, net_name, set_net_version=None): net_path = os.path.join(self.trained_nets_path, net_name, 'model_dir', 'dynamic_net.pth') temp_opt = config.get_configurations() opt_path = os.path.join(self.trained_nets_path, net_name, 'config.txt') if os.path.exists(opt_path): opt = utils.read_config_and_arrange_opt(opt_path, temp_opt) else: opt = temp_opt self.main_widget.dynamic_model = InferenceModel(opt, set_net_version=set_net_version) self.main_widget.dynamic_model.load_network(net_path)
def setup(opts): ckpt = opts["style_dir"] model_path = ckpt + "/" + "model_dir/dynamic_net.pth" config_path = ckpt + "/" + "config.json" conf = json.load(open(config_path)) set_net_version = conf["network_type"] opt = config.get_configurations() dynamic_model = InferenceModel(opt, set_net_version=set_net_version) dynamic_model.load_network(model_path) return {"dynamic_model" : dynamic_model, "network_type" : set_net_version }
parser = argparse.ArgumentParser() parser.add_argument('--network_name', default=network_name) parser.add_argument('--num_of_images', default=num_of_images, type=int) inference_opt = parser.parse_args() network_name = inference_opt.network_name num_of_images = inference_opt.num_of_images networks_path = os.path.join('trained_nets', network_name) model_path = os.path.join(networks_path, 'model_dir', 'dynamic_net.pth') config_path = os.path.join(networks_path, 'config.txt') save_path = os.path.join('results', 'inference_results') if not os.path.exists(save_path): utils.make_dirs(save_path) opt = config.get_configurations(parser=parser) if os.path.exists(config_path): utils.read_config_and_arrange_opt(config_path, opt) dynamic_model = InferenceModel(opt) dynamic_model.load_network(model_path) dynamic_model.net.train() to_tensor = transforms.ToTensor() to_pil_image = transforms.ToPILImage() first_image = True input_tensor = torch.randn((128, dynamic_model.opt.z_size)).view(-1, dynamic_model.opt.z_size, 1, 1).to(dynamic_model.device) for alpha in tqdm(alphas): output_tensor = dynamic_model.forward_and_recover(input_tensor.requires_grad_(False), alpha=alpha)
#!/usr/bin/env python import os #BA modules import log import git #import render import config #import template import cli import run import notifications if __name__ == '__main__': # Brief sketch follows args = cli.parse_cli() configs = config.get_configurations(os.getcwd()) run.run_process(args, configs)
import config from models.bank_model import BankModel opt = config.get_configurations() if __name__ == "__main__": model = BankModel(opt) model.init_paths() model.write_config() if opt.training_scheme == 'all': model.train(main_training=True) print('Trained main network') model.net.loop_count = 2 model.train(main_training=False) print('Trained bank network') elif opt.training_scheme == 'bank': model.net.loop_count = 2 model.load_pre_trained() model.train(main_training=False) print('Trained bank network') elif opt.training_scheme == 'main': model.train(main_training=True) print('Trained main network')