我一直在尝试设置对象检测环境。
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
但是我坚持这条线;
python object_detection/builders/model_builder_test.py
它吐出这个错误;
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in <module>
from object_detection.builders import model_builder
ImportError: No module named object_detection.builders
我的系统是;
MacOS Sierra
pip freeze&gt; requirements.txt
altgraph==0.10.2
appnope==0.1.0
backports-abc==0.5
backports.shutil-get-terminal-size==1.0.0
backports.weakref==1.0rc1
bdist-mpkg==0.5.0
bleach==1.5.0
bonjour-py==0.3
certifi==2017.4.17
configparser==3.5.0
decorator==4.0.11
entrypoints==0.2.3
enum34==1.1.6
funcsigs==1.0.2
functools32==3.2.3.post2
html5lib==0.9999999
ipykernel==4.6.1
ipython==5.4.1
ipython-genutils==0.2.0
ipywidgets==6.0.0
Jinja2==2.9.6
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.0.1
jupyter-console==5.1.0
jupyter-core==4.3.0
lxml==3.8.0
macholib==1.5.1
Markdown==2.2.0
MarkupSafe==1.0
matplotlib==1.3.1
mistune==0.7.4
mock==2.0.0
modulegraph==0.10.4
nbconvert==5.2.1
nbformat==4.3.0
nose==1.3.7
notebook==5.0.0
numpy==1.13.0
olefile==0.44
pandocfilters==1.4.1
pathlib2==2.3.0
pbr==3.1.1
pexpect==4.2.1
pickleshare==0.7.4
Pillow==4.1.1
prompt-toolkit==1.0.14
protobuf==3.3.0
ptyprocess==0.5.1
py2app==0.7.3
Pygments==2.2.0
pyobjc-core==2.5.1
pyobjc-framework-Accounts==2.5.1
pyobjc-framework-AddressBook==2.5.1
pyobjc-framework-AppleScriptKit==2.5.1
pyobjc-framework-AppleScriptObjC==2.5.1
pyobjc-framework-Automator==2.5.1
pyobjc-framework-CFNetwork==2.5.1
pyobjc-framework-Cocoa==2.5.1
pyobjc-framework-Collaboration==2.5.1
pyobjc-framework-CoreData==2.5.1
pyobjc-framework-CoreLocation==2.5.1
pyobjc-framework-CoreText==2.5.1
pyobjc-framework-DictionaryServices==2.5.1
pyobjc-framework-EventKit==2.5.1
pyobjc-framework-ExceptionHandling==2.5.1
pyobjc-framework-FSEvents==2.5.1
pyobjc-framework-InputMethodKit==2.5.1
pyobjc-framework-InstallerPlugins==2.5.1
pyobjc-framework-InstantMessage==2.5.1
pyobjc-framework-LatentSemanticMapping==2.5.1
pyobjc-framework-LaunchServices==2.5.1
pyobjc-framework-Message==2.5.1
pyobjc-framework-OpenDirectory==2.5.1
pyobjc-framework-PreferencePanes==2.5.1
pyobjc-framework-PubSub==2.5.1
pyobjc-framework-QTKit==2.5.1
pyobjc-framework-Quartz==2.5.1
pyobjc-framework-ScreenSaver==2.5.1
pyobjc-framework-ScriptingBridge==2.5.1
pyobjc-framework-SearchKit==2.5.1
pyobjc-framework-ServiceManagement==2.5.1
pyobjc-framework-Social==2.5.1
pyobjc-framework-SyncServices==2.5.1
pyobjc-framework-SystemConfiguration==2.5.1
pyobjc-framework-WebKit==2.5.1
pyOpenSSL==0.13.1
pyparsing==2.0.1
python-dateutil==2.6.0
pytz==2013.7
pyzmq==16.0.2
qtconsole==4.3.0
scandir==1.5
scipy==0.13.0b1
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.10.0
tensorflow==1.2.0
terminado==0.6
testpath==0.3.1
tornado==4.5.1
traitlets==4.3.2
vboxapi==1.0
virtualenv==15.1.0
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.12.2
widgetsnbextension==2.0.0
xattr==0.6.4
zope.interface==4.1.1
如果有人有线索,请。
修改1
我使用virtualenv,我找不到tensorflow / models /目录;
(objectDetects) $ pip show tensorflow
Name: tensorflow
Version: 1.2.0
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /tensorflow/objectDetects/lib/python2.7/site-packages
Requires: bleach, werkzeug, html5lib, six, markdown, backports.weakref, wheel, numpy, mock, protobuf
所以我尝试从根文件夹中导出它,并且它会吐出一个新的错误;
(objectDetects) $ export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
(objectDetects) $ python object_detection/builders/model_builder_test.py
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 "/tensorflow/objectDetects/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 "/tensorflow/objectDetects/object_detection/models/faster_rcnn_inception_resnet_v2_feature_extractor.py", line 29, in <module>
from nets import inception_resnet_v2
ImportError: No module named nets
答案 0 :(得分:2)
尝试将库添加到python路径
从tensorflow / models目录运行以下命令。
# From tensorflow/models/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
现在代码将成功运行。此命令需要从您启动的每个新终端运行。如果您希望避免手动运行,可以将其作为新行添加到〜/ .bashrc文件的末尾。
有关详细信息,请查看installation link:将库添加到PYTHON PATH部分。
答案 1 :(得分:0)
为避免每次发生此错误,可以将PYTHONPATH添加到〜/ .bashrc文件中。这是link供参考。
LOCAL_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
var=$(printf 'export PYTHONPATH="${PYTHONPATH}:%s/slim"' "$LOCAL_DIR")
echo $var >> ~/.bashrc
从tensorflow/models/research/
运行以上行,然后从同一目录运行以下行。
python object_detection/builders/model_builder_test.py