主要关于linux下export、echo、pwd的用法。
《21个项目玩转深度学习:基于Tensorflow的时间详解》5.2.1安装TensorFlow Object Detection API的一个操作,失败了,写给碰到同样问题的人。
照着这个教程做,发现运行一个python3 shell,然后import slim也确实没问题。
但是!!!
这容易有误解和干扰项,因为你可能就是在research目录下直接运行python shell,而不是其他地方,在research目录下,本来就有slim,怎么可能导入不成功呢?什么变量都别设置,import一样成功。所以这个判断方法不准确,至少,应该换个目录去运行python shell。
然后,运行下边那个py文件还是会提示找不到nets:
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in <module>
from object_detection.builders import model_builder
File "/home/qw/Documents/Deep-Learning-21-Examples/chapter_5/research/object_detection/builders/model_builder.py", line 30, in <module>
from object_detection.models import faster_rcnn_inception_resnet_v2_feature_extractor as frcnn_inc_res
File "/home/qw/Documents/Deep-Learning-21-Examples/chapter_5/research/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py", line 28, in <module>
from nets import inception_resnet_v2
ImportError: No module named 'nets'
解决方法一:去那个要执行的文件所在目录去export,再回到research目录下执行,可过。
../Deep-Learning-21-Examples/chapter_5/research/object_detection/builders#export PYTHONPATH=$PYTHONPATH:'pwd'../../slim
问题好像出在那个'pwd'上。
解决方法二:使用绝对路径
解决方案三:
没错~!
我是说,原文没错,注意pwd两边的不是'是`,键盘左上角那个按键。
# export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
linux的反单引号是命令替换,能直接把pwd的输出放到这里,也就等于方案二的手写绝对路径。
还有$(pwd)
# export PYTHONPATH=$PYTHONPATH:$(pwd):$(pwd)/slim
总之,是一个变量替换,类似字符串中的%s。
root@ubuntu:/home/qw/Documents/Deep-Learning-21-Examples/chapter_5/research# str="hello world `date`"
root@ubuntu:/home/qw/Documents/Deep-Learning-21-Examples/chapter_5/research# echo $strhello world Thu Oct 11 20:05:30 PDT 2018