1
0
Fork 0
mirror of synced 2024-05-16 10:52:20 +12:00

Merge branch 'dev'

This commit is contained in:
nagadomi 2018-04-28 11:08:05 +09:00
commit 3c46906cb7
34 changed files with 800 additions and 41 deletions

2
NOTICE
View file

@ -1,2 +1,4 @@
images/miku_*: CC BY-NC by piapro (http://piapro.net/en_for_creators.html)
webgen/assets/bg.png: Generated by chibichara maker (http://tetrabo.com/chibichara/).
lib/sRGB2014.lua: sRGB2014.icc from http://www.color.org/srgbprofiles.xalter

View file

@ -39,7 +39,7 @@ git pull
[Third-Party](https://github.com/nagadomi/waifu2x/wiki/Third-Party)
If you are a windows user, I recommend you to use [waifu2x-caffe](https://github.com/lltcggie/waifu2x-caffe)(Just download from `releases` tab) or [waifu2x-conver-cpp](https://github.com/tanakamura/waifu2x-converter-cpp).
If you are a windows user, I recommend you to use [waifu2x-caffe](https://github.com/lltcggie/waifu2x-caffe)(Just download from `releases` tab) or [waifu2x-conver-cpp](https://github.com/DeadSix27/waifu2x-converter-cpp).
## Dependencies

View file

@ -17,6 +17,8 @@ map $http_accept_language $lang {
~zh-TW zh-TW;
~zh zh-CN;
~ko ko;
~nl nl;
~ca ca;
~en en;
}

195
assets/index.ca.html Normal file
View file

@ -0,0 +1,195 @@
<!DOCTYPE html>
<html lang="ca">
<!-- This file was automatically generated by webgen/gen.rb. Do not make changes to this file manually. -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico"/>
<meta name="viewport" content="initial-scale=1.0,width=device-width">
<link href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css" rel="stylesheet" type="text/css">
<link href="style.css" rel="stylesheet" type="text/css">
<link href="mobile.css" rel="stylesheet" type="text/css" media="screen and (max-width: 768px) and (min-width: 0px)">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/URI.js/1.18.1/URI.min.js"></script>
<script type="text/javascript" src="ui.js"></script>
<title>waifu2x</title>
</head>
<body>
<div class="all-page">
<h1 class="main-title">waifu2x</h1>
<div class="choose-lang">
<a href="index.html">
English
</a>
/
<a href="index.ja.html">
日本語
</a>
/
<a href="index.ru.html">
Русский
</a>
/
<a href="index.pt.html">
Português
</a>
/
<a href="index.es.html">
Español
</a>
/
<a href="index.fr.html">
Français
</a>
/
<a href="index.de.html">
Deutsch
</a>
/
<a href="index.tr.html">
Türkçe
</a>
/
<a href="index.zh-CN.html">
简体中文
</a>
/
<a href="index.zh-TW.html">
繁體中文
</a>
/
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Amplia la resolució d'il·lustracions d'estil anime utilitzant xarxes neuronals convolucionals profundes. I suporta fotos.</p>
<p class="margin1 link-box">
<a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" class="blue-link" target="_blank">
Mostra'n una demostració
</a>
|
<a href="https://github.com/nagadomi/waifu2x" class="blue-link" target="_blank">
Vés al GitHub
</a>
</p>
<form action="/api" method="POST" enctype="multipart/form-data" target="_blank">
<div class="option-box first">
<div class="option-left">Escolliu una imatge:</div>
<div class="option-right">
<input type="text" id="url" name="url" placeholder="Escriviu una URL">
<div class="option-right-small">
O escolliu un fitxer:
<input type="file" id="file" name="file"></div>
</div>
<div class="option-hint file_limits">
Límits: Mida: 5MB, Reducció de soroll: 3000x3000px, Sobreescalat: 1500x1500px.
</div>
</div>
<div class="option-box">
<div class="option-left">
Estil:
</div>
<div class="option-right">
<label><input type="radio" name="style" class="radio" value="art" checked>
<span class="r-text">
Il·lustració
</span>
</label>
<label><input type="radio" name="style" class="radio" value="photo">
<span class="r-text">
Foto
</span>
</label>
</div>
</div>
<div class="option-box">
<div class="option-left">
Reducció de soroll:
<div class="option-left-small">
(espera artefactes JPEG)
</div>
</div>
<div class="option-right">
<label><input type="radio" name="noise" class="radio" value="-1">
<span class="r-text">
Cap
</span>
</label>
<label><input type="radio" name="noise" class="radio" value="0" checked>
<span class="r-text">
Baixa
</span>
</label>
<label><input type="radio" name="noise" class="radio" value="1" checked>
<span class="r-text">
Mitjana
</span>
</label>
<label>
<input type="radio" name="noise" class="radio" value="2">
<span class="r-text">
Alta
</span>
</label>
<label>
<input type="radio" name="noise" class="radio" value="3">
<span class="r-text">
Molt alta
</span>
</label>
</div>
<div class="option-hint">
Utilitzeu la reducció de soroll si la imatge té soroll, si no, podeu aconseguir l'efecte contrari.
</div>
</div>
<div class="option-box">
<div class="option-left">
Sobreescalat:
<div class="option-left-small"></div>
</div>
<div class="option-right">
<label><input type="radio" name="scale" class="radio" value="-1" checked>
<span class="r-text">
Cap
</span>
</label>
<label><input type="radio" name="scale" class="radio" value="1">
<span class="r-text">
1.6x
</span>
</label>
<label><input type="radio" name="scale" class="radio" value="2">
<span class="r-text">
2x
</span>
</label>
</div>
</div>
<input type="submit" class="button" value="Converteix">
<input type="submit" name="download" value="Descarrega" class="button">
<div class="bottom-hint">
<ul>
<li>Si utilitzeu el Firefox, premeu la tecla Control+S per desar la imatge. L'opció "Desa la imatge" no funciona.</li>
</ul>
</div>
</form>
</div>
<div class="bottom-info address">
<a href="https://github.com/nagadomi/waifu2x" class="gray-link" target="_blank">waifu2x</a>
</div>
</body>
</html>

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Einzelbild Super-Auflösungs Konvertierung für Bilder im Anime Stil mithilfe eines künstlichen neuronalen Netzwerk. Zusätzlich dazu unterstützt es auch Fotos.</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Mejora la resolución de ilustraciones de tipo anime utilizando redes neuronales convolucionales. También es compatible con fotografías.</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Outil permettant la mise à l'échelle de n'importe quelle image de style "anime", par le biais de réseaux de neurones convolutionnels. Fonctionne également sur les photos.</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Single-Image Super-Resolution for Anime-Style Art using Deep Convolutional Neural Networks. And it supports photo.</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>深層畳み込みニューラルネットワークによる二次元画像のための超解像システム。 写真にも対応。</p>
<p class="margin1 link-box">

View file

@ -62,11 +62,19 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>컨볼루젼 신경망(CNN) 시스템을 통한 딥 러닝으로 2차원 이미지의 해상도를 개선합니다. 그림 뿐만 아니라 사진에도 대응합니다.</p>
<p>컨볼루 신경망(CNN) 시스템을 통한 딥 러닝으로 2차원 이미지의 해상도를 개선합니다. 그림뿐만 아니라 사진도 지원합니다.</p>
<p class="margin1 link-box">
<a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" class="blue-link" target="_blank">
실제 데모 보기
실제 예제 보기
</a>
|
<a href="https://github.com/nagadomi/waifu2x" class="blue-link" target="_blank">
@ -83,7 +91,7 @@
<input type="file" id="file" name="file"></div>
</div>
<div class="option-hint file_limits">
제한: 크기: 5MB, 노이즈 감소: 3000x3000px, 업스케일링: 1500x1500px.
제한: 크기: 5MB, 노이즈 감소: 3000x3000px, 확대: 1500x1500px.
</div>
</div>
<div class="option-box">
@ -107,7 +115,7 @@
<div class="option-left">
노이즈 감소:
<div class="option-left-small">
(JPEG 아티팩트 제외)
(JPEG 이미지에 권장)
</div>
</div>
<div class="option-right">
@ -118,7 +126,7 @@
</label>
<label><input type="radio" name="noise" class="radio" value="0" checked>
<span class="r-text">
Low
낮음
</span>
</label>
<label><input type="radio" name="noise" class="radio" value="1" checked>
@ -135,17 +143,17 @@
<label>
<input type="radio" name="noise" class="radio" value="3">
<span class="r-text">
</span>
</label>
</div>
<div class="option-hint">
실제로 노이즈가 있는 이미지에만 사용해야 하며, 그렇지 않을 경우 사진의 세세한 부분이 뭉개질 수 있습니다.
실제로 노이즈가 있는 이미지에만 사용해야 하며, 그렇지 않을 경우 세세한 부분이 뭉개질 수 있습니다.
</div>
</div>
<div class="option-box">
<div class="option-left">
업스케일링:
확대:
<div class="option-left-small"></div>
</div>
<div class="option-right">
@ -174,7 +182,7 @@
<div class="bottom-hint">
<ul>
<li>FireFox에서 이미지를 저장하려면 Ctrl+S를 누르세요. 오른쪽 클릭 > "이미지 저장"을 이용하면 정상적으로 동작하지 않습니다.</li>
<li>Firefox에서 이미지를 저장하려면 Ctrl+S를 누르십시오. ‘이미지 저장’ 옵션은 작동하지 않습니다.</li>
</ul>
</div>

195
assets/index.nl.html Normal file
View file

@ -0,0 +1,195 @@
<!DOCTYPE html>
<html lang="nl">
<!-- This file was automatically generated by webgen/gen.rb. Do not make changes to this file manually. -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico"/>
<meta name="viewport" content="initial-scale=1.0,width=device-width">
<link href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css" rel="stylesheet" type="text/css">
<link href="style.css" rel="stylesheet" type="text/css">
<link href="mobile.css" rel="stylesheet" type="text/css" media="screen and (max-width: 768px) and (min-width: 0px)">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/URI.js/1.18.1/URI.min.js"></script>
<script type="text/javascript" src="ui.js"></script>
<title>waifu2x</title>
</head>
<body>
<div class="all-page">
<h1 class="main-title">waifu2x</h1>
<div class="choose-lang">
<a href="index.html">
English
</a>
/
<a href="index.ja.html">
日本語
</a>
/
<a href="index.ru.html">
Русский
</a>
/
<a href="index.pt.html">
Português
</a>
/
<a href="index.es.html">
Español
</a>
/
<a href="index.fr.html">
Français
</a>
/
<a href="index.de.html">
Deutsch
</a>
/
<a href="index.tr.html">
Türkçe
</a>
/
<a href="index.zh-CN.html">
简体中文
</a>
/
<a href="index.zh-TW.html">
繁體中文
</a>
/
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Single-Image Super-Resolutie voor Anime-Style afbeeldingen met behulp van Deep Convolutional Neural Networks. Oh, en het ondersteunt foto's.</p>
<p class="margin1 link-box">
<a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" class="blue-link" target="_blank">
Toon volledige demonstratie
</a>
|
<a href="https://github.com/nagadomi/waifu2x" class="blue-link" target="_blank">
Ga naar GitHub
</a>
</p>
<form action="/api" method="POST" enctype="multipart/form-data" target="_blank">
<div class="option-box first">
<div class="option-left">Afbeelding selecteren:</div>
<div class="option-right">
<input type="text" id="url" name="url" placeholder="Typ je URL">
<div class="option-right-small">
Of selecteer een bestand:
<input type="file" id="file" name="file"></div>
</div>
<div class="option-hint file_limits">
Limieten: Grootte: 5MB, Ruis vermindering: 3000x3000px, Vergroting: 1500x1500px.
</div>
</div>
<div class="option-box">
<div class="option-left">
Stijl:
</div>
<div class="option-right">
<label><input type="radio" name="style" class="radio" value="art" checked>
<span class="r-text">
Artwork
</span>
</label>
<label><input type="radio" name="style" class="radio" value="photo">
<span class="r-text">
Foto
</span>
</label>
</div>
</div>
<div class="option-box">
<div class="option-left">
Ruis vermindering:
<div class="option-left-small">
(verwacht JPEG artifact)
</div>
</div>
<div class="option-right">
<label><input type="radio" name="noise" class="radio" value="-1">
<span class="r-text">
Geen
</span>
</label>
<label><input type="radio" name="noise" class="radio" value="0" checked>
<span class="r-text">
Laag
</span>
</label>
<label><input type="radio" name="noise" class="radio" value="1" checked>
<span class="r-text">
Gemiddeld
</span>
</label>
<label>
<input type="radio" name="noise" class="radio" value="2">
<span class="r-text">
Hoog
</span>
</label>
<label>
<input type="radio" name="noise" class="radio" value="3">
<span class="r-text">
Hoogste
</span>
</label>
</div>
<div class="option-hint">
Gebruik ruisvermindering alleen als de afbeelding ook daadwerkelijk ruis bevat, anders zal het effect omgekeerd zijn.
</div>
</div>
<div class="option-box">
<div class="option-left">
Vergroting:
<div class="option-left-small"></div>
</div>
<div class="option-right">
<label><input type="radio" name="scale" class="radio" value="-1" checked>
<span class="r-text">
Geen
</span>
</label>
<label><input type="radio" name="scale" class="radio" value="1">
<span class="r-text">
1.6x
</span>
</label>
<label><input type="radio" name="scale" class="radio" value="2">
<span class="r-text">
2x
</span>
</label>
</div>
</div>
<input type="submit" class="button" value="Converteer">
<input type="submit" name="download" value="Download" class="button">
<div class="bottom-hint">
<ul>
<li>Als je gebruik maakt van FireFox, gebruik dan CTRL + S om een afbeelding op te slaan. De "Save Image" "Afbeelding Opslaan" optie werkt niet.</li>
</ul>
</div>
</form>
</div>
<div class="bottom-info address">
<a href="https://github.com/nagadomi/waifu2x" class="gray-link" target="_blank">waifu2x</a>
</div>
</body>
</html>

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Single-Image Super-Resolution for Anime-Style Art using Deep Convolutional Neural Networks. And it supports photo.</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Waifu2x позволяет увеличивать в 2 раза рисованные изображения, например аниме или арт, а также устранять шум на изображении (преимущественно артефакты сжатия JPEG). Теперь также поддерживаются фотографии.</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>Derin Sarmalı Sinirsel Ağ ile çalışan anime stili çalışmalar için süper çözünürlük yükselticidir. Normal fotoğrafları da destekler.</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>本程序使用卷积神经网络对动漫风格的图片进行放大操作(支持照片)。</p>
<p class="margin1 link-box">

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p>使用深度卷積神經網路的二次元圖片超解析系統。同時支援照片處理。</p>
<p class="margin1 link-box">

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View file

@ -1,5 +1,5 @@
-- snapply compression for ByteTensor
require 'snappy'
local snappy = require 'snappy'
local compression = {}
compression.compress = function (bt)
@ -9,7 +9,7 @@ end
compression.decompress = function(data)
local size = data[1]
local dec = snappy.decompress(data[2]:string())
local bt = torch.ByteTensor(unpack(torch.totable(size)))
local bt = torch.ByteTensor(table.unpack(torch.totable(size)))
bt:storage():string(dec)
return bt
end

View file

@ -135,7 +135,7 @@ function image_loader.load_float(file)
if not fp then
error(file .. ": failed to load image")
end
local buff = fp:read("*a")
local buff = fp:read("*all")
fp:close()
return image_loader.decode_float(buff)
end
@ -144,7 +144,7 @@ function image_loader.load_byte(file)
if not fp then
error(file .. ": failed to load image")
end
local buff = fp:read("*a")
local buff = fp:read("*all")
fp:close()
return image_loader.decode_byte(buff)
end

View file

@ -176,6 +176,10 @@ end
settings.images = string.format("%s/images.t7", settings.data_dir)
settings.image_list = string.format("%s/image_list.txt", settings.data_dir)
-- patch for lua52
if not math.log10 then
math.log10 = function(x) return math.log(x, 10) end
end
if settings.gpu:len() > 0 then
local gpus = {}
local gpu_string = utils.split(settings.gpu, ",")

View file

@ -83,6 +83,11 @@ if opt.output_dir:len() > 0 then
dir.makepath(opt.output_dir)
end
-- patch for lua52
if not math.log10 then
math.log10 = function(x) return math.log(x, 10) end
end
local function rgb2y_matlab(x)
local y = torch.Tensor(1, x:size(2), x:size(3)):zero()
x = iproc.byte2float(x)

View file

@ -0,0 +1,138 @@
require 'pl'
local __FILE__ = (function() return string.gsub(debug.getinfo(2, 'S').source, "^@", "") end)()
package.path = path.join(path.dirname(__FILE__), "..", "lib", "?.lua;") .. package.path
require 'sys'
require 'w2nn'
local iproc = require 'iproc'
local reconstruct = require 'reconstruct'
local image_loader = require 'image_loader'
local CONV_LAYERS = {"nn.SpatialConvolutionMM",
"cudnn.SpatialConvolution",
"nn.SpatialFullConvolution",
"cudnn.SpatialFullConvolution"
}
local ACTIVATION_LAYERS = {"nn.ReLU",
"nn.LeakyReLU",
"w2nn.LeakyReLU",
"cudnn.ReLU",
"nn.SoftMax",
"cudnn.SoftMax"
}
local function includes(s, a)
for i = 1, #a do
if s == a[i] then
return true
end
end
return false
end
local function count_conv_layers(seq)
local count = 0
for k = 1, #seq.modules do
local mod = seq.modules[k]
local name = torch.typename(mod)
if name == "nn.ConcatTable" or includes(name, CONV_LAYERS) then
count = count + 1
end
end
return count
end
local function strip_conv_layers(seq, limit)
local new_seq = nn.Sequential()
local count = 0
for k = 1, #seq.modules do
local mod = seq.modules[k]
local name = torch.typename(mod)
if name == "nn.ConcatTable" or includes(name, CONV_LAYERS) then
new_seq:add(mod)
count = count + 1
if count == limit then
if seq.modules[k+1] ~= nil and
includes(torch.typename(seq.modules[k+1]), ACTIVATION_LAYERS) then
new_seq:add(seq.modules[k+1])
end
return new_seq
end
else
new_seq:add(mod)
end
end
return new_seq
end
local function save_layer_outputs(x, model, out)
local count = count_conv_layers(model)
print("conv layer count", count)
local output_file = path.join(out, string.format("layer-%d.png", 0))
image.save(output_file, x)
print("* save layer output " .. 0 .. ": " .. output_file)
for i = 1, count do
output_file = path.join(out, string.format("layer-%d.png", i))
print("* save layer output " .. i .. ": " .. output_file)
local test_model = strip_conv_layers(model, i)
test_model:cuda()
test_model:evaluate()
local z = test_model:forward(x:reshape(1, x:size(1), x:size(2), x:size(3)):cuda()):float()
z = z:reshape(z:size(2), z:size(3), z:size(4)) -- drop batch dim
z = image.toDisplayTensor({input=z, padding=2})
image.save(output_file, z)
collectgarbage()
end
end
local cmd = torch.CmdLine()
cmd:text()
cmd:text("waifu2x - visualize layer output")
cmd:text("Options:")
cmd:option("-i", "images/miku_small.png", 'path to input image')
cmd:option("-scale", 2, 'scale factor')
cmd:option("-o", "./layer_outputs", 'path to output dir')
cmd:option("-model_dir", "./models/upconv_7/art", 'path to model directory')
cmd:option("-name", "user", 'model name for user method')
cmd:option("-m", "noise_scale", 'method (noise|scale|noise_scale|user)')
cmd:option("-noise_level", 1, '(1|2|3)')
cmd:option("-force_cudnn", 0, 'use cuDNN backend (0|1)')
cmd:option("-gpu", 1, 'Device ID')
local opt = cmd:parse(arg)
cutorch.setDevice(opt.gpu)
opt.force_cudnn = opt.force_cudnn == 1
opt.model_path = path.join(opt.model_dir, string.format("%s_model.t7", opt.name))
local x, meta = image_loader.load_float(opt.i)
if x:size(2) > 256 or x:size(3) > 256 then
error(string.format("input image is too large: %dx%d", x:size(3), x:size(2)))
end
local model = nil
local new_x = nil
if opt.m == "noise" then
local model_path = path.join(opt.model_dir, ("noise%d_model.t7"):format(opt.noise_level))
model = w2nn.load_model(model_path, opt.force_cudnn)
if not model then
error("Load Error: " .. model_path)
end
elseif opt.m == "scale" then
local model_path = path.join(opt.model_dir, ("scale%.1fx_model.t7"):format(opt.scale))
model = w2nn.load_model(model_path, opt.force_cudnn)
if not model then
error("Load Error: " .. model_path)
end
elseif opt.m == "noise_scale" then
local model_path = path.join(opt.model_dir, ("noise%d_scale%.1fx_model.t7"):format(opt.noise_level, opt.scale))
model = w2nn.load_model(model_path, opt.force_cudnn)
elseif opt.m == "user" then
local model_path = opt.model_path
model = w2nn.load_model(model_path, opt.force_cudnn)
if not model then
error("Load Error: " .. model_path)
end
else
error("undefined method:" .. opt.method)
end
assert(model ~= nil)
assert(x ~= nil)
dir.makepath(opt.o)
save_layer_outputs(x, model, opt.o)

99
web.lua
View file

@ -12,6 +12,7 @@ local iproc = require 'iproc'
local reconstruct = require 'reconstruct'
local image_loader = require 'image_loader'
local alpha_util = require 'alpha_util'
local compression = require 'compression'
local gm = require 'graphicsmagick'
-- Note: turbo and xlua has different implementation of string:split().
@ -34,6 +35,7 @@ cmd:option("-curl_request_timeout", 60, "request_timeout for curl")
cmd:option("-curl_connect_timeout", 60, "connect_timeout for curl")
cmd:option("-curl_max_redirects", 2, "max_redirects for curl")
cmd:option("-max_body_size", 5 * 1024 * 1024, "maximum allowed size for uploaded files")
cmd:option("-cache_max", 200, "number of cached images on RAM")
local opt = cmd:parse(arg)
cutorch.setDevice(opt.gpu)
@ -75,6 +77,7 @@ local CLEANUP_MODEL = false -- if you are using the low memory GPU, you could us
local CACHE_DIR = path.join(ROOT, "cache")
local MAX_NOISE_IMAGE = opt.max_pixels
local MAX_SCALE_IMAGE = (math.sqrt(opt.max_pixels) / 2)^2
local PNG_DEPTH = 8
local CURL_OPTIONS = {
request_timeout = opt.curl_request_timeout,
connect_timeout = opt.curl_connect_timeout,
@ -167,26 +170,73 @@ local function cleanup_model(model)
model:clearState() -- release GPU memory
end
end
local function convert(x, meta, options)
local cache_file = path.join(CACHE_DIR, options.prefix .. ".png")
local alpha_cache_file = path.join(CACHE_DIR, options.alpha_prefix .. ".png")
local alpha = meta.alpha
local alpha_orig = alpha
if path.exists(alpha_cache_file) then
alpha = image_loader.load_float(alpha_cache_file)
if alpha:dim() == 2 then
alpha = alpha:reshape(1, alpha:size(1), alpha:size(2))
end
if alpha:size(1) == 3 then
alpha = image.rgb2y(alpha)
-- cache
local g_cache = {}
local function cache_count()
local count = 0
for _ in pairs(g_cache) do
count = count + 1
end
return count
end
local function cache_remove_old()
local old_time = nil
local old_key = nil
for k, v in pairs(g_cache) do
if old_time == nil or old_time > v.updated_at then
old_key = k
old_time = v.updated_at
end
end
if path.exists(cache_file) then
x = image_loader.load_float(cache_file)
if old_key then
g_cache[old_key] = nil
end
end
local function cache_compress(raw_image)
if raw_image then
compressed_image = compression.compress(iproc.float2byte(raw_image))
return compressed_image
else
return nil
end
end
local function cache_decompress(compressed_image)
if compressed_image then
local raw_image = compression.decompress(compressed_image)
return iproc.byte2float(raw_image)
else
return nil
end
end
local function cache_get(filename)
local cache = g_cache[filename]
if cache then
return {image = cache_decompress(cache.image),
alpha = cache_decompress(cache.alpha)}
else
return nil
end
end
local function cache_put(filename, image, alpha)
g_cache[filename] = {image = cache_compress(image),
alpha = cache_compress(alpha),
updated_at = os.time()};
local count = cache_count(g_cache)
if count > opt.cache_max then
cache_remove_old()
end
end
local function convert(x, meta, options)
local cache_file = path.join(CACHE_DIR, options.prefix .. ".png")
local alpha = meta.alpha
local alpha_orig = alpha
local cache = cache_get(cache_file)
if cache then
meta = tablex.copy(meta)
meta.alpha = alpha
return x, meta
meta.alpha = cache.alpha
return cache.image, meta
else
local model = nil
if options.style == "art" then
@ -209,7 +259,6 @@ local function convert(x, meta, options)
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
end
@ -223,7 +272,7 @@ local function convert(x, meta, options)
x, opt.crop_size, opt.batch_size)
cleanup_model(model[options.method])
end
image_loader.save_png(cache_file, x)
cache_put(cache_file, x, alpha)
meta = tablex.copy(meta)
meta.alpha = alpha
return x, meta
@ -259,6 +308,12 @@ function APIHandler:post()
local style = self:get_argument("style", "art")
local download = (self:get_argument("download", "")):len()
if client_disconnected(self) then
self:set_status(400)
self:write("client disconnected")
return
end
if tta_level == 0 then
tta_level = auto_tta_level(x, scale)
end
@ -321,7 +376,7 @@ function APIHandler:post()
name = uuid() .. ".png"
end
local blob = image_loader.encode_png(alpha_util.composite(x, meta.alpha),
tablex.update({depth = 8, inplace = true}, meta))
tablex.update({depth = PNG_DEPTH, inplace = true}, meta))
self:set_header("Content-Length", string.format("%d", #blob))
if download > 0 then
@ -354,6 +409,8 @@ local index_tr = file.read(path.join(ROOT, "assets", "index.tr.html"))
local index_zh_cn = file.read(path.join(ROOT, "assets", "index.zh-CN.html"))
local index_zh_tw = file.read(path.join(ROOT, "assets", "index.zh-TW.html"))
local index_ko = file.read(path.join(ROOT, "assets", "index.ko.html"))
local index_nl = file.read(path.join(ROOT, "assets", "index.nl.html"))
local index_ca = file.read(path.join(ROOT, "assets", "index.ca.html"))
local index_en = file.read(path.join(ROOT, "assets", "index.html"))
function FormHandler:get()
local lang = self.request.headers:get("Accept-Language")
@ -382,6 +439,10 @@ function FormHandler:get()
self:write(index_zh_tw)
elseif langs[1] == "ko" then
self:write(index_ko)
elseif langs[1] == "nl" then
self:write(index_nl)
elseif langs[1] == "ca" or langs[1] == "ca-ES" or langs[1] == "ca-FR" or langs[1] == "ca-IT" or langs[1] == "ca-AD" then
self:write(index_ca)
else
self:write(index_en)
end

30
webgen/locales/ca.yml Normal file
View file

@ -0,0 +1,30 @@
---
description: Amplia la resolució d'il·lustracions d'estil anime utilitzant xarxes neuronals convolucionals profundes. I suporta fotos.
show_demonstration: Mostra'n una demostració
go_to_github: Vés al GitHub
image_choosing: Escolliu una imatge
type_url: Escriviu una URL
choose_file: O escolliu un fitxer
file_limits: "Límits: Mida: 5MB, Reducció de soroll: 3000x3000px, Sobreescalat: 1500x1500px."
style: Estil
artwork: Il·lustració
photo: Foto
noise_reduction: Reducció de soroll
expect_jpeg: espera artefactes JPEG
nr_none: Cap
nr_low: Baixa
nr_medium: Mitjana
nr_high: Alta
nr_highest: Molt alta
nr_hint: "Utilitzeu la reducció de soroll si la imatge té soroll, si no, podeu aconseguir l'efecte contrari."
upscaling: Sobreescalat
up_none: Cap
tta: TTA
tta_best_effort: "n-pass auto"
tta_rule: "Mostra la regla de `n-pass auto`."
tta_hint: "El TTA estabilitza la qualitat però limita la mida de la imatge d'origen."
button_convert: Converteix
button_download: Descarrega
hints:
- "Si utilitzeu el Firefox, premeu la tecla Control+S per desar la imatge. L'opció \"Desa la imatge\" no funciona."

View file

@ -1,24 +1,25 @@
---
description: 컨볼루 신경망(CNN) 시스템을 통한 딥 러닝으로 2차원 이미지의 해상도를 개선합니다. 그림 뿐만 아니라 사진에도 대응합니다.
show_demonstration: 실제 데모 보기
description: 컨볼루 신경망(CNN) 시스템을 통한 딥 러닝으로 2차원 이미지의 해상도를 개선합니다. 그림뿐만 아니라 사진도 지원합니다.
show_demonstration: 실제 예제 보기
go_to_github: GitHub에서 보기
image_choosing: 이미지 선택
type_url: URL 입력
choose_file: 또는 파일 업로드
file_limits: "제한: 크기: 5MB, 노이즈 감소: 3000x3000px, 업스케일링: 1500x1500px."
file_limits: "제한: 크기: 5MB, 노이즈 감소: 3000x3000px, 확대: 1500x1500px."
style: 스타일
artwork: 그림
photo: 사진
noise_reduction: 노이즈 감소
expect_jpeg: JPEG 아티팩트 제외
expect_jpeg: JPEG 이미지에 권장
nr_none: 없음
nr_low: 낮음
nr_medium: 중간
nr_high: 높음
nr_highest:
nr_hint: "실제로 노이즈가 있는 이미지에만 사용해야 하며, 그렇지 않을 경우 사진의 세세한 부분이 뭉개질 수 있습니다."
upscaling: 업스케일링
nr_highest:
nr_hint: "실제로 노이즈가 있는 이미지에만 사용해야 하며, 그렇지 않을 경우 세세한 부분이 뭉개질 수 있습니다."
upscaling: 확대
up_none: 없음
button_convert: 변환
button_download: 다운로드
hints:
- "FireFox에서 이미지를 저장하려면 Ctrl+S를 누르세요. 오른쪽 클릭 > \"이미지 저장\"을 이용하면 정상적으로 동작하지 않습니다."
- "Firefox에서 이미지를 저장하려면 Ctrl+S를 누르십시오. ‘이미지 저장’ 옵션은 작동하지 않습니다."

30
webgen/locales/nl.yml Normal file
View file

@ -0,0 +1,30 @@
---
description: Single-Image Super-Resolutie voor Anime-Style afbeeldingen met behulp van Deep Convolutional Neural Networks. Oh, en het ondersteunt foto's.
show_demonstration: Toon volledige demonstratie
go_to_github: Ga naar GitHub
image_choosing: Afbeelding selecteren
type_url: Typ je URL
choose_file: Of selecteer een bestand
file_limits: "Limieten: Grootte: 5MB, Ruis vermindering: 3000x3000px, Vergroting: 1500x1500px."
style: Stijl
artwork: Artwork
photo: Foto
noise_reduction: Ruis vermindering
expect_jpeg: verwacht JPEG artifact
nr_none: Geen
nr_low: Laag
nr_medium: Gemiddeld
nr_high: Hoog
nr_highest: Hoogste
nr_hint: "Gebruik ruisvermindering alleen als de afbeelding ook daadwerkelijk ruis bevat, anders zal het effect omgekeerd zijn."
upscaling: Vergroting
up_none: Geen
tta: TTA
tta_best_effort: "n-pass auto"
tta_rule: "Vertoon de `n-pass auto` optie."
tta_hint: "TTA verzekerd een betere kwaliteit, maar het limiteerd de grootte van de afbeelding."
button_convert: Converteer
button_download: Download
hints:
- "Als je gebruik maakt van FireFox, gebruik dan CTRL + S om een afbeelding op te slaan. De \"Save Image\" \"Afbeelding Opslaan\" optie werkt niet."

View file

@ -62,6 +62,14 @@
<a href="index.ko.html">
한국어
</a>
/
<a href="index.nl.html">
Nederlands
</a>
/
<a href="index.ca.html">
Català
</a>
</div>
<p><%= t[:description] %></p>
<p class="margin1 link-box">