一、池化层的github中的比较官方的定义:
池化层定义
有最大值池化和均值池化
max_pooling2d(
inputs,
pool_size,
strides,
padding='valid',
data_format='channels_last',
name=None
)
pool1=tf.layers.max_pooling2d(inputs=x, pool_size=[2, 2], strides=2)
池化层一般放在卷积之后的位置上,如:
conv=tf.layers.conv2d(
inputs=x,
filters=32,
kernel_size=[5, 5],
padding="same",
activation=tf.nn.relu)
pool=tf.layers.max_pooling2d(inputs=conv, pool_size=[2, 2], strides=2)
2、tf.layers.average_pooling2d
average_pooling2d(
inputs,
pool_size,
strides,
padding='valid',
data_format='channels_last',
name=None
)
参数的具体含义跟最大值池化的含义一样,这里就不再进行过多的陈述。
二、全连接dense层定义在github中也有相应的定义:
全连接层的定义
dense(
inputs,
units,
activation=None,
use_bias=True,
kernel_initializer=None,
bias_initializer=tf.zeros_initializer(),
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
trainable=True,
name=None,
reuse=None
)
#全连接层
dense1 = tf.layers.dense(inputs=pool3, units=1024, activation=tf.nn.relu)
dense2= tf.layers.dense(inputs=dense1, units=512, activation=tf.nn.relu)
logits= tf.layers.dense(inputs=dense2, units=10, activation=None)
最后可以对全连接层进行正则化约束:
dense1 = tf.layers.dense(inputs=pool3, units=1024, activation=tf.nn.relu,kernel_regularizer=tf.contrib.layers.l2_regularizer(0.003))