options.py 3.7 KB
Newer Older
H
hypox64 已提交
1 2
import argparse
import os
H
hypox64 已提交
3
import torch
H
hypox64 已提交
4 5 6 7 8 9 10 11 12

class Options():
    def __init__(self):
        self.parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
        self.initialized = False

    def initialize(self):

        #base
H
hypox64 已提交
13
        self.parser.add_argument('--use_gpu',type=int,default=1, help='if 0, do not use gpu')
H
hypox64 已提交
14
        # self.parser.add_argument('--use_gpu', action='store_true', help='if input it, use gpu')
H
hypox64 已提交
15
        self.parser.add_argument('--media_path', type=str, default='./hands_test.mp4',help='your videos or images path')
H
hypox64 已提交
16
        self.parser.add_argument('--mode', type=str, default='auto',help='add or clean mosaic into your media  auto | add | clean')
H
hypox64 已提交
17 18 19 20 21
        self.parser.add_argument('--model_path', type=str, default='./pretrained_models/add_hands_128.pth',help='pretrained model path')
        self.parser.add_argument('--result_dir', type=str, default='./result',help='output result will be saved here')
        self.parser.add_argument('--tempimage_type', type=str, default='png',help='type of temp image, png | jpg, png is better but occupy more storage space')

        #AddMosaic
H
hypox64 已提交
22 23 24
        self.parser.add_argument('--mosaic_mod', type=str, default='squa_avg',help='type of mosaic -> squa_avg | squa_random | squa_avg_circle_edge | rect_avg | random')
        self.parser.add_argument('--mosaic_size', type=int, default=0,help='mosaic size,if 0 auto size')
        self.parser.add_argument('--mask_extend', type=int, default=10,help='more mosaic area')
H
hypox64 已提交
25 26 27
        self.parser.add_argument('--mask_threshold', type=int, default=64,help='threshold of recognize mosaic position 0~255')
        self.parser.add_argument('--output_size', type=int, default=0,help='size of output file,if 0 -> origin')
        
H
hypox64 已提交
28
        #CleanMosaic
H
hypox64 已提交
29
        self.parser.add_argument('--netG', type=str, default='auto',help='select model to use for netG(clean mosaic) -> auto | unet_128 | resnet_9blocks | HD | video')
30
        self.parser.add_argument('--mosaic_position_model_path', type=str, default='auto',help='name of model use to find mosaic position')
H
hypox64 已提交
31
        self.parser.add_argument('--no_feather', action='store_true', help='if true, no edge feather and color correction, but run faster')
H
hypox64 已提交
32 33 34 35 36 37 38 39 40
        self.parser.add_argument('--medfilt_num', type=int, default=11,help='medfilt window of mosaic movement in the video')
        self.initialized = True


    def getparse(self):
        if not self.initialized:
            self.initialize()
        self.opt = self.parser.parse_args()

H
hypox64 已提交
41 42 43 44 45 46
        if torch.cuda.is_available() and self.opt.use_gpu:
            self.opt.use_gpu = True
        else:
            self.opt.use_gpu = False


H
hypox64 已提交
47 48 49 50 51 52 53 54
        if self.opt.mode == 'auto':
            if 'add' in self.opt.model_path:
                self.opt.mode = 'add'
            elif 'clean' in self.opt.model_path:
                self.opt.mode = 'clean'
            else:
                print('Please input running mode!')

H
hypox64 已提交
55
        if self.opt.netG == 'auto' and self.opt.mode =='clean':
H
hypox64 已提交
56 57 58 59
            if 'unet_128' in self.opt.model_path:
                self.opt.netG = 'unet_128'
            elif 'resnet_9blocks' in self.opt.model_path:
                self.opt.netG = 'resnet_9blocks'
H
hypox64 已提交
60 61
            elif 'HD' in self.opt.model_path:
                self.opt.netG = 'HD'
H
hypox64 已提交
62 63
            elif 'video' in self.opt.model_path:
                self.opt.netG = 'video'
H
hypox64 已提交
64 65 66
            else:
                print('Type of Generator error!')

H
hypox64 已提交
67

68 69 70
        if self.opt.mosaic_position_model_path == 'auto':
            _path = os.path.join(os.path.split(self.opt.model_path)[0],'mosaic_position.pth')
            self.opt.mosaic_position_model_path = _path
H
hypox64 已提交
71
            # print(self.opt.mosaic_position_model_path)
72

H
hypox64 已提交
73
        return self.opt