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