deepmosaic.py 1.7 KB
Newer Older
H
hypox64 已提交
1
import os
H
hypox64 已提交
2 3
from cores import Options,core
from util import util
H
hypox64 已提交
4
from models import loadmodel
H
hypox64 已提交
5 6

opt = Options().getparse()
H
hypox64 已提交
7
util.file_init(opt)
H
hypox64 已提交
8

H
hypox64 已提交
9
def main():
H
hypox64 已提交
10
    
H
hypox64 已提交
11 12 13 14
    if os.path.isdir(opt.media_path):
        files = util.Traversal(opt.media_path)
    else:
        files = [opt.media_path]        
H
hypox64 已提交
15
    if opt.mode == 'add':
H
hypox64 已提交
16 17 18 19 20 21 22 23 24 25
        netS = loadmodel.unet(opt)
        for file in files:
            opt.media_path = file
            if util.is_img(file):
                core.addmosaic_img(opt,netS)
            elif util.is_video(file):
                core.addmosaic_video(opt,netS)
                util.clean_tempfiles(tmp_init = False)
            else:
                print('This type of file is not supported')
H
hypox64 已提交
26

H
hypox64 已提交
27
    elif opt.mode == 'clean':
H
hypox64 已提交
28 29 30
        netM = loadmodel.unet_clean(opt)
        if opt.netG == 'video':
            netG = loadmodel.video(opt)
H
hypox64 已提交
31
        else:
H
hypox64 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45
            netG = loadmodel.pix2pix(opt)
        
        for file in files:
            opt.media_path = file
            if util.is_img(file):
                core.cleanmosaic_img(opt,netG,netM)
            elif util.is_video(file):
                if opt.netG == 'video':            
                    core.cleanmosaic_video_fusion(opt,netG,netM)
                else:
                    core.cleanmosaic_video_byframe(opt,netG,netM)
                util.clean_tempfiles(tmp_init = False)
            else:
                print('This type of file is not supported')
H
hypox64 已提交
46

H
hypox64 已提交
47 48 49 50 51 52 53 54 55 56
        
main()
# if __name__ == '__main__':
#     try:
#         main()
#     except Exception as e:
#         print('Error:',e)
#         input('Please press any key to exit.\n')
#         util.clean_tempfiles(tmp_init = False)
#         exit(0)