1
0
Fork 0
mirror of synced 2024-06-13 16:34:32 +12:00

merge from master

This commit is contained in:
nagadomi 2015-10-26 09:39:41 +09:00
commit 956ae0d24c
7 changed files with 211 additions and 108 deletions

View file

@ -18,7 +18,15 @@ waifu2x is inspired by SRCNN [1]. 2D character picture (HatsuneMiku) is licensed
- [2] "For Creators", http://piapro.net/en_for_creators.html
## Public AMI
(maintenance)
```
AMI ID: ami-0be01e4f
AMI NAME: waifu2x-server
Instance Type: g2.2xlarge
Region: US West (N.California)
OS: Ubuntu 14.04
User: ubuntu
Created at: 2015-08-12
```
## Third Party Software
[Third-Party](https://github.com/nagadomi/waifu2x/wiki/Third-Party)
@ -32,64 +40,47 @@ waifu2x is inspired by SRCNN [1]. 2D character picture (HatsuneMiku) is licensed
- [Torch7](http://torch.ch/)
- [NVIDIA CUDA](https://developer.nvidia.com/cuda-toolkit)
### Packages (luarocks)
- cutorch
- cunn
- [graphicsmagick](https://github.com/clementfarabet/graphicsmagick)
- [turbo](https://github.com/kernelsauce/turbo)
### lualocks packages (excludes torch7's default packages)
- md5
- uuid
- [turbo](https://github.com/kernelsauce/turbo)
## Installation
### Setting Up the Command Line Tool Environment
(on Ubuntu 14.04)
#### Install Torch7
```
sudo apt-get install curl
curl -s https://raw.githubusercontent.com/torch/ezinstall/master/install-all | sudo bash
```
see [Torch (easy) install](https://github.com/torch/ezinstall)
#### Install CUDA
Google! Search keyword: "install cuda ubuntu"
See: [NVIDIA CUDA Getting Started Guide for Linux](http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/#ubuntu-installation)
#### Install packages
Download [CUDA](http://developer.nvidia.com/cuda-downloads)
```
sudo luarocks install cutorch
sudo luarocks install cunn
sudo apt-get install graphicsmagick libgraphicsmagick-dev
sudo luarocks install graphicsmagick
sudo dpkg -i cuda-repo-ubuntu1404_7.0-28_amd64.deb
sudo apt-get update
sudo apt-get install cuda
```
Test the waifu2x command line tool.
#### Install Torch7
See: [Getting started with Torch](http://torch.ch/docs/getting-started.html)
#### Validation
Test the waifu2x command line tool.
```
th waifu2x.lua
```
### Setting Up the Web Application Environment (if you needed)
#### Install luajit 2.0.4
```
curl -O http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -xzvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make
sudo make install
```
#### Install packages
Install luarocks packages.
```
sudo luarocks install md5
sudo luarocks install uuid
sudo luarocks install turbo
luarocks install md5
luarocks install uuid
PREFIX=$HOME/torch/install luarocks install turbo
```
## Web Application

View file

@ -1,19 +1,29 @@
upstream waifu2x {
server localhost:8812;
}
map $http_accept_language $lang {
default en;
~ja ja;
~en en;
~ru ru;
}
server {
server_name waifu2x.udp.jp;
# listen 80 default_server;
server_name waifu2x.udp.jp; # fill your domain
access_log /var/log/nginx/waifu2x.udp.jp.access.log;
access_log /var/log/nginx/waifu2x.access.log;
root /home/ubuntu/waifu2x/assets;
try_files $uri $uri/index.$lang.html $uri/index.html @api;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
location ~ ^/(apple-touch-icon|browserconfig|favicon|mstile)(.*)\.(png|xml|ico)$ {
return 204;
}
location @api {
proxy_pass http://waifu2x;
}
}

View file

@ -15,12 +15,14 @@
margin-bottom: 1em;
}
.about {
font-size: 0.8em;
margin: 1em 0 1em 0;
position: relative;
display: inline-block;
font-size: 0.9em;
padding: 1em 5px 0.2em 0;
}
.help {
font-size: 0.8em;
margin: 1em 0 1em 0;
font-size: 0.85em;
margin: 1em 0 0 0;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
@ -42,45 +44,46 @@
<body>
<h1>waifu2x</h1>
<div class="header">
<a href="https://github.com/nagadomi/waifu2x">
<img style="position: absolute; top: 0; left: 540px; border: 0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png">
</a>
<a href="index.ja.html">ja</a>/<a href="index.html">en</a>
<div style="position:absolute; display:block; top:0; left:540px; max-height:140px;">
<img style="position:absolute; display:block; left:0; top:0; width:149px; height:149px; border:0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png">
<a href="https://github.com/nagadomi/waifu2x" target="_blank" style="position:absolute; display:block; left:0; top:0; width:149px; height:130px;"></a>
</div>
<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.</div>
<div><a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" target="_blank">about</a>.</div>
<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>
<form action="/api" method="POST" enctype="multipart/form-data" target="_blank">
<fieldset>
<legend>Image</legend>
<div>
URL: <input id="url" type="text" name="url" style="width:400px"> or
</div>
<div>
FILE: <input id="file" type="file" name="file">
</div>
<div class="help">
Limits: Size: 2MB, Noise Reduction: 2560x2560px, Upscaling: 1280x1280px
</div>
<legend>Image</legend>
<div>
URL: <input id="url" type="text" name="url" style="width:400px"> or
</div>
<div>
FILE: <input id="file" type="file" name="file">
</div>
<div class="help">
Limits: Size: 2MB, Noise Reduction: 2560x2560px, Upscaling: 1280x1280px
</div>
</fieldset>
<fieldset>
<legend>Noise Reduction (expect JPEG Artifact)</legend>
<label><input type="radio" name="noise" value="0"> None</label>
<label><input type="radio" name="noise" value="1" checked="checked"> Low</label>
<label><input type="radio" name="noise" value="2"> High</label>
<legend>Noise Reduction (expect JPEG Artifact)</legend>
<label><input type="radio" name="noise" value="0"> None</label>
<label><input type="radio" name="noise" value="1" checked="checked"> Medium</label>
<label><input type="radio" name="noise" value="2"> High</label>
<div class="help">When using 2x scaling, we never recommend to use high level of noise reduction, it almost always makes image worse, it makes sense for only some rare cases when image had really bad quality from the beginning.</div>
</fieldset>
<fieldset>
<legend>Upscaling</legend>
<label><input type="radio" name="scale" value="0" checked="checked"> None</label>
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
<legend>Upscaling</legend>
<label><input type="radio" name="scale" value="0" checked="checked"> None</label>
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
</fieldset>
<input type="submit"/>
</form>
<div class="help">
<ul>
<li>If you are using Firefox, Please press the CTRL+S key to save image. "Save Image" option doesn't work.</li>
<ul style="padding-left: 15px;">
<li>If you are using Firefox, Please press the CTRL+S key to save image. "Save Image" option doesn't work.
</ul>
</div>
</body>

View file

@ -12,15 +12,17 @@
}
fieldset {
margin-top: 1em;
margin-bottom: 1em;
margin-bottom: 1em;
}
.about {
position: relative;
display: inline-block;
font-size: 0.8em;
margin: 1em 0 1em 0;
padding: 1em 5px 0.2em 0;
}
.help {
font-size: 0.8em;
margin: 1em 0 1em 0;
margin: 1em 0 0 0;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
@ -42,46 +44,46 @@
<body>
<h1>waifu2x</h1>
<div class="header">
<a href="https://github.com/nagadomi/waifu2x">
<img style="position: absolute; top: 0; left: 540px; border: 0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png">
</a>
<a href="index.ja.html">ja</a>/<a href="index.html">en</a>
<div style="position:absolute; display:block; top:0; left:540px; max-height:140px;">
<img style="position:absolute; display:block; left:0; top:0; width:149px; height:149px; border:0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png">
<a href="https://github.com/nagadomi/waifu2x" target="_blank" style="position:absolute; display:block; left:0; top:0; width:149px; height:130px;"></a>
</div>
<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>深層畳み込みニューラルネットワークによる二次元画像のための超解像システム.</div>
<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>
<legend>画像</legend>
<div>
URL: <input id="url" type="text" name="url" style="width:400px"> or
</div>
<div>
FILE: <input id="file" type="file" name="file">
</div>
<div class="help">
制限: サイズ: 2MB, ノイズ除去: 2560x2560px, 拡大: 1280x1280px
</div>
<legend>画像</legend>
<div>
URL: <input id="url" type="text" name="url" style="width:400px"> or
</div>
<div>
FILE: <input id="file" type="file" name="file">
</div>
<div class="help">
制限: サイズ: 2MB, ノイズ除去: 2560x2560px, 拡大: 1280x1280px
</div>
</fieldset>
<fieldset>
<legend>ノイズ除去 (JPEGイズを想定)</legend>
<label><input type="radio" name="noise" value="0"> なし</label>
<label><input type="radio" name="noise" value="1" checked="checked"></label>
<label><input type="radio" name="noise" value="2"></label>
<legend>ノイズ除去 (JPEGイズを想定)</legend>
<label><input type="radio" name="noise" value="0"> なし</label>
<label><input type="radio" name="noise" value="1" checked="checked"></label>
<label><input type="radio" name="noise" value="2"></label>
</fieldset>
<fieldset>
<legend>拡大</legend>
<label><input type="radio" name="scale" value="0" checked="checked"> なし</label>
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
<legend>拡大</legend>
<label><input type="radio" name="scale" value="0" checked="checked"> なし</label>
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
</fieldset>
<input type="submit" value="実行"/>
</form>
<div class="help">
<ul>
<li>なし/なしで入力画像を変換せずに出力する。ブラウザのタブで変換結果を比較したい人用。</li>
<li>Firefoxの方は、右クリから画像が保存できないようなので、CTRL+SキーかALTキー後 ファイル - ページを保存 で画像を保存してください。</li>
<ul style="padding-left: 15px;">
<li>なし/なしで入力画像を変換せずに出力する。ブラウザのタブで変換結果を比較したい人用。
<li>Firefoxの方は、右クリから画像が保存できないようなので、CTRL+SキーかALTキー後 ファイル - ページを保存 で画像を保存してください。
</ul>
</div>
</body>

90
assets/index.ru.html Normal file
View file

@ -0,0 +1,90 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="canonical" href="http://waifu2x.udp.jp/">
<title>waifu2x</title>
<style type="text/css">
body {
margin: 1em 2em 1em 2em;
background: LightGray;
width: 640px;
}
fieldset {
margin-top: 1em;
margin-bottom: 1em;
}
.about {
position: relative;
display: inline-block;
font-size: 0.9em;
padding: 1em 5px 0.2em 0;
}
.help {
font-size: 0.85em;
margin: 1em 0 0 0;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
function clear_file() {
var new_file = $("#file").clone();
new_file.change(clear_url);
$("#file").replaceWith(new_file);
}
function clear_url() {
$("#url").val("")
}
$(function (){
$("#url").change(clear_file);
$("#file").change(clear_url);
})
</script>
</head>
<body>
<h1>waifu2x</h1>
<div class="header">
<div style="position:absolute; display:block; top:0; left:540px; max-height:140px;">
<img style="position:absolute; display:block; left:0; top:0; width:149px; height:149px; border:0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png">
<a href="https://github.com/nagadomi/waifu2x" target="_blank" style="position:absolute; display:block; left:0; top:0; width:149px; height:130px;"></a>
</div>
<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>Увеличение в 4 раза рисованных изображений, например, аниме или фан-арт, а также устранение шума (преимущественно артефактов сжатия JPEG), см. <a href="https://raw.githubusercontent.com/nagadomi/waifu2x/master/images/slide.png" target="_blank">демонстрацию и сравнения</a></div>
</div>
<form action="/api" method="POST" enctype="multipart/form-data" target="_blank">
<fieldset>
<legend>Выбор изображения</legend>
<div>
Указать URL: <input id="url" type="text" name="url" style="width:400px">
</div>
<div>
Или загрузить файл: <input id="file" type="file" name="file">
</div>
<div class="help">
Макс. размер файла — 2MB, устранение шума — макс. 2560x2560px, апскейл — 1280x1280px
</div>
</fieldset>
<fieldset>
<legend>Устранение шума (артефактов JPEG)</legend>
<label><input type="radio" name="noise" value="0"> Нет</label>
<label><input type="radio" name="noise" value="1" checked="checked"> Средне</label>
<label><input type="radio" name="noise" value="2"> Сильно (не рекомендуется)</label>
<div class="help">Устранение шума нужно использовать, если на картинке действительно есть шум, иначе это даст противоположный эффект. Также не рекомендуется сильное устранение шума, оно даёт выгоду только в редких случаях, когда картинка изначально была сильно испорчена.</div>
</fieldset>
<fieldset>
<legend>Апскейл (увеличение размера)</legend>
<label><input type="radio" name="scale" value="0" checked="checked"> Нет</label>
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
</fieldset>
<input type="submit"/>
</form>
<div class="help">
<ul style="padding-left: 15px;">
<li>Если Вы используете Firefox, для сохранения изображения Вам придётся нажать Ctrl+S (опция в меню "Сохранить изображение" работать не будет!)
</ul>
</div>
</body>
</html>

View file

@ -1,5 +1,8 @@
require 'torch'
require 'nn'
local function load_cuda()
require 'nn'
require 'cutorch'
require 'cunn'
end
local function load_cudnn()
@ -9,13 +12,6 @@ end
if pcall(load_cuda) then
else
--[[ TODO: fakecuda does not work.
io.stderr:write("use FakeCUDA; if you have NVIDIA GPU, Please install cutorch and cunn. FakeCuda will be extremely slow.\n")
require 'torch'
require 'nn'
require('fakecuda').init(true)
--]]
end
if pcall(load_cudnn) then
end

13
web.lua
View file

@ -177,6 +177,7 @@ function APIHandler:post()
end
local FormHandler = class("FormHandler", turbo.web.RequestHandler)
local index_ja = file.read("./assets/index.ja.html")
local index_ru = file.read("./assets/index.ru.html")
local index_en = file.read("./assets/index.html")
function FormHandler:get()
local lang = self.request.headers:get("Accept-Language")
@ -187,6 +188,8 @@ function FormHandler:get()
end
if langs[1] == "ja" then
self:write(index_ja)
elseif langs[1] == "ru" then
self:write(index_ru)
else
self:write(index_en)
end
@ -194,12 +197,20 @@ function FormHandler:get()
self:write(index_en)
end
end
turbo.log.categories = {
["success"] = true,
["notice"] = false,
["warning"] = true,
["error"] = true,
["debug"] = false,
["development"] = false
}
local app = turbo.web.Application:new(
{
{"^/$", FormHandler},
{"^/index.html", turbo.web.StaticFileHandler, path.join("./assets", "index.html")},
{"^/index.ja.html", turbo.web.StaticFileHandler, path.join("./assets", "index.ja.html")},
{"^/index.ru.html", turbo.web.StaticFileHandler, path.join("./assets", "index.ru.html")},
{"^/api$", APIHandler},
}
)