deepmosaic.py 2.0 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
        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)
            else:
                print('This type of file is not supported')
H
hypox64 已提交
25

H
hypox64 已提交
26
    elif opt.mode == 'clean':
H
hypox64 已提交
27 28 29
        netM = loadmodel.unet_clean(opt)
        if opt.netG == 'video':
            netG = loadmodel.video(opt)
H
hypox64 已提交
30
        else:
H
hypox64 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43
            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)
            else:
                print('This type of file is not supported')
H
hypox64 已提交
44

H
hypox64 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57
    elif opt.mode == 'style':
        netG = loadmodel.cyclegan(opt)
        for file in files:
            opt.media_path = file
            if util.is_img(file):
                core.styletransfer_img(opt,netG)
            elif util.is_video(file):
                core.styletransfer_video(opt,netG)

            else:
                print('This type of file is not supported')

    util.clean_tempfiles(tmp_init = False)
H
hypox64 已提交
58 59 60 61 62 63 64 65 66 67
        
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)