Skip to content

Instantly share code, notes, and snippets.

-- this program takes in an image
-- and finds nc channels on a given layer
-- having the strongest activations
require 'torch'
require 'nn'
require 'image'
require 'loadcaffe'
function preprocess(img)
# git clone from https://github.com/tkarras/progressive_growing_of_gans
# download the snapshot from their Google drive
# use the following code in the same directory to generate random faces
import os
import sys
import time
import glob
import shutil
import operator
import theano
@htoyryla
htoyryla / neural-mean2.lua
Last active October 27, 2017 09:13
Neural-style with additional loss through spatial mean of feature maps
-- neural-style modified by @htoyryla 27 Oct 2017
-- to use both gram matrix (as a statistical evaluation) and a mean of n featuremaps (to retain spatial sturcture of the style image)
-- to evaluate style
-- StyleLoss and GramMatrix have been copied from fast-neural-style
-- but modified to calculate a spatial mean of the feature maps
-- new param mean_weight to control the amount of mean for style
-- loss_type to select between L2 and SmoothL1 (as in fast-neural-style)
-- **** style_scale no longer works, the mean calculation requires that style image is resized as the content image ****
@htoyryla
htoyryla / neural_grad.lua
Created October 24, 2017 09:41
neural-style modified not to decrease style gradients when image size is increased
-- this is a modified version of neural_style.lua originally by @jcjohnson
-- @htoyryla 24 Oct 2017
--
-- original neural-style includes scaling of gram matrix output and gradient in the StyleLoss
-- using division by the number of elements in input
-- this is done to make the style representations from different layers (of different size) better comparable
-- but it also has the effect of decreasing gradients as the image size is increased
--
-- this version attempts to keep the gradients from style loss modules in the same range
-- (i.e. that what is obtained at image size 512px)
@htoyryla
htoyryla / neural-channels.lua
Last active May 18, 2017 22:16
Neural-style with selected channels emphasis
-- modified version of @jcjohnson's neural-style
-- by @htoyryla 14 May 2017
-- allows exploring th effect of giving emphasis to specific channel(s) in a style layer
-- use -style_layers to select layer as usual, using a single layer is recommended
-- -style_channels to specify one or more channels to be given emphasis, other channels will be attenuated
-- if a channel does not exist in a layer, it is ignored and given a warning
-- note: if multiple style layers are used, style_channels setting affects both
require 'torch'
require 'nn'
@htoyryla
htoyryla / nsrg-replace.lua
Created May 13, 2017 10:39
Varying style neural-style transfer by modifying gram matrix (v2 fantasy)
-- neural-style by jcjohnson modified by @htoyryla
-- 13 May 2017
-- generate style variants by modifying style target Gram matrix with randomized eigenvalues
-- see function randomizeEigenvalues() for details
require 'torch'
require 'nn'
require 'image'
require 'optim'
@htoyryla
htoyryla / nsrg.lua
Created May 13, 2017 10:35
Varying style neural-style transfer by modifying gram matrix (v1)
-- neural-style by jcjohnson modified by @htoyryla
-- 13 May 2017
-- generate style variants by modifying style target Gram matrix with randomized eigenvalues
-- see function randomizeEigenvalues() for details
-- this version produces slight variants of a given style
-- by multiplying gram matrix eigenvalues by random multiplies 0.1 to 1.9
require 'torch'
require 'nn'
@htoyryla
htoyryla / neural_mirage5.lua
Last active September 2, 2018 14:26
Neural-style modified to use also fc layers
--[[
Neural-mirage 5
by @htoyryla 3/2016, 3/2017
based on neural-style by @jcjohnson
for more info see
http://liipetti.net/erratic/2016/03/31/i-have-seen-a-neural-mirage/
http://liipetti.net/erratic/2016/04/20/getting-the-space-back/
@htoyryla
htoyryla / train2.lua
Last active February 5, 2017 02:51
Fast-neural-style train with Torch display
--
-- a quickly modified version of jcjohnson/fast-neural-style/train.lua
-- using torch.display to monitor training using a test image run through the model every 50 iterations
--
-- hannu toyryla @htoyryla 20 Nov 2016
--
-- use -test_image parameter to give test image
-- see https://github.com/szym/display for more information on torch display
--
--
@htoyryla
htoyryla / original_colors.lua
Last active June 18, 2018 19:25
Use original colors in an image generated by fast-neural-style
-- this program takes an original image, such as a photo,
-- and a generated image, such as generated by jcjohnson/fast-neural-style
-- and copies the original colors to the generated image
-- like when using the original_colors param in jcjohnson/neural-style
--
-- by hannu töyrylä @htoyryla 30 oct 2016
--
require 'torch'
require 'image'