Пример #1
0
def sr(x, opt):
    sc = opt.scale
    sum = ensemble(
        x, opt.ensemble, {
            'opt': opt,
            'model': getModel(opt),
            'padding': 2 if sc == 3 else 1,
            'sc': sc
        })
    if opt.ensemble:
        return sum / (opt.ensemble + 1)
    else:
        return sum
Пример #2
0
def sr(x, opt):
  sc = opt.scale
  if opt.mode == 'lite.old':
    x = interpolate(x)
  sum = ensemble(x, opt.ensemble, {
    'opt': opt,
    'model': opt.modelCached,
    'padding': 2 if sc == 3 else 1,
    'sc': sc
  })
  if opt.ensemble:
    return sum / (opt.ensemble + 1)
  else:
    return sum
Пример #3
0
import numpy as np
from imageProcess import ensemble, genGetModel
from models import NetDN, SEDN
from config import config

model_dict = {
    '15': './model/l15/model_new.pth',
    '25': './model/l25/model_new.pth',
    '50': './model/l50/model_new.pth',
    'lite5': './model/dn_lite5/model_new.pth',
    'lite10': './model/dn_lite10/model_new.pth',
    'lite15': './model/dn_lite15/model_new.pth'
}
ramCoef = .9 / np.array([2700., 4106.9, 2400., 7405., 1253.4, 4304.2])

dn = lambda x, opt: ensemble(x, 0, {'opt': opt, 'model': getModel(opt)})

getModel = genGetModel(lambda opt, *args: NetDN()
                       if 'dn_lite' in opt.model else SEDN())

##################################


def getOpt(model):
    def opt():
        pass

    if not model in model_dict:
        return
    opt.model = model_dict[model]
Пример #4
0
refFile = 0  #'test/1566005911.7879605_ci.png'


def context():
    pass


opt = Option(
    ('test/{}.pth' if test else 'model/demoire/{}.pth').format(modelName))
opt.padding = 31
opt.ramCoef = 1 / 8000.
opt.align = 128
opt.modelCached = initModel(opt, weights=opt.model, f=lambda _: Net())
toTorch = lambda x: torch.from_numpy(np.array(x)).permute(2, 0, 1).to(
    dtype=config.dtype(), device=config.device()) / 256
time = 0.0
for pic in os.listdir(inputFolder):
    original = toTorch(readFile(context=context)(inputFolder + '/' + pic))
    ref = toTorch(readFile(context=context)(refFile + '/' +
                                            pic)) if refFile else original
    start = perf_counter()
    y = ensemble(opt)(original)
    time += perf_counter() - start
    print(pic, float(y.mean(dtype=torch.float)),
          float((y - ref).abs().mean(dtype=torch.float)))
    out = toOutput(8)(toFloat(y))
    writeFile(
        out,
        'download/{}.{}.png'.format(splitext(split(pic)[1])[0],
                                    modelName), context)
print(time)