资源简介
图像风格迁移原始论文完整实现代码,可以实现内容图片和风格图片的转化,https://blog.csdn.net/kevinoop/article/details/79827782 这个博客有代码详细介绍。
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Sun Jan 21 11:14:40 2018
@author: ASUS
“““
import os
import sys
import scipy.io
import scipy.misc
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
from PIL import Image
from nst_utils import *
import numpy as np
import tensorflow as tf
#matplotlib inline
def compute_content_cost(a_C a_G):
“““
Computes the content cost
Arguments:
a_C -- tensor of dimension (1 n_H n_W n_C) hidden layer activations representing content of the image C
a_G -- tensor of dimension (1 n_H n_W n_C) hidden layer activations representing content of the image G
Returns:
J_content -- scalar that you compute using equation 1 above.
“““
# Retrieve dimensions from a_G (≈1 line)
m n_H n_W n_C = a_G.get_shape().as_list()
# Reshape a_C and a_G (≈2 lines)
a_C_unrolled = tf.reshape(tf.transpose(a_C perm=[3 2 1 0]) [n_C n_H*n_W -1])
a_G_unrolled = tf.reshape(tf.transpose(a_G perm=[3 2 1 0]) [n_C n_H*n_W -1])
# compute the cost with tensorflow (≈1 line)
J_content = tf.reduce_sum(tf.square(tf.subtract(a_C_unrolled a_G_unrolled))) / (4 * n_H * n_W * n_C)
return J_content
def gram_matrix(A):
“““
Argument:
A -- matrix of shape (n_C n_H*n_W)
Returns:
GA -- Gram matrix of A of shape (n_C n_C)
“““
GA = tf.matmul(Atf.transpose(A))
return GA
def compute_layer_style_cost(a_S a_G):
“““
Arguments:
a_S -- tensor of dimension (1 n_H n_W n_C) hidden layer activations representing style of the image S
a_G -- tensor of dimension (1 n_H n_W n_C) hidden layer activations representing style of the image G
Returns:
J_style_layer -- tensor representing a scalar value style cost defined above by equation (2)
“““
# Retrieve dimensions from a_G (≈1 line)
m n_H n_W n_C = a_G.get_shape().as_list()
# Reshape the images to have them of shape (n_C n_H*n_W) (≈2 lines)
a_S = tf.reshape(tf.transpose(a_S perm=[3 1 2 0]) [n_C n_W*n_H])
a_G = tf.reshape(tf.transpose(a_G perm=[3 1 2 0]) [n_C n_W*n_H])
# Computing gram_matrices for both images S and G (≈2 lines)
GS = gram_matrix(a_S)
GG = gram_matrix(a_G)
# Computing the loss (≈1 line)
J_style_layer = tf.reduce_sum(tf.square(tf.subtract(GS GG))) / (4 * n_C**2 * (n_W * n_H)**2)
return J_style_layer
style_layerS = [
(‘conv1_1‘ 0.2)
(‘conv2_1‘ 0.2)
(‘conv3_1‘ 0.2)
(‘conv4_1‘ 0.2)
(‘conv5_1‘ 0.2)]
def compute_style_cost(model style_layerS):
“““
Computes the overall style cost from several chosen layers
Arguments:
model -- our tensorflow model
style_layerS -- A python list containing:
- the names of the layers we would like to extract style from
- a coefficient for eac
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 68 2018-05-12 10:40 pretrained-model\预训练数据下载网址.txt
文件 7669 2018-01-21 11:33 NST(Gaty).py
目录 0 2018-01-21 11:25 images\
文件 720646 2017-11-26 03:30 images\NST_GM.png
文件 868690 2017-11-26 03:30 images\NST_LOSS.png
文件 533504 2017-12-28 23:38 images\Thumbs.db
文件 76975 2017-11-26 03:30 images\camp-nou.jpg
文件 33239 2017-11-26 03:30 images\cat.jpg
文件 930639 2017-11-26 03:30 images\circle_abstract.png
文件 29674 2017-11-26 03:30 images\claude-monet.jpg
文件 90349 2017-11-26 03:30 images\content.jpeg
文件 21296 2017-11-26 03:30 images\content300.jpg
文件 232594 2017-11-26 03:30 images\content_plus_st
文件 74758 2017-11-26 03:30 images\drop-of-water.jpg
文件 320270 2017-11-26 03:30 images\gram.png
文件 368783 2017-11-26 03:30 images\hidden_la
文件 168901 2017-11-26 03:30 images\louvre.jpg
文件 897986 2017-11-26 03:30 images\louvre_generated.png
文件 50296 2017-11-26 03:30 images\louvre_small.jpg
文件 48146 2017-11-26 03:30 images\monet.jpg
文件 172643 2017-11-26 03:30 images\monet_800600.jpg
文件 858141 2017-11-26 03:30 images\pasargad_kashi.png
文件 238928 2017-11-26 03:30 images\persian_cat.jpg
文件 30492 2017-11-26 03:30 images\persian_cat_content.jpg
文件 820820 2017-11-26 03:30 images\perspolis_vangogh.png
文件 329708 2017-11-26 03:30 images\reshape_loss.png
文件 893421 2017-11-26 03:30 images\result.png
文件 66303 2017-11-26 03:30 images\sandstone.jpg
文件 53165 2017-11-26 03:30 images\stone_st
文件 29674 2017-11-26 03:30 images\st
文件 6716 2017-12-20 23:45 nst_utils.py
............此处省略4个文件信息
- 上一篇:RSA前台公钥加密后台私钥解密
- 下一篇:佳能打印机G3800主板编程器固件
评论
共有 条评论