VGG16实战图像风格转换V1

具体原理可以参考: https://blog.csdn.net/qq_37982109/article/details/105193638

1·读取VGG16的参数类

import os
import math
import numpy as np
import tensorflow as tf
from PIL import Image
import time

VGG_MEAN = [103.939, 116.779, 123.68]


class VGGNet:
    """Builds VGG-16 net structure,
       load parameters from pre-train models.
    """

    def __init__(self, data_dict):
        self.data_dict = data_dict

    # 处理卷积层
    def get_conv_filter(self, name):
        return tf.constant(self.data_dict[name][0], name='conv')
    # 获取权重
    def get_fc_weight(self, name):
        return tf.constant(self.data_dict[name][0], name='fc')
    # 获取偏置
    def get_bias(self, name):
        return tf.constant(self.data_dict[name][1], name='bias')
    # 创建卷积层
    def conv_layer(self, x, name):
        """Builds convolution layer."""
        with tf.name_scope(name):
            conv_w = self.get_conv_filter(name)
            conv_b = self.get_bias(name)
            h = tf.nn.conv2d(x, conv_w, [1, 1, 1, 1], padding='SAME')
            h = tf.nn.bias_add(h, conv_b)
            h = tf.nn.relu(h)
            return h
    # pooling层
    def pooling_layer(self, x, name):
        """Builds pooling layer."""
        return tf.nn.max_pool(x,
                              ksize=[1, 2, 2, 1],
                              strides=[1, 2, 2, 1],
                              padding='SAME',
                              name=name)
    # 全连接层
    def fc_layer(self, x, name, activation=tf.nn.relu):
        """Builds fully-connected layer."""
        with tf.name_scope(
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值