Tensorflow Slim用法
TF-Slim 是Tensorflow为了定义、训练和评估复杂模型的一个轻量级工具
用户通过样板代码使模型的定义更加紧凑,提高了可读性和可维护性,通过复制粘贴超参数值降低了人工输入出错的可能性,并简化了超参数调优。
TF-Slim的导入
import tensorflow.contrib.slim as slim
Tensorflow Slim中slim.arg_scope的用法
arg_scope(list_ops_or_scope,kwargs)
list_ops_or_scope: 操作列表或操作域
kwargs: 设置的参数,以keyword=value方式显示
未用slim简化前:
net = slim.conv2d(inputs, 64, [11, 11], 4, padding='SAME', weights_initializer=tf.truncated_normal_initializer(stddev=0.01), weights_regularizer=slim.l2_regularizer(0.0005), scope='conv1')
net = slim.conv2d(net, 128, [11, 11], padding='VALID', weights_initializer=tf.truncated_normal_initializer(stddev=0.01), weights_regularizer=slim.l2_regularizer(0.0005), scope='conv2')
net = slim.conv2d(net, 256, [11, 11], padding='SAME', weights_initializer=tf.truncated_normal_initializer(stddev=0.01), weights_regularizer=slim.l2_regularizer(0.0005), scope='conv3')
slim简化后:
with slim.arg_scope([slim.conv2d], padding='SAME', weights_initializer=tf.truncated_normal_initializer(stddev=0.01) weights_regularizer=slim.l2_regularizer(0.0005)):
//参数模板
net = slim.conv2d(inputs, 64, [11, 11], scope='conv1')
net = slim.conv2d(net, 128, [11, 11], padding='VALID', scope='conv2')
net = slim.conv2d(net, 256, [11, 11], scope='conv3')