1
0
Fork 0
mirror of synced 2024-06-18 19:04:30 +12:00

Add support for photo model and cookie in web.lua

This commit is contained in:
nagadomi 2015-12-04 22:07:52 +09:00
parent c35abe33e5
commit 95a0b8ad09
5 changed files with 44 additions and 34 deletions

View file

@ -4,7 +4,8 @@
<meta charset="UTF-8">
<title>waifu2x</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script type="text/javascript" src="ui.js"></script>
</head>
<body>
@ -17,7 +18,7 @@
<a href="index.html">en</a>/<a href="index.ja.html">ja</a>/<a href="index.ru.html">ru</a>
</div>
<div class="about">
<div>Single-Image Super-Resolution for anime/fan-art using Deep Convolutional Neural Networks. <a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" target="_blank">about</a>.</div>
<div>Single-Image Super-Resolution for Anime-Style Art using Deep Convolutional Neural Networks. Also it is supported photo. <a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" target="_blank">about</a>.</div>
</div>
<form action="/api" method="POST" enctype="multipart/form-data" target="_blank">
<fieldset>
@ -32,6 +33,11 @@
Limits: Size: 2MB, Noise Reduction: 2560x2560px, Upscaling: 1280x1280px
</div>
</fieldset>
<fieldset>
<legend>Style</legend>
<label><input type="radio" name="style" value="art" checked>Art</label>
<label><input type="radio" name="style" value="photo">Photo</label>
</fieldset>
<fieldset class="noise-field">
<legend>Noise Reduction (expect JPEG Artifact)</legend>
<label><input type="radio" name="noise" value="0"> None</label>

View file

@ -5,6 +5,7 @@
<link href="style.css" rel="stylesheet" type="text/css">
<title>waifu2x</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script type="text/javascript" src="ui.js"></script>
</head>
<body>
@ -17,7 +18,7 @@
<a href="index.html">en</a>/<a href="index.ja.html">ja</a>/<a href="index.ru.html">ru</a>
</div>
<div class="about">
<div>深層畳み込みニューラルネットワークによる二次元画像のための超解像システム. <a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" target="_blank">about</a>.</div>
<div>深層畳み込みニューラルネットワークによる二次元画像のための超解像システム. 写真にも対応. <a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" target="_blank">about</a>.</div>
</div>
<form action="/api" method="POST" enctype="multipart/form-data" target="_blank">
<fieldset>
@ -32,6 +33,11 @@
制限: サイズ: 2MB, ノイズ除去: 2560x2560px, 拡大: 1280x1280px
</div>
</fieldset>
<fieldset>
<legend>スタイル</legend>
<label><input type="radio" name="style" value="art" checked>イラスト</label>
<label><input type="radio" name="style" value="photo">写真</label>
</fieldset>
<fieldset class="noise-field">
<legend>ノイズ除去 (JPEGイズを想定)</legend>
<label><input type="radio" name="noise" value="0"> なし</label>

View file

@ -6,6 +6,7 @@
<title>waifu2x</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script type="text/javascript" src="ui.js"></script>
</head>
<body>
@ -33,6 +34,11 @@
Макс. размер файла — 2MB, устранение шума — макс. 2560x2560px, апскейл — 1280x1280px
</div>
</fieldset>
<fieldset>
<legend>Стиль</legend>
<label><input type="radio" name="style" value="art" checked>Произведение искусства</label>
<label><input type="radio" name="style" value="photo">фото</label>
</fieldset>
<fieldset class="noise-field">
<legend>Устранение шума (артефактов JPEG)</legend>
<label><input type="radio" name="noise" value="0"> Нет</label>

View file

@ -1,4 +1,5 @@
$(function (){
var expires = 365;
function clear_file() {
var new_file = $("#file").clone();
new_file.change(clear_url);
@ -19,6 +20,7 @@ $(function (){
} else {
$("h1").html("w<s>/a/</s>ifu2x");
}
$.cookie("style", checked.val(), {expires: expires});
}
function on_change_noise_level(e)
{
@ -30,6 +32,7 @@ $(function (){
if (checked.val() != 0) {
checked.parents("label").css("font-weight", "bold");
}
$.cookie("noise", checked.val(), {expires: expires});
}
function on_change_scale_factor(e)
{
@ -41,40 +44,29 @@ $(function (){
if (checked.val() != 0) {
checked.parents("label").css("font-weight", "bold");
}
$.cookie("scale", checked.val(), {expires: expires});
}
function on_change_white_noise(e)
function restore_from_cookie()
{
$("input[name=white_noise]").parents("label").each(
function (i, elm) {
$(elm).css("font-weight", "normal");
});
var checked = $("input[name=white_noise]:checked");
if (checked.val() != 0) {
checked.parents("label").css("font-weight", "bold");
if ($.cookie("style")) {
$("input[name=style]").filter("[value=" + $.cookie("style") + "]").prop("checked", true)
}
}
function on_click_experimental_button(e)
{
if ($(this).hasClass("close")) {
$(".experimental .container").show();
$(this).removeClass("close");
} else {
$(".experimental .container").hide();
$(this).addClass("close");
if ($.cookie("noise")) {
$("input[name=noise]").filter("[value=" + $.cookie("noise") + "]").prop("checked", true)
}
if ($.cookie("scale")) {
$("input[name=scale]").filter("[value=" + $.cookie("scale") + "]").prop("checked", true)
}
e.preventDefault();
e.stopPropagation();
}
$("#url").change(clear_file);
$("#file").change(clear_url);
//$("input[name=style]").change(on_change_style);
$("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=white_noise]").change(on_change_white_noise);
//$(".experimental .button").click(on_click_experimental_button)
//on_change_style();
restore_from_cookie();
on_change_style();
on_change_scale_factor();
on_change_noise_level();
})

14
web.lua
View file

@ -12,8 +12,9 @@ local iproc = require 'iproc'
local reconstruct = require 'reconstruct'
local image_loader = require 'image_loader'
local alpha_util = require 'alpha_util'
local gm = require 'graphicsmagick'
-- Notes: turbo and xlua has different implementation of string:split().
-- Note: turbo and xlua has different implementation of string:split().
-- Therefore, string:split() has conflict issue.
-- In this script, use turbo's string:split().
local turbo = require 'turbo'
@ -36,13 +37,13 @@ if cudnn then
cudnn.benchmark = false
end
local ART_MODEL_DIR = path.join(ROOT, "models", "anime_style_art_rgb")
local PHOTO_MODEL_DIR = path.join(ROOT, "models", "ukbench")
local PHOTO_MODEL_DIR = path.join(ROOT, "models", "photo")
local art_noise1_model = torch.load(path.join(ART_MODEL_DIR, "noise1_model.t7"), "ascii")
local art_noise2_model = torch.load(path.join(ART_MODEL_DIR, "noise2_model.t7"), "ascii")
local art_scale2_model = torch.load(path.join(ART_MODEL_DIR, "scale2.0x_model.t7"), "ascii")
--local photo_scale2_model = torch.load(path.join(PHOTO_MODEL_DIR, "scale2.0x_model.t7"), "ascii")
--local photo_noise1_model = torch.load(path.join(PHOTO_MODEL_DIR, "noise1_model.t7"), "ascii")
--local photo_noise2_model = torch.load(path.join(PHOTO_MODEL_DIR, "noise2_model.t7"), "ascii")
local photo_scale2_model = torch.load(path.join(PHOTO_MODEL_DIR, "scale2.0x_model.t7"), "ascii")
local photo_noise1_model = torch.load(path.join(PHOTO_MODEL_DIR, "noise1_model.t7"), "ascii")
local photo_noise2_model = torch.load(path.join(PHOTO_MODEL_DIR, "noise2_model.t7"), "ascii")
local CLEANUP_MODEL = false -- if you are using the low memory GPU, you could use this flag.
local CACHE_DIR = path.join(ROOT, "cache")
local MAX_NOISE_IMAGE = 2560 * 2560
@ -143,7 +144,7 @@ local function convert(x, alpha, options)
x = reconstruct.image(art_noise2_model, x)
cleanup_model(art_noise2_model)
end
else --[[photo
else -- photo
if options.border then
x = alpha_util.make_border(x, alpha, reconstruct.offset_size(photo_scale2_model))
end
@ -163,7 +164,6 @@ local function convert(x, alpha, options)
x = reconstruct.image(photo_noise2_model, x)
cleanup_model(photo_noise2_model)
end
--]]
end
image_loader.save_png(cache_file, x)