资源简介
这是基于VGG19网络的一个图像风格转换,需要下载VGG19的权重文件,拷入到工程目录下即可,代码直接运行就能跑。
代码片段和文件信息
import tensorflow as tf
import numpy as np
import os
import cv2
IMAGE_W = 600
IMAGE_H = 600
Ratio = None
INI_NOISE_RATIO = 0.7
style_STRENGTH = 500
ITERATION = 2000
CONTENT_layerS = [(‘conv4_2‘ 1.)]
style_layerS = [(‘conv1_1‘ 2.) (‘conv2_1‘ 1.) (‘conv3_1‘ 0.5) (‘conv4_1‘ 0.25) (‘conv5_1‘ 0.125)]
layers = [‘conv1_1‘ ‘conv1_2‘ ‘conv2_1‘ ‘conv2_2‘ ‘conv3_1‘ ‘conv3_2‘ ‘conv3_3‘ ‘conv3_4‘
‘conv4_1‘ ‘conv4_2‘ ‘conv4_3‘ ‘conv4_4‘ ‘conv5_1‘ ‘conv5_2‘ ‘conv5_3‘ ‘conv5_4‘ ]
def vgg19(input model_path=None):
‘‘‘
Build the VGG19 network which is initialized with the pre-trained VGG19 model.
:param input: The input image.
:param model_path:Which path the VGG19 model is stored.
:return:A python dict which contains all the layers needed.
‘‘‘
if model_path is None:
model_path = ‘vgg19.npy‘
if os.path.isfile(model_path) is False:
raise FileNotFoundError(‘vgg19.npy cannot be found!!!‘)
wDict = np.load(model_path encoding=“bytes“).item()
net = {}
net[‘input‘] = input
# conv1_1
weight1_1 = tf.Variable(initial_value=wDict[‘conv1_1‘][0] trainable=False)
bias1_1 = tf.Variable(wDict[‘conv1_1‘][1] trainable=False)
net[‘conv1_1‘] = tf.nn.relu(tf.nn.conv2d(net[‘input‘] weight1_1 [1 1 1 1] ‘SAME‘) + bias1_1)
# conv1_2
weight1_2 = tf.Variable(wDict[‘conv1_2‘][0] trainable=False)
bias1_2 = tf.Variable(wDict[‘conv1_2‘][1] trainable=False)
net[‘conv1_2‘] = tf.nn.relu(tf.nn.conv2d(net[‘conv1_1‘] weight1_2 [1 1 1 1] ‘SAME‘) + bias1_2)
# pool1
net[‘pool1‘] = tf.nn.avg_pool(net[‘conv1_2‘] [1 2 2 1] [1 2 2 1] ‘SAME‘)
# conv2_1
weight2_1 = tf.Variable(wDict[‘conv2_1‘][0] trainable=False)
bias2_1 = tf.Variable(wDict[‘conv2_2‘][1] trainable=False)
net[‘conv2_1‘] = tf.nn.relu(tf.nn.conv2d(net[‘pool1‘] weight2_1 [1 1 1 1] ‘SAME‘) + bias2_1)
# conv2_2
weight2_2 = tf.Variable(wDict[‘conv2_2‘][0] trainable=False)
bias2_2 = tf.Variable(wDict[‘conv2_2‘][1] trainable=False)
net[‘conv2_2‘] = tf.nn.relu(tf.nn.conv2d(net[‘conv2_1‘] weight2_2 [1 1 1 1] ‘SAME‘) + bias2_2)
# pool2
net[‘pool2‘] = tf.nn.avg_pool(net[‘conv2_2‘] [1 2 2 1] [1 2 2 1] ‘SAME‘)
# conv3_1
weight3_1 = tf.Variable(wDict[‘conv3_1‘][0] trainable=False)
bias3_1 = tf.Variable(wDict[‘conv3_1‘][1] trainable=False)
net[‘conv3_1‘] = tf.nn.relu(tf.nn.conv2d(net[‘pool2‘] weight3_1 [1 1 1 1] ‘SAME‘) + bias3_1)
# conv3_2
weight3_2 = tf.Variable(wDict[‘conv3_2‘][0] trainable=False)
bias3_2 = tf.Variable(wDict[‘conv3_2‘][1] trainable=False)
net[‘conv3_2‘] = tf.nn.relu(tf.nn.conv2d(net[‘conv3_1‘] weight3_2 [1 1 1 1] ‘SAME‘) + bias3_2)
# conv3_3
weight3_3 = tf.Variable(wDict[‘conv3_3‘][0] trainable=False)
bias3_3 = tf.Variable(wDict[‘conv3_3‘][1] trainable=False)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 153 2018-06-03 19:33 Transfer\.idea\codest
文件 198 2018-06-03 19:33 Transfer\.idea\codest
文件 84 2018-06-03 19:33 Transfer\.idea\dictionaries\Yel.xm
文件 185 2018-06-03 19:33 Transfer\.idea\misc.xm
文件 268 2018-06-03 19:33 Transfer\.idea\modules.xm
文件 455 2018-06-03 19:33 Transfer\.idea\Transfer.iml
文件 13130 2018-06-13 20:59 Transfer\.idea\workspace.xm
文件 120217 2018-03-29 16:17 Transfer\content.jpg
文件 202404 2018-03-29 16:17 Transfer\st
文件 10707 2018-06-03 19:40 Transfer\st
目录 0 2018-06-03 19:33 Transfer\.idea\codest
目录 0 2018-06-03 19:33 Transfer\.idea\dictionaries
目录 0 2018-06-13 20:59 Transfer\.idea
目录 0 2018-06-03 15:07 Transfer\model
目录 0 2018-06-13 20:56 Transfer
----------- --------- ---------- ----- ----
347801 15
- 上一篇:计算机组网技术入门
- 下一篇:AT89C51数字时钟
相关资源
- 第三方控减
- On the Darboux Transformation of the (2+1)
- Martensitic transformation and magnetocaloric
- Research on carbon emissions of Industry in tr
- Effect of isovalent substitution on martensiti
- Co-doping effect on the martensitic transforma
- Facile hydrothermal synthesis of Tb2(MoO4)
-
易语言GDI自绘电梯st
yle源码 - 行业数字化转型方法论白皮书2019.pd
- Microstructure transformation behavior and mec
- Anti-CD3 antibody treatment ameliorates transf
- css3 animation transform鱼游动动画特效
- WaveletTutorial原文及其翻译
- Nano/Microscale Heat Transfer
-
svn代码检查工具(svnchecker+checkst
y - Qt界面外观
- H-Transforms Theory and Applications
- 万能数据转换工具stat/transfer12
-
Checkst
ylenet.sf.eclipsecs-updatesite_5.6.1 - 麻省理工传热学教材:A Heat Transfer.
- Wavelet methods in statistics with R
- color transfer 颜色转化
- Visual Attribute Transfer through Deep Image A
- StatTransfer_Twelve_12
- Fast Fourier Transform and Its Applications
- SSH Secure File Transfer Client
-
Source Insight 4.0 仿SolarizedDark主题xm
- LIFT: Learned Invariant Feature Transform
- Runtime Transform Gizmos
- StatTransfer7.0.2
评论
共有 条评论