1、简介

文章:2017_CVPR_Unsupervised Learning of Depth and Ego-Motion from Video

代码下载:SfMLearner

2、代码运行记录

基本可以依据作者readme.md文件所述步骤执行;以下是本人在运行过程中遇到的一些问题;

系统配置:Python3+TensorFlow1.9.0+cuda 9.0

(1)demo 运行

1.1 demo下载

在/SfMLearner/models/目录下执行:

bash ./models/download_depth_model.sh
bash ./models/download_pose_model.sh

下载作者训练好的模型参数。如果采用终端bash下载失败,可点击文件,通过文件中的网址进行下载:

http://people.eecs.berkeley.edu/~tinghuiz/projects/SfMLearner/models/kitti_depth_model.tar

http://people.eecs.berkeley.edu/~tinghuiz/projects/SfMLearner/models/kitti_pose_model.tar

下载后得到两个压缩包并提取到当前文件夹,每个压缩包中可以得到三个文件,即训练的网络模型

1.2 运行

可利用ipython-notebook打开/sfmlearner/目录下的demo.iptnb

配置tensorflow环境,逐块运行,如果报错,一般是由于一些依赖库未安装,pip install 相应的依赖库之后继续逐块运行

如果在第一块遇到如下错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

只需将

fh = open('misc/000800.png', 'r')     ===      fh = open('misc/000000.png', 'rb')

本人在运行时最后出现图像加载显示部分的错误,是因为作者在源码中少关联了一个库matplotlib.pyplot,更改后的完整代码如下:

from __future__ import division
import os
import numpy as np
import PIL.Image as pil
import tensorflow as tf
from SfMLearner import SfMLearner
from utils import normalize_depth_for_display

import matplotlib.pyplot as plt

img_height=128
img_width=416
ckpt_file = 'models/model-190532'#所下载作者训练好的模型参数地址及名称
fh = open('misc/000000.png', 'rb')
I = pil.open(fh)
I = I.resize((img_width, img_height), pil.ANTIALIAS)
I = np.array(I)


sfm = SfMLearner()
sfm.setup_inference(img_height,
                    img_width,
                    mode='depth')

saver = tf.train.Saver([var for var in tf.model_variables()]) 
with tf.Session() as sess:
    saver.restore(sess, ckpt_file)
    pred = sfm.inference(I[None,:,:,:], sess, mode='depth')

plt.figure(figsize=(15,15))
plt.subplot(1,2,1); plt.imshow(I)
plt.imsave("depth000000.png",normalize_depth_for_display(pred['depth'][0,:,:,0]))
plt.subplot(1,2,2); plt.imshow(normalize_depth_for_display(pred['depth'][0,:,:,0]))

如果对ipython-notebook不熟悉,可以直接将上述code复制,建立demo.py文件,并执行Python demo.py即可运行,运行结果会保存在当前目录下

(2)KITTI Testing code

由于电脑本身算力以及个人需求,我没有对整个网络进行测试,而仅仅是利用作者训练好的模型对kitti数据集的color image中的09序列进行了 测试

作者github上所给的指令:

python test_kitti_pose.py --test_seq 9 --dataset_dir /path/to/KITTI/odometry/set/ --output_dir /path/to/output/directory/ --ckpt_file models/model-100280

对应个人设置输入指令:

python3 test_kitti_pose.py --test_seq 9 --dataset_dir /home/dataset/ --output_dir /home/SfMLearner/output/ --ckpt_file /home/SfMLearner/models/model-100280

本人SfMLearning 放在/home/文件夹下 kitti 数据集存放位置为 /home/dataset/sequences/09  神经网络输出结果至/home/SfMLearner/output/  output文件夹下,最后一个路径为前文所下载作者训练好的模型参数位置,网络输出结果为output文件夹下.txt文件,每个文件中包含五帧图像位姿估计,5*8数组:时间戳timestamp ,位置:x,y,z,方向四元数:qx,qy,qz,qw 

 

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐