from datetime import datetime
import math
import time
import tensorflow as tf
首先构建conv_op函数,用于创建卷积层并把本层的参数存入参数列表;
def conv_op(input_op, name, kh,kw, n_out, dh, dw, p):
n_in = input_op.get_shape()[-1].value
with tf.name_scope(name) as scope:
kernel = tf.get_variable(scope+"w",shape=[kh, kw, n_in, n_out], dtype = tf.float32, initializer = tf.contrib.layers.xavier_initializer_conv2d())
input_op是输入的tensor,
name是这一层的名称,
kh是kernel height即为卷积核的高,
kw是卷积核的宽,
n_out是卷积核数量即为输出通道,
dh是步长的高,
dw是步长的宽,
p是参数列表。
通过get_shape()[-1].value获取输入的tensor的通道数;
通过tf.name_scope(name)设置scope;
通过get_variable创建卷积核参数。
shape为[kh,kw,n_in,n_out]即为卷积核的高,卷积核的宽,输入通道数,输出通道数;
使用tf.contrib.layers.xavier_initializer_conv2d()进行参数初始化。
conv = tf.nn.conv2d(input_op, kernel, (1, dh, dw, 1),padding='SAME')
bias_init_val = tf.constant(0.0, shape=[n_out], dtype=tf.float32)
biases = tf.Variable(bias_init_val, trainable=True, name='b')
z = tf.nn.bias_add(conv, biases)
activation = tf.nn.relu(z,name=scope)
p+=[kernel,biases]
return activation
通过tf.nn.conv2d对input

本文详细介绍了VGGNet-16的构建过程,包括卷积层、全连接层和最大池化层的创建。通过conv_op函数创建卷积层,fc_op函数构建全连接层,mpool_op函数实现最大池化。VGGNet-16分为5段卷积网络,每段包含多个卷积层和最大池化层,逐步减小图像尺寸,增加输出通道数。网络结构依次为64->128->256->512通道,最终输出为7*7*512的特征图。
最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



