def procOutput(opt, out, *_): load = out['load'] node0 = Node(dict(op='toFloat'), load) bitDepthOut = out['bitDepth'] node1 = newNode(opt, dict(op='toOutput', bits=bitDepthOut), load) fOutput = node1.bindFunc(toOutput(bitDepthOut)) fs = [NonNullWrap(node0.bindFunc(toFloat)), NonNullWrap(fOutput)] ns = [node0, node1] if out['source']: fPreview[0] = restrictSize(2048) fs1 = [node0.bindFunc(toFloat), fOutput] if previewFormat: def o(im): res = reduce(applyNonNull, fs1, im) funcPreview(im) return [res] else: o = lambda im: [reduce(applyNonNull, fs1, im)] fs = [o] if out['channel']: fPreview[4] = BGR2RGB else: fPreview[4] = identity ns.append( appendFuncs(BGR2RGB, Node(dict(op='Channel')), fs1, False)) out['channel'] = 1 ns.append( appendFuncs(toBuffer(bitDepthOut), Node(dict(op='toBuffer', bits=bitDepthOut), load), fs1, False)) return fs, ns, out
def procInput(source, bitDepth, fs, out): out['load'] = 1 node = Node({'op': 'toTorch', 'bits': bitDepth}) fs.append( NonNullWrap( node.bindFunc(toTorch(bitDepth, config.dtype(), config.device())))) return fs, [node], out
def procDN(opt, out, *_): DNopt = opt['opt'] node = Node(dict(op='DN', model=opt['model']), out['load']) if 'name' in opt: node.name = opt['name'] return [NonNullWrap(node.bindFunc(lambda im: runDN.dn(im, DNopt))) ], [node], out
def genProcess(steps, root=True, outType=None): funcs=[] nodes=[] last = identity rf = lambda im: reduce(apply, funcs, im) if root: for i, opt in enumerate(steps): opt['name'] = i + (0 if steps[0]['op'] == 'file' else 2) for opt in filter((lambda opt: opt['op'] == 'SR'), steps): toInt(opt, ['scale', 'ensemble']) opt['opt'] = runSR.getOpt(opt) for opt in filter((lambda opt: opt['op'] == 'resize'), steps): toInt(opt, ['width', 'height']) if 'scaleW' in opt: opt['scaleW'] = float(opt['scaleW']) if 'scaleH' in opt: opt['scaleH'] = float(opt['scaleH']) for opt in filter((lambda opt: opt['op'] == 'DN'), steps): opt['opt'] = runDN.getOpt(opt) for opt in filter((lambda opt: opt['op'] == 'dehaze'), steps): opt['opt'] = dehaze.getOpt(opt) slomos = [*filter((lambda opt: opt['op'] == 'slomo'), steps)] for opt in slomos: toInt(opt, ['sf']) opt['opt'] = runSlomo.getOpt(opt) if len(slomos): slomos[-1]['opt'].notLast = 0 if steps[-1]['op'] != 'output': steps.append(dict(op='output')) config.getFreeMem(True) process = lambda im, name=None: last(rf(im), name, context) else: process = rf for i, opt in enumerate(steps): op = opt['op'] fs, ns, outType = procs[op](opt, outType, nodes) funcs.extend(fs) nodes.extend(ns) if op == 'slomo': if i + 1 < len(steps): f, nodesAfter = genProcess(steps[i + 1:], False, outType) else: f = identity nodesAfter = [] slomoOpt = opt['opt'] slomo = funcs[-1](f, nodes[-1], slomoOpt) funcs[-1] = windowWrap(slomo, slomoOpt, 2) nodeAfter = Node({}, total=opt['sf'], learn=0) for node in nodesAfter: nodeAfter.append(node) nodes.append(nodeAfter) break if root and steps[0]['op'] == 'file': n = Node({'op': 'write'}, outType['load']) nodes.append(n) last = n.bindFunc(writeFile) else: context.imageMode = 'RGB' return process, nodes
def genProcess(steps, root=True, outType=None): funcs = [] nodes = [] last = identity rf = lambda im: reduce(apply, funcs, im) if root: stepOffset = 0 if steps[0]['op'] == 'file' else 2 for i, opt in enumerate(steps): opt['name'] = i + stepOffset if opt['op'] == 'resize': if 'scaleW' in opt: opt['scaleW'] = float(opt['scaleW']) if 'scaleH' in opt: opt['scaleH'] = float(opt['scaleH']) if opt['op'] in stepOpts: stepOpt = stepOpts[opt['op']] toInt(opt, stepOpt.get('toInt', [])) if 'getOpt' in stepOpt: opt['opt'] = stepOpt['getOpt'].getOpt(opt) if steps[-1]['op'] != 'output': steps.append(dict(op='output')) config.getFreeMem(True) process = lambda im, name=None: last(rf(im), name, context) else: process = rf for i, opt in enumerate(steps): op = opt['op'] fs, ns, outType = procs[op](opt, outType, nodes) funcs.extend(fs) nodes.extend(ns) if op in videoOps: if i + 1 < len(steps): f, nodesAfter = genProcess(steps[i + 1:], False, outType) else: f = identity nodesAfter = [] videoOpt = opt['opt'] func = funcs[-1](f, nodes[-1], videoOpt) funcs[-1] = windowWrap(func, videoOpt, videoOps[op]) if videoOps[op] > 1 else func nodeAfter = Node({}, total=opt.get('sf', 1), learn=0) for node in nodesAfter: nodeAfter.append(node) nodes.append(nodeAfter) break if root and steps[0]['op'] == 'file': n = Node({'op': 'write'}, outType['load']) nodes.append(n) last = n.bindFunc(writeFile) else: context.imageMode = 'RGB' return process, nodes
def genProcess(steps, root=True, outType=None): funcs=[] nodes=[] last = identity rf = lambda im: reduce(apply, funcs, im) if root: for opt in filter((lambda opt: opt['op'] == 'SR'), steps): opt['scale'] = int(opt['scale']) opt['opt'] = runSR.getOpt(opt['scale'], opt['model'], config.ensembleSR) for opt in filter((lambda opt: opt['op'] == 'resize'), steps): opt['scale'] = int(opt['scale']) for opt in filter((lambda opt: opt['op'] == 'DN'), steps): opt['opt'] = runDN.getOpt(opt['model']) for opt in filter((lambda opt: opt['op'] == 'dehaze'), steps): opt['opt'] = dehaze.getOpt() slomos = [*filter((lambda opt: opt['op'] == 'slomo'), steps)] for opt in slomos: opt['sf'] = int(opt['sf']) opt['opt'] = runSlomo.getOpt(opt) if len(slomos): slomos[-1]['opt'].notLast = 0 steps.append(dict(op='output')) config.getFreeMem(True) process = lambda im, name=None: last(rf(im), name) else: process = rf for i, opt in enumerate(steps): op = opt['op'] fs, ns, outType = procs[op](opt, outType, nodes) funcs.extend(fs) nodes.extend(ns) if op == 'slomo': if i + 1 < len(steps): f, nodesAfter = genProcess(steps[i + 1:], False, outType) else: f = identity nodesAfter = [] slomoOpt = opt['opt'] slomo = funcs[-1](f, nodes[-1]) funcs[-1] = windowWrap(lambda data: slomo(data, slomoOpt), 2, runSlomo.getBatchSize(opt)) nodeAfter = Node({}, total=opt['sf'], learn=0) for node in nodesAfter: nodeAfter.append(node) nodes.append(nodeAfter) break if root and steps[0]['op'] == 'file': n = Node({'op': 'write'}, outType['load']) nodes.append(n) last = n.bindFunc(writeFile) return process, nodes
def procOutput(opt, out, *_): load = out['load'] node0 = Node(dict(op='toFloat'), load) bitDepthOut = out['bitDepth'] node1 = Node(dict(op='toOutput', bits=bitDepthOut), load, name=opt['name'] if 'name' in opt else None) fOutput = node1.bindFunc(toOutput(bitDepthOut)) fs = [NonNullWrap(node0.bindFunc(toFloat)), NonNullWrap(fOutput)] ns = [node0, node1] if out['source']: fs1 = [fOutput] def o(im): res = reduce(applyNonNull, fs1, im) funcPreview(im) return [res] fs[1] = o if out['channel']: fPreview[2] = BGR2RGB else: fPreview[2] = identity ns.append(appendFuncs(BGR2RGB, Node(dict(op='Channel')), fs1, False)) out['channel'] = 1 ns.append(appendFuncs(toBuffer(bitDepthOut), Node(dict(op='toBuffer', bits=bitDepthOut), load), fs1, False)) return fs, ns, out
def procResize(opt, out, nodes): node = Node(dict(op='resize', mode=opt['method']), 1, name=opt['name'] if 'name' in opt else None) return [node.bindFunc(NonNullWrap(resize(opt, out, len(nodes), nodes)))], [node], out