Skip to content

Instantly share code, notes, and snippets.

-- 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.
@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()

Multiscale Resolution Scripts

Setup

First download the linear-color-transfer.py, and lum-transfer.py scripts from Neural-Tools:

wget -c https://raw.githubusercontent.com/ProGamerGov/Neural-Tools/master/linear-color-transfer.py

wget -c https://raw.githubusercontent.com/ProGamerGov/Neural-Tools/master/lum-transfer.py
# Inspired by: https://github.com/torch/nn/blob/master/GPU.lua
# And: https://github.com/jcjohnson/neural-style/blob/master/neural_style.lua#L360
# As seen in: https://github.com/ProGamerGov/neural-style-pt
import torch
import torch.nn as nn
class ModelParallel(nn.Module):
r"""Splits a sequential network across multiple devices.
import torch
import torch.nn as nn
class VGG(nn.Module):
def __init__(self, features, num_classes=1000):
super(VGG, self).__init__()
self.features = features
self.classifier = nn.Sequential(
nn.Linear(512 * 7 * 7, 4096),
import os
import copy
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision.transforms as transforms
from PIL import Image
from CaffeLoader import loadCaffemodel, ModelParallel
import os
import copy
import time
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision.transforms as transforms
from PIL import Image
from CaffeLoader import loadCaffemodel, ModelParallel
import os
import copy
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision.transforms as transforms
from PIL import Image
from CaffeLoader import loadCaffemodel, ModelParallel
@ProGamerGov
ProGamerGov / notebook.ipynb
Last active November 16, 2019 02:06
neural-style-pt
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ProGamerGov
ProGamerGov / convert_model.py
Last active November 17, 2019 18:18
Make a model's weight and bias names be compatible with neural-style-pt
import torch
from collections import OrderedDict
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-model_file", type=str, default='')
parser.add_argument("-output_name", type=str, default='')
params = parser.parse_args()