Skip to content

Instantly share code, notes, and snippets.

Avatar

ProGamerGov

  • Multiverse
View GitHub Profile
@ProGamerGov
ProGamerGov / image_cppn.py
Last active May 22, 2020
tensorflow/lucid CPPN (X,Y) --> (R,G,B) Differentiable Image Parameterization in PyTorch
View image_cppn.py
# tensorflow/lucid CPPN (X,Y) --> (R,G,B) Differentiable Image Parameterization in PyTorch
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision.transforms as transforms
from inception5h import Inception5h
from PIL import Image
View README.md

neural-style-pt with tiling

Tiling

The tiling feature is based on neural-dream's tiling system.

Usage

Basic usage:

python neural_style_tile.py -style_image <image.jpg> -content_image <image.jpg> -tile_size 256 -image_size 512
@ProGamerGov
ProGamerGov / c.py
Last active Feb 28, 2020
This file is used to convert an MMdnn PyTorch model to a usable state dict model.
View c.py
import torch
import torch.nn as nn
from collections import OrderedDict
import imp
import numpy as np
# Import the model classes that were edited. Replace 'model_class_name" with the name of the class script, and
# replace 'ModelName' with the name of the class in the script
from model_class_name import ModelName
@ProGamerGov
ProGamerGov / neural_style_hooks.py
Last active Feb 16, 2020
Use the '-use_hooks' parameter to use forward hooks instead of layers to compute content and style loss.
View neural_style_hooks.py
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
View README.md

neural-style-pt with mean loss and histogram transfer

Histogram Transfer

Users can specify an image for which the histogram will be transfered from, and what images the histogram will be transfered to; either the content image, style image(s), or both.

Mean Loss

A new loss layer type has been added that uses image means. Currently it only uses the first style image specified.

View README_HLOSS.md
View neural_style_test_loss.py
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
View download_gdrive_models.sh
#!/bin/bash
fileid="1qWjJd-mVNxvHhzc9XsU6LjC0pQXIwW4t"
filename="models/VGG16-Stylized-ImageNet.pth"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}
fileid="1EU-F9ugeIeTO9ay4PinzsBXgEuCYBu0Z"
filename="models/VGG16_SOD_finetune.pth"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}
@ProGamerGov
ProGamerGov / convert_model.py
Last active Nov 17, 2019
Make a model's weight and bias names be compatible with neural-style-pt
View convert_model.py
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()
@ProGamerGov
ProGamerGov / notebook.ipynb
Last active Nov 16, 2019
neural-style-pt
View notebook.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.