代码学习笔记
Unsupervised Monocular Depth Estimation with Left-Right Consistency :monodepth_dataloader.py
源码:monodepth
"""
代码学习 注释专用
song
stay hungry stay foolish
"""
from __future__ import absolute_import, division, print_function
import tensorflow as tf
def string_length_tf(t): # 测量tensor长度
return tf.py_func(len, [t], [tf.int64]) # tf.py_func 提供对tensor的操作接口
class MonodepthDataloader(object): # 定义类 MonodepthDataloader
"""monodepth dataloader"""
def __init__(self, data_path, filenames_file, params, dataset, mode):
self.data_path = data_path # 数据路径
self.params = params # 参数
self.dataset = dataset # 数据集
self.mode = mode # 模型
self.left_image_batch = None # 定义赋值变量 采用默认值
self.right_image_batch = None
input_queue = tf.train.string_input_producer([filenames_file], shuffle=False)
"""
把输入的数据进行按照要求排序成一个队列。 这里把KITTI的图片文件名 整理 成一个队列(queue)
Tip:这里的 shuffle 是布尔值的意思,默认为TRUE 。会改变input的顺序
"""
line_reader = tf.TextLineReader() # 创建一个 TextLineReader 文件
_, line = line_reader.read(input_queue) # 输出键值对
"""
一个键值对如下图所示:
key: 第几个键值对
b'kitti_train_files.txt:11987'
value: 包含的内容,即 一对双目图像的路径
b'2011_09_30/2011_09_30_drive_0033_sync/image_02/data/0000001585.jpg 2011_09_30/2011_09_30_drive_0033_sync/image_03/data/0000001585.jpg'
"""
split_line = tf.string_split([line]).values # 将两张图片的地址字符串分开
# we load only one image for test, except if we trained a stereo model
if mode == 'test' and not self.params.do_stereo: # 单张图片的测试