Skip to content

Instantly share code, notes, and snippets.

View crcrpar's full-sized avatar

Masaki Kozuki crcrpar

  • NVIDIA
  • Tokyo
  • 20:51 (UTC +09:00)
View GitHub Profile
@crcrpar
crcrpar / vgg16layers_no_top.py
Last active August 31, 2017 09:08
a wrapper of chainer VGG16Layers w/o fully connected layers.
from __future__ import print_function
import collections
import os
import numpy as np
import chainer
import chainer.functions as F
import chainer.links as L
@crcrpar
crcrpar / vgg.py
Created September 14, 2017 02:23
[PyTorch] pre-trained VGG16 for perceptual loss. e.g. Style Transfer
"""Modified VGG16 to compute perceptual loss.
This class is mostly copied from pytorch/examples.
See, fast_neural_style in https://github.com/pytorch/examples.
"""
import torch
from torchvision import models
class VGG_OUTPUT(object):
@crcrpar
crcrpar / vgg_19_get_hidden_feature_pytorch.py
Created October 6, 2017 11:11
wrapper for pretrained vgg19 in pytorch. you can get any hidden feature.
import torch
import torch.nn as nn
from torchvision.models import vgg19
"""
sequential (
# block_1
(0): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(1): ReLU (inplace)
@crcrpar
crcrpar / vgg19_chainer.py
Last active July 30, 2018 06:50
loader for pretrained, official VGG19
from __future__ import print_function
import collections
import os
import numpy
try:
from PIL import Image
available = True
except ImportError as e:
available = False
@crcrpar
crcrpar / instance_normalization.py
Last active September 11, 2019 05:25
Instance Normalization in Chainer on top of Batch Normalization
import numpy
import chainer
from chainer import configuration
from chainer import cuda
from chainer import functions
from chainer import initializers
from chainer import link
from chainer.utils import argument
from chainer import variable
@crcrpar
crcrpar / mnist_pytorch2caffe2.py
Last active January 28, 2018 14:39
an example: pytorch to caffe2
from __future__ import print_function
import argparse
from datetime import datetime as dt
import numpy as np
import onnx_caffe2.backend
import torch
import torch.nn as nn
@crcrpar
crcrpar / Dockerfile
Created January 28, 2018 14:50
dockerfile to try pytorch to caffe2
FROM caffe2ai/caffe2:c2v0.8.1.cpu.min.ubuntu16.04
LABEL maintainer="aaronmarkham@fb.com"
# caffe2 install with cpu support
RUN apt-get update && apt-get install -y --no-install-recommends \
libgflags-dev \
libgtest-dev \
libiomp-dev \
libleveldb-dev \
@crcrpar
crcrpar / Dockerfile
Created April 17, 2018 13:24
Dockerfile for fastai
FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
curl \
vim \
ca-certificates \
libjpeg-dev \
import chainer
from chainer.backends import cuda
import chainer.link_hooks
from chainer.link_hooks import _ForwardPreprocessCallbackArgs
from chainer import variable
def _get_axis(ndim, axis):
axes = [axis]
for i in range(ndim):
import torch.nn as nn
from torch.nn.utils import spectral_norm
if __name__ == '__main__':
layer = nn.Conv2d(3, 15, 3, 1, 1)
layer = spectral_norm(layer)
torch.save(layer.state_dict(), 'tmp.pth')