https://github.com/mingtaoguo/conditional-instance-norm-for-n-style-transfer
Implementation of the paper A Learned Representation for Artistic Style (Conditional instance normalization)
https://github.com/mingtaoguo/conditional-instance-norm-for-n-style-transfer
conditional-instance-normalization styletransfer tensorflow
Last synced: about 1 year ago
JSON representation
Implementation of the paper A Learned Representation for Artistic Style (Conditional instance normalization)
- Host: GitHub
- URL: https://github.com/mingtaoguo/conditional-instance-norm-for-n-style-transfer
- Owner: MingtaoGuo
- License: mit
- Created: 2018-11-02T06:00:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-19T13:16:54.000Z (over 7 years ago)
- Last Synced: 2025-04-05T13:11:18.803Z (about 1 year ago)
- Topics: conditional-instance-normalization, styletransfer, tensorflow
- Language: Python
- Homepage:
- Size: 24.6 MB
- Stars: 40
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Conditional-Instance-Norm-for-n-Style-Transfer
Implementation of the paper A Learned Representation for Artistic Style
## Introduction
Simply implementing the paper [A Learned Representation for Artistic Style](https://arxiv.org/pdf/1610.07629.pdf) (Conditional instance normalization)

``` python
def conditional_instance_norm(x, scope_bn, y1=None, y2=None, alpha=1):
mean, var = tf.nn.moments(x, axes=[1, 2], keep_dims=True)
if y1==None:
beta = tf.get_variable(name=scope_bn + 'beta', shape=[x.shape[-1]], initializer=tf.constant_initializer([0.]), trainable=True)
gamma = tf.get_variable(name=scope_bn + 'gamma', shape=[x.shape[-1]], initializer=tf.constant_initializer([1.]), trainable=True)
else:
beta = tf.get_variable(name=scope_bn+'beta', shape=[y1.shape[-1], x.shape[-1]], initializer=tf.constant_initializer([0.]), trainable=True) # label_nums x C
gamma = tf.get_variable(name=scope_bn+'gamma', shape=[y1.shape[-1], x.shape[-1]], initializer=tf.constant_initializer([1.]), trainable=True) # label_nums x C
beta1 = tf.matmul(y1, beta)
gamma1 = tf.matmul(y1, gamma)
beta2 = tf.matmul(y2, beta)
gamma2 = tf.matmul(y2, gamma)
beta = alpha * beta1 + (1. - alpha) * beta2
gamma = alpha * gamma1 + (1. - alpha) * gamma2
x = tf.nn.batch_normalization(x, mean, var, beta, gamma, 1e-10)
return x
```
## How to use
1. Download the dataset [MSCOCO](http://images.cocodataset.org/zips/train2014.zip), and unzip the dataset to the folder 'MSCOCO'
```
├── imgs
├── results
├── save_imgs
├── save_para
├── style_imgs
├── vgg_para
├── MSCOCO
├── COCO_train2014_000000000009.jpg
├── COCO_train2014_000000000025.jpg
├── COCO_train2014_000000000030.jpg
├── COCO_train2014_000000000034.jpg
├── COCO_train2014_000000000036.jpg
├── COCO_train2014_000000000049.jpg
...
```
2. Download the vgg16.npy, and put it into the folder 'vgg_para'
3. Execute the python file 'main.py'
## Requirement
- python3.5
- tensorflow1.4.0
- scipy
- numpy
- pillow
## Results
Style = alpha * style2 + (1 - alpha) * style1
|Content|Style1|Style2|Result|
|-|-|-|-|
|||||
|Content|Style1|Style2|Result|
|-|-|-|-|
|||||
|Content|Style1|Style2|
|-|-|-|
||||
|alpha=0|alpha=0.6|alpha=1.0|
|-|-|-|
||||
|Content|Style1|Style2|
|-|-|-|
||||
|alpha=0|alpha=0.6|alpha=1.0|
|-|-|-|
||||
|Content|Style1|Style2|
|-|-|-|
||||
|alpha=0|alpha=0.2|alpha=0.4|alpha=0.6|alpha=0.8|alpha=1.0|
|-|-|-|-|-|-|
|||||||
|Content|style|result|
|-|-|-|
||||