### Install waifu2x Dependencies Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Installs necessary system packages for waifu2x on Ubuntu, including snappy for compression and graphicsmagick for image manipulation. SSL development libraries are also included for the web server functionality. ```Shell sudo apt-get install libsnappy-dev sudo apt-get install libgraphicsmagick1-dev sudo apt-get install libssl1.0-dev # for web server ``` -------------------------------- ### Clone and Install waifu2x Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Clones the waifu2x repository and installs its required Lua modules using a provided script. This is the primary method for obtaining and setting up the waifu2x command-line tool. ```Shell git clone --depth 1 https://github.com/nagadomi/waifu2x.git cd waifu2x ./install_lua_modules.sh ``` -------------------------------- ### Run waifu2x Docker Container (Web Server) Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This command runs the waifu2x Docker container, exposing port 8812 and starting the web server interface. ```bash docker run --gpus all -p 8812:8812 waifu2x th web.lua ``` -------------------------------- ### Install CUDA on Ubuntu Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Commands to install the CUDA toolkit on Ubuntu 16.04, including adding the repository and installing the package. This is a prerequisite for using waifu2x with GPU acceleration. ```Shell sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb sudo apt-get update sudo apt-get install cuda ``` -------------------------------- ### Run waifu2x Web Application Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Starts the web server component of waifu2x, allowing users to interact with the tool through a web browser. The application is typically accessible at http://localhost:8812/. ```Shell th web.lua ``` -------------------------------- ### Neural Network Sequential Model Source: https://github.com/nagadomi/waifu2x/blob/master/appendix/arch/upcunet.txt Defines a sequential model within the waifu2x network, processing input through a series of layers. This example shows a sequence involving nn.SelectTable and w2nn.InplaceClip01. ```Python nn.Sequential { [input -> (1) -> (2) -> output] (1): nn.SelectTable(2) (2): w2nn.InplaceClip01 } ``` -------------------------------- ### Configure Upstart Service for waifu2x Source: https://github.com/nagadomi/waifu2x/wiki/Server-guide This snippet shows how to copy the Upstart configuration file and manage the waifu2x service using initctl commands. It also details the arguments for the run-web.sh script, which include the GPU device ID and TCP port number. ```bash sudo cp appendix/waifu2x.upstart.conf /etc/init/waifu2x_1 sudo initctl waifu2x_1 ``` ```shell /home/ubuntu/waifu2x/appendix/run-web.sh ``` -------------------------------- ### Configure Nginx for waifu2x Source: https://github.com/nagadomi/waifu2x/wiki/Server-guide Instructions for setting up Nginx to serve the waifu2x application. This involves copying the Nginx configuration file, creating a symbolic link, and restarting the Nginx service. It also recommends setting client_max_body_size for file uploads. ```bash sudo cp appendix/waifu2x.nginx.conf /etc/nginx/sites-available/waifu2x.udp.jp sudo ln -s /etc/nginx/sites-available/waifu2x.udp.jp /etc/nginx/sites-enabled/ sudo service nginx restart ``` -------------------------------- ### Run waifu2x Command Line Tool Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Executes the main waifu2x Lua script to test its functionality. This command is used to initiate the image processing tasks. ```Shell th waifu2x.lua ``` -------------------------------- ### Build waifu2x Docker Image Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This command builds a Docker image for waifu2x from the current directory. The image is tagged as 'waifu2x'. ```bash docker build -t waifu2x . ``` -------------------------------- ### Run Waifu2x Benchmark (Photo) Source: https://github.com/nagadomi/waifu2x/blob/master/appendix/benchmark.md This command executes the Waifu2x benchmark for photo models. It requires specifying the dataset directory, model directory, and various parameters like filter, color mode, and whether to force CUDA/cuDNN. ```bash th tools/benchmark.lua -dir -model1_dir -method scale -filter Catrom -color y -range_bug 1 -tta <0|1> -force_cudnn 1 ``` -------------------------------- ### Generate File List for Training Data Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This command creates a file list of all PNG images in a specified directory, which is used as input for training waifu2x models. It's important to use noise-free images for training. ```bash find /path/to/image/dir -name "*.png" > data/image_list.txt ``` -------------------------------- ### Waifu2x Network - Padding and Output Layers Source: https://github.com/nagadomi/waifu2x/blob/master/appendix/arch/cunet.txt Illustrates the zero padding operations applied at different stages of the Waifu2x network and the final output layer configuration. ```Lua nn.SpatialZeroPadding(l=-4, r=-4, t=-4, b=-4) ... -> output ``` ```Lua nn.SpatialZeroPadding(l=-16, r=-16, t=-16, b=-16) ... -> output ``` ```Lua nn.SpatialZeroPadding(l=-20, r=-20, t=-20, b=-20) ... -> output ``` -------------------------------- ### Run waifu2x Docker Container (Image Processing) Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This command runs the waifu2x Docker container to process an image. It mounts the local 'images' directory into the container, forces cuDNN, applies 2x scaling, and saves the output. ```bash docker run --gpus all -v `pwd`/images:/images waifu2x th waifu2x.lua -force_cudnn 1 -m scale -scale 2 -i /images/miku_small.png -o /images/output.png ``` -------------------------------- ### Run waifu2x Docker Container with CUDA Cache Path Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This command runs the waifu2x Docker container and mounts a host volume to '/root/.nv/ComputeCache' for CUDA JIT caching. This can improve performance when running waifu2x within Docker. ```bash docker run --gpus all -v $PWD/ComputeCache:/root/.nv/ComputeCache waifu2x th waifu2x.lua --help ``` -------------------------------- ### Customize waifu2x Web Pages with Ruby Source: https://github.com/nagadomi/waifu2x/wiki/Server-guide This snippet demonstrates how to customize the web interface of the waifu2x server. It involves editing ERB template files and then running a Ruby script to generate the static HTML pages. ```ruby ruby webgen/gen.rb ``` -------------------------------- ### waifu2x Using Photo Model Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Applies the photo-specific model for image processing with waifu2x. This is done by specifying the `-model_dir models/photo` option in the command line. ```Shell th waifu2x.lua -model_dir models/photo -m scale -i input_image.png -o output_image.png ``` -------------------------------- ### Extract Images and Audio from Video using avconv Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This snippet demonstrates how to extract individual frames (as PNG images) and audio (as MP3) from a video file using the `avconv` command. It specifies a time range and frame rate for extraction. ```bash mkdir frames avconv -i data/raw.avi -ss 00:09:00 -t 00:03:00 -r 24 -f image2 frames/%06d.png avconv -i data/raw.avi -ss 00:09:00 -t 00:03:00 audio.mp3 ``` -------------------------------- ### Waifu2x Benchmark Script (Art) Source: https://github.com/nagadomi/waifu2x/blob/master/appendix/benchmark.md The benchmark script for art models is located in the appendix. Refer to the specified file for the exact command and parameters. ```bash See appendix/benchmark.sh ``` -------------------------------- ### Generate Video from Processed Images and Audio using avconv Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This command reconstructs a video file from a sequence of processed images and an audio file using `avconv`. It specifies the video codec, quality (CRF), and frame rate for the output video. ```bash avconv -f image2 -framerate 24 -i new_frames/%d.png -i audio.mp3 -r 24 -vcodec libx264 -crf 16 video.mp4 ``` -------------------------------- ### waifu2x Batch Conversion Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Processes multiple images in a directory for upscaling using waifu2x. It reads a list of image files and saves the processed output with a specified naming convention. ```Shell find /path/to/imagedir -name "*.png" -o -name "*.jpg" > image_list.txt th waifu2x.lua -m scale -l ./image_list.txt -o /path/to/outputdir/prefix_%d.png ``` -------------------------------- ### waifu2x 2x Upscaling Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Performs 2x image upscaling using waifu2x. This command takes an input image and outputs a higher-resolution version. ```Shell th waifu2x.lua -m scale -i input_image.png -o output_image.png ``` -------------------------------- ### Generate Image List using find and sort Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This command generates a sorted list of all PNG files within the 'frames' directory, saving the output to 'data/frame.txt'. This list is typically used as input for subsequent processing steps. ```bash find ./frames -name "*.png" |sort > data/frame.txt ``` -------------------------------- ### Usage: Apply 2x Upscaling with Custom Model Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script demonstrates using a trained waifu2x model for 2x upscaling. It requires the model directory, method, scale factor, input image, and output path. ```lua th waifu2x.lua -model_dir models/my_model -m scale -scale 2 -i images/miku_small.png -o output.png ``` -------------------------------- ### Convert Training Data using Lua Script Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script, `convert_data.lua`, is used to convert the prepared image data into a format suitable for training the waifu2x models. ```lua th convert_data.lua ``` -------------------------------- ### waifu2x Noise Reduction + 2x Upscaling Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Combines noise reduction and 2x upscaling in a single operation with waifu2x. The `-noise_level` parameter can be adjusted for desired noise reduction strength. ```Shell th waifu2x.lua -m noise_scale -noise_level 1 -i input_image.png -o output_image.png ``` ```Shell th waifu2x.lua -m noise_scale -noise_level 0 -i input_image.png -o output_image.png ``` ```Shell th waifu2x.lua -m noise_scale -noise_level 2 -i input_image.png -o output_image.png ``` ```Shell th waifu2x.lua -m noise_scale -noise_level 3 -i input_image.png -o output_image.png ``` -------------------------------- ### Usage: Apply 2x Upscaling and Noise Reduction Fusion with Custom Model Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script shows how to apply a trained waifu2x model that combines 2x upscaling and noise reduction. It requires the model directory, method, scale factor, noise level, input image, and output path. ```lua th waifu2x.lua -model_dir models/my_model -m noise_scale -scale 2 -noise_level 1 -i images/miku_small.png -o output.png ``` -------------------------------- ### Train Noise Reduction Model (Level 1) Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script trains a noise reduction model for waifu2x at level 1. It requires a model directory, specifies the method and noise level, and uses a test image to evaluate the training process. The best model is saved for later use. ```lua mkdir models/my_model th train.lua -model_dir models/my_model -method noise -noise_level 1 -test images/miku_noisy.png ``` -------------------------------- ### Waifu2x Network - Feature Concatenation and Addition Source: https://github.com/nagadomi/waifu2x/blob/master/appendix/arch/cunet.txt Demonstrates the use of ConcatTable and CAddTable for combining and adding feature maps at various points in the Waifu2x network architecture. ```Lua (1): nn.ConcatTable { input |`-> (1): nn.Identity `-> (2): nn.Sequential { [input -> (1) -> (2) -> (3) -> (4) -> (5) -> output] (1): nn.Sequential { [input -> (1) -> (2) -> (3) -> output] (1): nn.Mean (2): nn.Mean (3): nn.View(-1, 128, 1, 1) } (2): nn.SpatialConvolutionMM(128 -> 16, 1x1) (3): nn.ReLU (4): nn.SpatialConvolutionMM(16 -> 128, 1x1) (5): nn.Sigmoid } } ... } ``` ```Lua (2): nn.CAddTable ``` ```Lua (2): nn.CAddTable ``` ```Lua (3): nn.ConcatTable { input |`-> (1): nn.Identity `-> (2): nn.Sequential { [input -> (1) -> (2) -> (3) -> (4) -> (5) -> output] (1): nn.Sequential { [input -> (1) -> (2) -> (3) -> output] (1): nn.Mean (2): nn.Mean (3): nn.View(-1, 64, 1, 1) } (2): nn.SpatialConvolutionMM(64 -> 8, 1x1) (3): nn.ReLU (4): nn.SpatialConvolutionMM(8 -> 64, 1x1) (5): nn.Sigmoid } } ... } ``` -------------------------------- ### Train 2x Upscaling Model Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script trains a 2x upscaling model for waifu2x. It specifies the model architecture ('upconv_7'), model directory, method, scale factor, and uses a test image for training. ```lua th train.lua -model upconv_7 -model_dir models/my_model -method scale -scale 2 -test images/miku_small.png ``` -------------------------------- ### Usage: Apply Noise Reduction (Level 1) with Custom Model Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script demonstrates how to use a trained waifu2x model for noise reduction (level 1). It specifies the model directory, method, noise level, input image, and output path. ```lua th waifu2x.lua -model_dir models/my_model -m noise -noise_level 1 -i images/miku_noisy.png -o output.png ``` -------------------------------- ### waifu2x - Image Upscaling and Noise Reduction Source: https://github.com/nagadomi/waifu2x/blob/master/assets/index.tr.html This snippet demonstrates the core functionality of waifu2x, an AI-based image upscaler. It allows users to select an image, apply noise reduction, and increase the resolution. The tool supports various levels of noise reduction and upscaling factors (1.6x, 2x). It also provides a workaround for Firefox users to download images using CTRL+S. ```html ``` -------------------------------- ### Usage: Apply Noise Reduction (Level 2) with Custom Model Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script shows how to apply a trained waifu2x model for noise reduction at level 2. It requires the model directory, method, noise level, input image, and output path. ```lua th waifu2x.lua -model_dir models/my_model -m noise -noise_level 2 -i images/miku_noisy.png -o output.png ``` -------------------------------- ### Train 2x Upscaling and Noise Reduction Fusion Model Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script trains a fused model for both 2x upscaling and noise reduction. It specifies the model architecture, model directory, method, scale factor, and noise level, using a test image. ```lua th train.lua -model upconv_7 -model_dir models/my_model -method noise_scale -scale 2 -noise_level 1 -test images/miku_small.png ``` -------------------------------- ### Schedule Cache Purging with CRON for waifu2x Source: https://github.com/nagadomi/waifu2x/wiki/Server-guide This section explains how to add a CRON job to periodically purge the waifu2x image cache. The purge_cache.sh script removes cache files older than 4 hours. ```bash crontab -e */30 * * * * /home/ubuntu/waifu2x/appendix/purge_cache.sh ``` -------------------------------- ### Apply waifu2x for Noise Reduction Source: https://github.com/nagadomi/waifu2x/blob/master/README.md This Lua script applies waifu2x for noise reduction on images. It takes a list of input images (specified by 'data/frame.txt'), applies noise reduction with a specified level, and saves the processed images to a new directory. ```lua mkdir new_frames th waifu2x.lua -m noise -noise_level 1 -resume 1 -l data/frame.txt -o new_frames/%d.png ``` -------------------------------- ### waifu2x Noise Reduction Source: https://github.com/nagadomi/waifu2x/blob/master/README.md Applies noise reduction to an input image using waifu2x. The `-noise_level` parameter controls the intensity of the reduction, with levels ranging from 0 to 3. ```Shell th waifu2x.lua -m noise -noise_level 1 -i input_image.png -o output_image.png ``` ```Shell th waifu2x.lua -m noise -noise_level 0 -i input_image.png -o output_image.png ``` ```Shell th waifu2x.lua -m noise -noise_level 2 -i input_image.png -o output_image.png ``` ```Shell th waifu2x.lua -m noise -noise_level 3 -i input_image.png -o output_image.png ```