Skip to content

Instantly share code, notes, and snippets.

@ProGamerGov
ProGamerGov / original_colors.py
Last active July 2, 2018 19:05
A Python version of Neural-Style's color-independent style transfer function, using only PIL/Pillow.
from PIL import Image
import argparse
parser = argparse.ArgumentParser()
# Basic options
parser.add_argument("-content", help="Original content target image", default='examples/inputs/tubingen.jpg')
parser.add_argument("-generated", help="Stylized image", default='examples/outputs/tubingen_starry.png')
parser.add_argument("-output_image", default='out.png')
params = parser.parse_args()
-- This modified version of Neural-Style was created by github.com/ProGamerGov on 2017-09-29
-- Use: "luarocks install paths" to install the required package.
-- The -style_image parameter will now automatically determine if the input is a directory, or a string of one or more images.
-- The FC layers as content layers feature comes from:
-- github.com/htoyryla's gist.github.com/htoyryla/806ca4d978f0528114282cd00022ad71
-- Code from: https://github.com/jcjohnson/neural-style/pull/408
-- The NIN ImageNet model uses dropout layers with random values,
-- so this version of neural_style.lua removes the unneeded dropout layers entirely.
-- This modified version of Neural-Style was created by github.com/ProGamerGov on 2017-09-29
-- Use: "luarocks install paths" to install the required package.
-- The -style_image parameter will now automatically determine if the input is a directory, or a string of one or more images.
-- Code from: https://github.com/jcjohnson/neural-style/pull/408
-- The NIN ImageNet model uses dropout layers with random values,
-- so this version of neural_style.lua removes the unneeded dropout layers entirely.
require 'torch'
require 'nn'
-- modified by ProGamerGov to select the best content channels, in addition to style channels.
-- modified version of @jcjohnson's neural-style
-- by @htoyryla 13 Feb 2018
-- allows giving emphasis to nc best channel(s) in each style layer
-- use -style_layers to select layer as usual, using a single layer is recommended
-- -nc to set how many of the best channels are used per layer
-- during target capture, tests the model using the style image
-- and selects nc channels with strongest activations to be given emphasis during iterations
-- not tested with multiple style images
-- Modified from github.com/htoyryla's code here: https://github.com/htoyryla/convis/issues/2#issuecomment-365009705
require 'torch'
require 'nn'
require 'image'
require 'loadcaffe'
function preprocess(img)
local mean_pixel = torch.DoubleTensor({103.939, 116.779, 123.68})
local perm = torch.LongTensor{3, 2, 1}
-- This version of neural_style.lua allows for the use of all of the Adam optimizer parameters.
-- The learning rate parameter also now affect's L-BFGS' learning rate.
-- The modifications were made based on the research done here:
-- https://github.com/jcjohnson/neural-style/issues/428#issuecomment-342618091
-- github.com/ProGamerGov 2017-11-07
require 'torch'
@ProGamerGov
ProGamerGov / neural_style_dir.lua
Last active September 30, 2017 21:16
This modified neural_style.lua allows for a directory to be used as an input for the -style_image parameter.
-- This modified version of Neural-Style was created by github.com/ProGamerGov on 2017-09-29
-- Use: "luarocks install paths" to install the required package.
-- The -style_image parameter will now automatically determine if the input is a directory, or a string of one or more images.
require 'torch'
require 'nn'
require 'image'
require 'optim'
require 'paths'
@ProGamerGov
ProGamerGov / neural_style_rng_fix.lua
Last active September 24, 2017 21:50
The NIN ImageNet model uses dropout layers with random values, so this version of neural_style.lua removes the unneeded dropout layers entirely.
-- Code from: https://github.com/jcjohnson/neural-style/pull/408
-- The NIN ImageNet model uses dropout layers with random values,
-- so this version of neural_style.lua removes the unneeded dropout layers entirely.
require 'torch'
require 'nn'
require 'image'
require 'optim'
require 'loadcaffe'
@ProGamerGov
ProGamerGov / alternate.sh
Last active September 22, 2020 21:04
Scripts that create rotated and reflected version of a specified image
#! /bin/bash
#Usage: ./alternate.sh <input.png>
#Dependency: sudo apt-get install imagemagick
#Permission fix troubleshooting: chmod u+x ./alternate.sh
# 1. Defines the input image as a variable
input=$1
input_file=`basename $input`
clean_name="${input_file%.*}"
@ProGamerGov
ProGamerGov / neural_style_laplacian.lua
Last active June 11, 2017 23:38
Neural-Style with the laplacian feature from deep-photo-styletransfer. See the comments for setting up and using the new feature.
-- Matting laplacian code from: github.com/martinbenson/deep-photo-styletransfer/
-- Generate the laplacian with: https://gist.github.com/ProGamerGov/290f26afccc5e013d1a8425ef6a594f2
-- More details can be found in this gist: https://gist.github.com/ProGamerGov/d3988b914c92220ae45aa5bb1e31d6a7
-- The original Neural Style code can be found here: https://github.com/jcjohnson/neural-style
require 'torch'
require 'nn'
require 'image'
require 'optim'