コード例 #1
0
ファイル: deepmosaic.py プロジェクト: xc20021/DeepMosaics
import os
import sys
import traceback
from cores import Options, core
from util import util
from models import loadmodel

opt = Options().getparse()
util.file_init(opt)


def main():

    if os.path.isdir(opt.media_path):
        files = util.Traversal(opt.media_path)
    else:
        files = [opt.media_path]
    if opt.mode == 'add':
        netS = loadmodel.bisenet(opt, 'roi')
        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')

    elif opt.mode == 'clean':
        netM = loadmodel.bisenet(opt, 'mosaic')
        if opt.traditional:
コード例 #2
0
ファイル: deepmosaic.py プロジェクト: zoujer/DeepMosaics
import os
import sys
import traceback
from cores import Options,core
from util import util
from models import loadmodel

opt = Options().getparse(test_flag = True)
util.file_init(opt)

def main():
    
    if os.path.isdir(opt.media_path):
        files = util.Traversal(opt.media_path)
    else:
        files = [opt.media_path]        
    if opt.mode == 'add':
        netS = loadmodel.bisenet(opt,'roi')
        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')

    elif opt.mode == 'clean':
        netM = loadmodel.bisenet(opt,'mosaic')
        if opt.traditional:
            netG = None
コード例 #3
0
import sys
import traceback
sys.path.append("..")
from util import mosaic
import torch

try:
    from cores import Options,add,clean,style
    from util import util
    from models import loadmodel
except Exception as e:
    print(e)
    input('Please press any key to exit.\n')
    sys.exit(0)

opt = Options().getparse(test_flag = False)
if not os.path.isdir(opt.temp_dir):
    util.file_init(opt)

def saveScriptModel(model,example,savepath):
    model.cpu()
    traced_script_module = torch.jit.trace(model, example)
    # try ScriptModel
    output = traced_script_module(example)
    print(output)
    traced_script_module.save(savepath)

savedir = '../cpp/res/models/'
util.makedirs(savedir)

opt.mosaic_position_model_path = '../pretrained_models/mosaic/mosaic_position.pth'
コード例 #4
0
ファイル: train.py プロジェクト: wliang410/DeepMosaics
import sys
sys.path.append("..")
sys.path.append("../..")
from util import mosaic,util,ffmpeg,filt,data
from util import image_processing as impro
from cores import Options
from models import pix2pix_model,pix2pixHD_model,video_model,unet_model,loadmodel,videoHD_model
from matplotlib import pyplot as plt
import torch.backends.cudnn as cudnn

'''
--------------------------Get options--------------------------
'''

opt = Options()
opt.parser.add_argument('--N',type=int,default=25, help='')
opt.parser.add_argument('--lr',type=float,default=0.0002, help='')
opt.parser.add_argument('--beta1',type=float,default=0.5, help='')
opt.parser.add_argument('--gan', action='store_true', help='if specified, use gan')
opt.parser.add_argument('--l2', action='store_true', help='if specified, use L2 loss')
opt.parser.add_argument('--hd', action='store_true', help='if specified, use HD model')
opt.parser.add_argument('--lambda_L1',type=float,default=100, help='')
opt.parser.add_argument('--lambda_gan',type=float,default=1, help='')
opt.parser.add_argument('--finesize',type=int,default=256, help='')
opt.parser.add_argument('--loadsize',type=int,default=286, help='')
opt.parser.add_argument('--batchsize',type=int,default=1, help='')
opt.parser.add_argument('--perload_num',type=int,default=16, help='')
opt.parser.add_argument('--norm',type=str,default='instance', help='')

opt.parser.add_argument('--maxiter',type=int,default=10000000, help='')
コード例 #5
0
import os
import sys
sys.path.append("..")
from cores import Options
opt = Options()

import random
import datetime
import time

import numpy as np
import cv2
import torch

from models import runmodel, loadmodel
import util.image_processing as impro
from util import filt, util, mosaic, data, ffmpeg

opt.parser.add_argument('--datadir',
                        type=str,
                        default='your video dir',
                        help='')
opt.parser.add_argument('--savedir',
                        type=str,
                        default='../datasets/video/face',
                        help='')
opt.parser.add_argument('--interval',
                        type=int,
                        default=30,
                        help='interval of split video ')
opt.parser.add_argument('--time', type=int, default=5, help='split video time')
コード例 #6
0
from models import pix2pix_model
from matplotlib import pyplot as plt
import torch.backends.cudnn as cudnn

N = 25
ITER = 1000000
LR = 0.0002
use_gpu = True
CONTINUE = True
# BATCHSIZE = 4
dir_checkpoint = 'checkpoints/'
SAVE_FRE = 5000
start_iter = 0
SIZE = 256
lambda_L1 = 100.0
opt = Options().getparse()
opt.use_gpu = True
videos = os.listdir('./dataset')
videos.sort()
lengths = []
for video in videos:
    video_images = os.listdir('./dataset/' + video + '/ori')
    lengths.append(len(video_images))

netG = pix2pix_model.define_G(3 * N + 1,
                              3,
                              128,
                              'resnet_9blocks',
                              norm='instance',
                              use_dropout=True,
                              init_type='normal',
コード例 #7
0
ファイル: train.py プロジェクト: zyuganlee/DeepMosaics
import os
import sys
sys.path.append("..")
sys.path.append("../..")
from cores import Options
opt = Options()

import numpy as np
import cv2
import random
import torch
import torch.nn as nn
import time
from multiprocessing import Process, Queue

from util import mosaic, util, ffmpeg, filt, data
from util import image_processing as impro
from models import pix2pix_model, pix2pixHD_model, video_model, unet_model, loadmodel, videoHD_model
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
import torch.backends.cudnn as cudnn
'''
--------------------------Get options--------------------------
'''
opt.parser.add_argument('--N', type=int, default=25, help='')
opt.parser.add_argument('--lr', type=float, default=0.0002, help='')
opt.parser.add_argument('--beta1', type=float, default=0.5, help='')
opt.parser.add_argument('--gan',
                        action='store_true',
                        help='if specified, use gan')
コード例 #8
0
import torch.backends.cudnn as cudnn
import torch.nn as nn
from torch import optim

sys.path.append("..")
sys.path.append("../..")
from cores import Options
from util import mosaic,util,ffmpeg,filt,data
from util import image_processing as impro
from models import unet_model,BiSeNet_model


'''
--------------------------Get options--------------------------
'''
opt = Options()
opt.parser.add_argument('--gpu_id',type=int,default=0, help='')
opt.parser.add_argument('--lr',type=float,default=0.001, help='')
opt.parser.add_argument('--finesize',type=int,default=360, help='')
opt.parser.add_argument('--loadsize',type=int,default=400, help='')
opt.parser.add_argument('--batchsize',type=int,default=8, help='')
opt.parser.add_argument('--model',type=str,default='BiSeNet', help='BiSeNet or UNet')

opt.parser.add_argument('--maxepoch',type=int,default=100, help='')
opt.parser.add_argument('--savefreq',type=int,default=5, help='')
opt.parser.add_argument('--maxload',type=int,default=1000000, help='')
opt.parser.add_argument('--continuetrain', action='store_true', help='')
opt.parser.add_argument('--startepoch',type=int,default=0, help='')
opt.parser.add_argument('--dataset',type=str,default='./datasets/face/', help='')
opt.parser.add_argument('--savename',type=str,default='face', help='')
コード例 #9
0
import os
import sys
sys.path.append("..")
from cores import Options
opt = Options()

import random
import datetime
import time
import warnings
warnings.filterwarnings(action='ignore')

import numpy as np
import cv2
import torch

from models import runmodel, loadmodel
import util.image_processing as impro
from util import util, mosaic, data

opt.parser.add_argument('--datadir',
                        type=str,
                        default='../datasets/draw/face',
                        help='')
opt.parser.add_argument('--savedir',
                        type=str,
                        default='../datasets/pix2pix/face',
                        help='')
opt.parser.add_argument('--name', type=str, default='', help='save name')
opt.parser.add_argument(
    '--mod',
コード例 #10
0
import os
import sys
sys.path.append("..")
sys.path.append("../..")
from cores import Options
opt = Options()

import numpy as np
import cv2
import random
import torch
import torch.nn as nn
import time

from util import util,data,dataloader
from util import image_processing as impro
from models import BVDNet,model_util
from skimage.metrics import structural_similarity
from tensorboardX import SummaryWriter

'''
--------------------------Get options--------------------------
'''
opt.parser.add_argument('--N',type=int,default=2, help='The input tensor shape is H×W×T×C, T = 2N+1')
opt.parser.add_argument('--S',type=int,default=3, help='Stride of 3 frames')
# opt.parser.add_argument('--T',type=int,default=7, help='T = 2N+1')
opt.parser.add_argument('--M',type=int,default=100, help='How many frames read from each videos')
opt.parser.add_argument('--lr',type=float,default=0.0002, help='')
opt.parser.add_argument('--beta1',type=float,default=0.9, help='')
opt.parser.add_argument('--beta2',type=float,default=0.999, help='')
opt.parser.add_argument('--finesize',type=int,default=256, help='')