数据
按行读取图像名称
input_queue = tf.train.string_input_producer([filenames_file], shuffle=False)
line_reader = tf.TextLineReader()
_, line = line_reader.read(input_queue)
split_line = tf.string_split([line]).values
图像路径名称拼接
left_image_path = tf.string_join([self.data_path, split_line[0]])
执行某些函数
# 在func函数中,可以对转化成numpy array的tensor进行np.运算
tf.py_func(len, [t], [tf.int64])
tf.image
图像数据类型变换
image = tf.image.convert_image_dtype(image, tf.float32)
图像resize
image = tf.image.resize_images(image, [self.params.height, self.params.width], tf.image.ResizeMethod.AREA)
tf.image.resize_nearest_neighbor(x, [h * ratio, w * ratio])
模型
优化
按区间变化的学习率
# 当前训练次数
global_step = tf.Variable(0, trainable=False)
# 划分区间的界值
boundaries = [np.int32((3/5) * num_total_steps), np.int32((4/5) * num_total_steps)]
# 区间内具体的学习率 值
values = [args.learning_rate, args.learning_rate / 2, args.learning_rate / 4]
# 按区间划分的学习率
learning_rate = tf.train.piecewise_constant(global_step, boundaries, values)
优化器
opt_step = tf.train.AdamOptimizer(learning_rate)