コード例 #1
0
ファイル: procedure.py プロジェクト: mindfyhh/MoePhoto
def procSR(opt, out, *_):
  load = out['load']
  scale = opt['scale']
  mode = opt['model']
  SRopt = opt['opt']
  es = SRopt.ensemble + 1
  if not scale > 1:
    raise TypeError('Invalid scale setting for SR.')
  out['load'] = load * scale * scale
  fs, ns = convertChannel(out) if out['channel'] and mode == 'gan' else ([], [])
  ns.append(appendFuncs(runSR.sr(SRopt), newNode(opt, dict(op='SR', model=mode, scale=scale), load * es), fs))
  return fs, ns, out
コード例 #2
0
ファイル: imageProcess.py プロジェクト: bugaosuni59/MoePhoto
def procSR(opt, out, *_):
  load = out['load']
  scale = opt['scale']
  mode = opt['model']
  SRopt = opt['opt']
  if not scale > 1:
    raise TypeError('Invalid scale setting for SR.')
  out['load'] = load * scale * scale
  fs, ns = convertChannel(out) if out['channel'] and mode == 'gan' else ([], [])
  ns.append(appendFuncs(lambda im: runSR.sr(im, SRopt), Node(dict(op='SR', model=mode), load), fs))
  if 'name' in opt:
    ns[-1].name = opt['name']
  return fs, ns, out
コード例 #3
0
def genProcess(scale=1,
               mode='a',
               dnmodel='no',
               dnseq='before',
               source='image',
               bitDepthIn=8,
               bitDepthOut=0):
    SRopt = runSR.getOpt(scale, mode, config.ensembleSR)
    DNopt = runDN.getOpt(dnmodel)
    config.getFreeMem(True)
    if not bitDepthOut:
        bitDepthOut = bitDepthIn
    quant = 1 << bitDepthIn
    funcs = []
    last = lambda im, _: im
    if source == 'file':
        funcs.append(readFile)
    elif source == 'buffer':
        funcs.append(toNumPy(bitDepthIn))
    funcs.append(toTorch(quant, config.dtype(), config.device()))
    if (dnseq == 'before') and (dnmodel != 'no'):
        funcs.append(lambda im: runDN.dn(im, DNopt))
    if (scale > 1):
        funcs.append(lambda im: runSR.sr(im, SRopt))
    if (dnseq == 'after') and (dnmodel != 'no'):
        funcs.append(lambda im: runDN.dn(im, DNopt))
    funcs.append(toOutput(bitDepthOut))
    if source == 'file':
        last = writeFile
    elif source == 'buffer':
        funcs.append(toBuffer(bitDepthOut))

    def process(im, name=None):
        im = reduce(apply, funcs, im)
        return last(im, name)

    return process