From eab65a1f201fda94cbc9bcbc711bfd50b40453d3 Mon Sep 17 00:00:00 2001 From: nagadomi Date: Mon, 13 Jun 2016 12:44:06 +0900 Subject: [PATCH] Update assets; remove photo option --- assets/index.de.html | 81 ++++++++++++++- assets/index.es.html | 81 ++++++++++++++- assets/index.fr.html | 81 ++++++++++++++- assets/index.html | 81 ++++++++++++++- assets/index.ja.html | 81 ++++++++++++++- assets/index.pt.html | 81 ++++++++++++++- assets/index.ru.html | 81 ++++++++++++++- assets/index.tr.html | 81 ++++++++++++++- assets/index.zh-CN.html | 81 ++++++++++++++- assets/style.css | 4 + assets/ui.js | 48 ++++++++- web.lua | 175 +++++++++++++------------------- webgen/templates/index.html.erb | 2 + 13 files changed, 842 insertions(+), 116 deletions(-) diff --git a/assets/index.de.html b/assets/index.de.html index d284fc3..543ab34 100644 --- a/assets/index.de.html +++ b/assets/index.de.html @@ -73,7 +73,7 @@ Oder wählen Sie eine Datei aus: -
+
Beschränkungen: Größe: 3MB, Rauschunterdrückung: 2560x2560px, maximale Hochskalierung: 1280x1280px.
@@ -87,11 +87,13 @@ Kunst +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/index.es.html b/assets/index.es.html index bee3673..f384200 100644 --- a/assets/index.es.html +++ b/assets/index.es.html @@ -73,7 +73,7 @@ O selecciona un archivo: -
+
Límites: Tamaño: 3 MB, Reducción de ruido: 2560x2560px, Aumento de resolución: 1280x1280px.
@@ -87,11 +87,13 @@ Ilustración +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/index.fr.html b/assets/index.fr.html index ae81821..5f33774 100644 --- a/assets/index.fr.html +++ b/assets/index.fr.html @@ -73,7 +73,7 @@ Ou choisissez un fichier : -
+
Limites : Taille : 3 Mo, Réduction du bruit numérique, 2560x2560px, Agrandissement : 1280x1280px.
@@ -87,11 +87,13 @@ Dessin +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/index.html b/assets/index.html index 6bbb613..8c526b3 100644 --- a/assets/index.html +++ b/assets/index.html @@ -73,7 +73,7 @@ Or choose a file: -
+
Limits: Size: 3MB, Noise Reduction: 2560x2560px, Upscaling: 1280x1280px.
@@ -87,11 +87,13 @@ Artwork +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/index.ja.html b/assets/index.ja.html index 24aa4d2..ff72129 100644 --- a/assets/index.ja.html +++ b/assets/index.ja.html @@ -73,7 +73,7 @@ ファイルを選択: -
+
制限: サイズ: 3MB, ノイズ除去: 2560x2560px, 拡大(前): 1280x1280px.
@@ -87,11 +87,13 @@ イラスト +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTAは安定した品質を作ります。ただし画像サイズに制限があります。 + + ルール + + +
+
diff --git a/assets/index.pt.html b/assets/index.pt.html index 9e68caf..97ce7f3 100644 --- a/assets/index.pt.html +++ b/assets/index.pt.html @@ -73,7 +73,7 @@ ARQUIVO: -
+
Limites: Tamanho: 3MB, Redução de ruído: 2560x2560px, Aumento de escala: 1280x1280px.
@@ -87,11 +87,13 @@ Arte +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/index.ru.html b/assets/index.ru.html index 7a8c02b..2a00f22 100644 --- a/assets/index.ru.html +++ b/assets/index.ru.html @@ -73,7 +73,7 @@ Либо выберите файл: -
+
Макс. размер файла — 3MB, устранение шума — макс. 2560x2560px, апскейл — 1280x1280px.
@@ -87,11 +87,13 @@ Арт +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/index.tr.html b/assets/index.tr.html index 57917de..73e5cc1 100644 --- a/assets/index.tr.html +++ b/assets/index.tr.html @@ -73,7 +73,7 @@ Veya bir dosya seçin: -
+
Limitler: Boyut: 3MB, Gürültü Azaltma: 2560x2560px, Çözünürlük Yükseltme: 1280x1280px.
@@ -87,11 +87,13 @@ Dijital Çizim +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/index.zh-CN.html b/assets/index.zh-CN.html index 2391d6b..5828703 100644 --- a/assets/index.zh-CN.html +++ b/assets/index.zh-CN.html @@ -73,7 +73,7 @@ 或者从本地上传: -
+
文件大小不得超过3MB;可降噪图像的最大尺寸:2560x2560px;可放大图像的最大尺寸:1280x1280px。
@@ -87,11 +87,13 @@ 插图 +
@@ -152,6 +154,83 @@
+
+
+ TTA: +
+
+
+ + + +
+
+ TTA makes stable quality but it limits the source image size. + + Show the rule of `n-pass auto`. + + +
+
diff --git a/assets/style.css b/assets/style.css index a11bb52..28306f9 100644 --- a/assets/style.css +++ b/assets/style.css @@ -196,3 +196,7 @@ label { .address { text-align: center; } +.tta_rule_text td { + padding: 4px; + border: 1px solid #ccc; +} diff --git a/assets/ui.js b/assets/ui.js index 0f90bb5..b278cf8 100644 --- a/assets/ui.js +++ b/assets/ui.js @@ -1,5 +1,8 @@ $(function (){ - var expires = 365; + var g_expires = 365; + var g_max_noise_image = 2560 * 2560; + var g_max_scale_image = 1280 * 1280; + function clear_file() { var new_file = $("#file").clone(); new_file.change(clear_url); @@ -15,17 +18,48 @@ $(function (){ } else { $(".main-title").html("w/a/ifu2x"); } - $.cookie("style", checked.val(), {expires: expires}); + $.cookie("style", checked.val(), {expires: g_expires}); + } + function on_click_tta_rule(e) { + e.preventDefault(); + e.stopPropagation(); + $(".tta_rule_text").toggle(); + } + function on_change_tta_level(e) { + var checked = $("input[name=tta_level]:checked"); + $.cookie("tta_level", checked.val(), {expires: g_expires}); + var level = checked.val(); + if (level == 0) { + level = 1; + } + var max_noise_w = Math.floor(Math.pow(g_max_noise_image / level, 0.5)); + var max_scale_w = Math.floor(Math.pow(g_max_scale_image / level, 0.5)); + var limit_text = $(".file_limits").text(); + var hits = 0; + limit_text = limit_text.replace(/\d+x\d+/g, function() { + hits += 1; + if (hits == 1) { + return "" + max_noise_w + "x" + max_noise_w; + } else { + return "" + max_scale_w + "x" + max_scale_w; + } + }); + $(".file_limits").text(limit_text); + if (level == 1) { + $(".file_limits").css("color", ""); + } else { + $(".file_limits").css("color", "blue"); + } } function on_change_noise_level(e) { var checked = $("input[name=noise]:checked"); - $.cookie("noise", checked.val(), {expires: expires}); + $.cookie("noise", checked.val(), {expires: g_expires}); } function on_change_scale_factor(e) { var checked = $("input[name=scale]:checked"); - $.cookie("scale", checked.val(), {expires: expires}); + $.cookie("scale", checked.val(), {expires: g_expires}); } function restore_from_cookie() { @@ -38,6 +72,9 @@ $(function (){ if ($.cookie("scale")) { $("input[name=scale]").filter("[value=" + $.cookie("scale") + "]").prop("checked", true) } + if ($.cookie("tta_level")) { + $("input[name=tta_level]").filter("[value=" + $.cookie("tta_level") + "]").prop("checked", true) + } } function uuid() { @@ -85,10 +122,13 @@ $(function (){ $("input[name=style]").change(on_change_style); $("input[name=noise]").change(on_change_noise_level); $("input[name=scale]").change(on_change_scale_factor); + $("input[name=tta_level]").change(on_change_tta_level); $("input[name=download]").click(download_with_xhr); + $("a.tta_rule").click(on_click_tta_rule); restore_from_cookie(); on_change_style(); on_change_scale_factor(); on_change_noise_level(); + on_change_tta_level(); }) diff --git a/web.lua b/web.lua index 55694e9..a8e9f2e 100644 --- a/web.lua +++ b/web.lua @@ -43,14 +43,16 @@ end opt.force_cudnn = opt.force_cudnn == 1 local ART_MODEL_DIR = path.join(ROOT, "models", "upconv_7", "art") local PHOTO_MODEL_DIR = path.join(ROOT, "models", "photo") -local art_scale2_model = w2nn.load_model(path.join(ART_MODEL_DIR, "scale2.0x_model.t7"), opt.force_cudnn) -local art_noise1_model = w2nn.load_model(path.join(ART_MODEL_DIR, "noise1_model.t7"), opt.force_cudnn) -local art_noise2_model = w2nn.load_model(path.join(ART_MODEL_DIR, "noise2_model.t7"), opt.force_cudnn) -local art_noise3_model = w2nn.load_model(path.join(ART_MODEL_DIR, "noise3_model.t7"), opt.force_cudnn) -local photo_scale2_model = w2nn.load_model(path.join(PHOTO_MODEL_DIR, "scale2.0x_model.t7"), opt.force_cudnn) -local photo_noise1_model = w2nn.load_model(path.join(PHOTO_MODEL_DIR, "noise1_model.t7"), opt.force_cudnn) -local photo_noise2_model = w2nn.load_model(path.join(PHOTO_MODEL_DIR, "noise2_model.t7"), opt.force_cudnn) -local photo_noise3_model = w2nn.load_model(path.join(PHOTO_MODEL_DIR, "noise3_model.t7"), opt.force_cudnn) +local art_model = {} +art_model.scale = w2nn.load_model(path.join(ART_MODEL_DIR, "scale2.0x_model.t7"), opt.force_cudnn) +art_model.noise1_scale = w2nn.load_model(path.join(ART_MODEL_DIR, "noise1_scale2.0x_model.t7"), opt.force_cudnn) +art_model.noise2_scale = w2nn.load_model(path.join(ART_MODEL_DIR, "noise2_scale2.0x_model.t7"), opt.force_cudnn) +art_model.noise3_scale = w2nn.load_model(path.join(ART_MODEL_DIR, "noise3_scale2.0x_model.t7"), opt.force_cudnn) +art_model.noise1 = w2nn.load_model(path.join(ART_MODEL_DIR, "noise1_model.t7"), opt.force_cudnn) +art_model.noise2 = w2nn.load_model(path.join(ART_MODEL_DIR, "noise2_model.t7"), opt.force_cudnn) +art_model.noise3 = w2nn.load_model(path.join(ART_MODEL_DIR, "noise3_model.t7"), opt.force_cudnn) +local photo_model = art_model -- TODO + collectgarbage() local CLEANUP_MODEL = false -- if you are using the low memory GPU, you could use this flag. local CACHE_DIR = path.join(ROOT, "cache") @@ -63,7 +65,6 @@ local CURL_OPTIONS = { max_redirects = 2 } local CURL_MAX_SIZE = 3 * 1024 * 1024 -local TTA_SUPPORT = true local function valid_size(x, scale, tta_level) if scale == 0 then @@ -170,67 +171,42 @@ local function convert(x, meta, options) meta.alpha = alpha return x, meta else + local model = nil if options.style == "art" then - if options.border then - x = alpha_util.make_border(x, alpha_orig, reconstruct.offset_size(art_scale2_model)) - end - if options.method == "scale" then - x = reconstruct.scale_tta(art_scale2_model, options.tta_level, 2.0, x, - opt.crop_size, opt.batch_size) - if alpha then - if not (alpha:size(2) == x:size(2) and alpha:size(3) == x:size(3)) then - alpha = reconstruct.scale(art_scale2_model, 2.0, alpha, - opt.crop_size, opt.batch_size) - image_loader.save_png(alpha_cache_file, alpha) - end + model = art_model + elseif options.style == "photo" then + model = photo_model + end + if options.border then + x = alpha_util.make_border(x, alpha_orig, reconstruct.offset_size(model.scale)) + end + if (options.method == "scale" or + options.method == "noise1_scale" or + options.method == "noise2_scale" or + options.method == "noise3_scale") + then + x = reconstruct.scale_tta(model[options.method], options.tta_level, 2.0, x, + opt.crop_size, opt.batch_size) + if alpha then + if not (alpha:size(2) == x:size(2) and alpha:size(3) == x:size(3)) then + alpha = reconstruct.scale(model.scale, 2.0, alpha, + opt.crop_size, opt.batch_size) + image_loader.save_png(alpha_cache_file, alpha) + cleanup_model(model.scale) end - cleanup_model(art_scale2_model) - elseif options.method == "noise1" then - x = reconstruct.image_tta(art_noise1_model, options.tta_level, - x, opt.crop_size, opt.batch_size) - cleanup_model(art_noise1_model) - elseif options.method == "noise2" then - x = reconstruct.image_tta(art_noise2_model, options.tta_level, - x, opt.crop_size, opt.batch_size) - cleanup_model(art_noise2_model) - elseif options.method == "noise3" then - x = reconstruct.image_tta(art_noise3_model, options.tta_level, - x, opt.crop_size, opt.batch_size) - cleanup_model(art_noise3_model) - end - else -- photo - if options.border then - x = alpha_util.make_border(x, alpha, reconstruct.offset_size(photo_scale2_model)) - end - if options.method == "scale" then - x = reconstruct.scale_tta(photo_scale2_model, options.tta_level, 2.0, x, - opt.crop_size, opt.batch_size) - if alpha then - if not (alpha:size(2) == x:size(2) and alpha:size(3) == x:size(3)) then - alpha = reconstruct.scale(photo_scale2_model, 2.0, alpha, - opt.crop_size, opt.batch_size) - image_loader.save_png(alpha_cache_file, alpha) - end - end - cleanup_model(photo_scale2_model) - elseif options.method == "noise1" then - x = reconstruct.image_tta(photo_noise1_model, options.tta_level, - x, opt.crop_size, opt.batch_size) - cleanup_model(photo_noise1_model) - elseif options.method == "noise2" then - x = reconstruct.image_tta(photo_noise2_model, options.tta_level, - x, opt.crop_size, opt.batch_size) - cleanup_model(photo_noise2_model) - elseif options.method == "noise3" then - x = reconstruct.image_tta(photo_noise3_model, options.tta_level, - x, opt.crop_size, opt.batch_size) - cleanup_model(photo_noise3_model) end + cleanup_model(model[options.method]) + elseif (options.method == "noise1" or + options.method == "noise2" or + options.method == "noise3") + then + x = reconstruct.image_tta(model[options.method], options.tta_level, + x, opt.crop_size, opt.batch_size) + cleanup_model(model[options.method]) end image_loader.save_png(cache_file, x) meta = tablex.copy(meta) meta.alpha = alpha - return x, meta end end @@ -264,15 +240,11 @@ function APIHandler:post() local style = self:get_argument("style", "art") local download = (self:get_argument("download", "")):len() - if not TTA_SUPPORT then - tta_level = 1 -- disable TTA mode - else - if tta_level == 0 then - tta_level = auto_tta_level(x, scale) - end - if not (tta_level == 0 or tta_level == 1 or tta_level == 2 or tta_level == 4 or tta_level == 8) then - tta_level = 1 - end + if tta_level == 0 then + tta_level = auto_tta_level(x, scale) + end + if not (tta_level == 0 or tta_level == 1 or tta_level == 2 or tta_level == 4 or tta_level == 8) then + tta_level = 1 end if style ~= "art" then style = "photo" -- style must be art or photo @@ -286,40 +258,37 @@ function APIHandler:post() if scale ~= 0 and meta.alpha then border = true end - if noise == 1 then - prefix = style .. "_noise1_tta_" .. tta_level .. "_" - x = convert(x, meta, {method = "noise1", style = style, tta_level = tta_level, - prefix = prefix .. hash, - alpha_prefix = alpha_prefix, border = border}) - border = false - elseif noise == 2 then - prefix = style .. "_noise2_tta_" .. tta_level .. "_" - x = convert(x, meta, {method = "noise2", style = style, tta_level = tta_level, - prefix = prefix .. hash, - alpha_prefix = alpha_prefix, border = border}) - border = false - elseif noise == 3 then - prefix = style .. "_noise3_tta_" .. tta_level .. "_" - x = convert(x, meta, {method = "noise3", style = style, tta_level = tta_level, - prefix = prefix .. hash, - alpha_prefix = alpha_prefix, border = border}) - border = false - end - if scale == 1 or scale == 2 then - if noise == 1 then - prefix = style .. "_noise1_scale_tta_" .. tta_level .. "_" - elseif noise == 2 then - prefix = style .. "_noise2_scale_tta_" .. tta_level .. "_" - elseif noise == 3 then - prefix = style .. "_noise3_scale_tta_" .. tta_level .. "_" - else - prefix = style .. "_scale_tta_" .. tta_level .. "_" - end - x, meta = convert(x, meta, {method = "scale", style = style, tta_level = tta_level, - prefix = prefix .. hash, alpha_prefix = alpha_prefix, border = border}) + if (scale == 1 or scale == 2) and (noise == 0) then + prefix = style .. "_scale_tta_" .. tta_level .. "_" + x, meta = convert(x, meta, {method = "scale", + style = style, + tta_level = tta_level, + prefix = prefix .. hash, + alpha_prefix = alpha_prefix, + border = border}) if scale == 1 then x = iproc.scale(x, x:size(3) * (1.6 / 2.0), x:size(2) * (1.6 / 2.0), "Sinc") end + elseif (scale == 1 or scale == 2) and (noise == 1 or noise == 2 or noise == 3) then + prefix = style .. string.format("_noise%d_scale_tta_", noise) .. tta_level .. "_" + x, meta = convert(x, meta, {method = string.format("noise%d_scale", noise), + style = style, + tta_level = tta_level, + prefix = prefix .. hash, + alpha_prefix = alpha_prefix, + border = border}) + if scale == 1 then + x = iproc.scale(x, x:size(3) * (1.6 / 2.0), x:size(2) * (1.6 / 2.0), "Sinc") + end + elseif (noise == 1 or noise == 2 or noise == 3) then + prefix = style .. string.format("_noise%d_tta_", noise) .. tta_level .. "_" + x = convert(x, meta, {method = string.format("noise%d", noise), + style = style, + tta_level = tta_level, + prefix = prefix .. hash, + alpha_prefix = alpha_prefix, + border = border}) + border = false end end local name = nil diff --git a/webgen/templates/index.html.erb b/webgen/templates/index.html.erb index 5d404ed..f0760a2 100644 --- a/webgen/templates/index.html.erb +++ b/webgen/templates/index.html.erb @@ -87,11 +87,13 @@ <%= t[:artwork] %> +