Пример #1
0
def print_options(opt, if_sv=False):
    """Print and save options

	It will print both current options and default values(if different).
	It will save options into a text file / [checkpoints_dir] / opt.txt
	"""
    message = ''
    message += '----------------- Options ---------------\n'
    for k, v in sorted(vars(opt).items()):
        comment = ''
        # default = self.parser.get_default(k)
        # if v != default:
        # 	comment = '\t[default: %s]' % str(default)
        message += '{:>25}: {:<30}{}\n'.format(str(k), str(v), comment)
    message += '----------------- End -------------------'
    print(message)

    # save to the disk
    if if_sv:
        ut.make_folder(
            opt.exp_dir
        )  # all option will mk dirs  # saved to json file in set_env
        file_name = os.path.join(opt.exp_dir,
                                 'opts.txt'.format(opt.start_epoch))  #
        with open(file_name, 'wt') as opt_file:
            opt_file.write(message)
            opt_file.write('\n')
Пример #2
0
def main(config):
    # For fast training
    cudnn.benchmark = True

    # Data loader
    data_loader = CelebADataset(config.supervise,
                                config.train,
                                config.dataset,
                                config.image_path,
                                config.imsize,
                                batchsize=config.batchsize,
                                shuffle=config.train)

    # Create directories if not exist
    check_path = os.path.join(config.sample_path, config.version)
    while os.path.exists(check_path):
        name, version = config.version.split("_")
        config.version = f"{name}_{int(version)+1}"
        check_path = os.path.join(config.sample_path, config.version)
    make_folder(config.model_save_path, config.version)
    make_folder(config.sample_path, config.version)
    make_folder(config.log_path, config.version)
    make_folder(config.attn_path, config.version)

    if config.train:
        # if config.model == 'sagan':
        trainer = Trainer(data_loader.loader(), config)
        # elif config.model == 'qgan':
        # trainer = qgan_trainer(data_loader.loader(), config)
        trainer.train()
    else:
        raise NotImplementedError
Пример #3
0
def main(config):
    # For fast training
    cudnn.benchmark = True

    # Data loader
    data_loader = Data_Loader(config.train,
                              config.dataset,
                              config.image_path,
                              config.imsize,
                              config.batch_size,
                              shuf=config.train)

    # Create directories if not exist
    make_folder(config.model_save_path, config.version)
    make_folder(config.sample_path, config.version)
    make_folder(config.log_path, config.version)
    make_folder(config.attn_path, config.version)

    if config.train:
        if config.model == 'sagan':
            trainer = Trainer(data_loader.loader(), config)
        elif config.model == 'qgan':
            trainer = qgan_trainer(data_loader.loader(), config)
        trainer.train()
    else:
        tester = Tester(data_loader.loader(), config)
        tester.test()
Пример #4
0
def set_env(opts):  # to be changed accordingly for rst fd
    # set sys paths
    # sys.path.insert(0, 'common')  # not using commong
    from utils.utils import add_pypath, make_folder
    add_pypath(osp.join('data'))  # actually we can use ds directly
    for i in range(len(opts.trainset)):
        add_pypath(osp.join('data', opts.trainset[i]))
    # if opts.cocoapi_dir:
    # 	add_pypath(opts.cocoapi_dir)  # add coco dir to it
    add_pypath(osp.join('data', opts.testset))

    # add folders
    make_folder(opts.model_dir)
    make_folder(opts.vis_dir)
    make_folder(opts.log_dir)
    make_folder(opts.rst_dir)
    make_folder(opts.web_dir)
Пример #5
0
    # weight softmax x convolution weight and normalize
    cam = weight_softmax[class_idx].dot(feature_conv.reshape((nc, h * w)))
    cam = cam.reshape(h, w)
    cam = cam - np.min(cam)
    cam_img = (255 * cam / np.max(cam)).astype(np.uint8)
    output_cam = cv2.resize(cam_img, size_upsample)
    return output_cam


if __name__ == '__main__':
    args = parser.parse_args()

    # make folder
    today = utils.get_today() + '_cam'
    save_dir = Path(args.save_dir) / today
    utils.make_folder(save_dir)

    # transform
    transform = transforms.Compose([
        transforms.Resize((128, 128)),
        transforms.ToTensor(),
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
    ])

    #load CIFAR10 DATASETS
    testset = torchvision.datasets.CIFAR10(root=args.data_dir,
                                           train=False,
                                           download=True,
                                           transform=transform)

    testloader = torch.utils.data.DataLoader(testset,