Windows 上的 Tensorflow 对象检测 API - 错误“ModuleNotFoundError: No module named 'utils'" [英] Tensorflow Object Detection API on Windows - error "ModuleNotFoundError: No module named 'utils'"

查看:85
本文介绍了Windows 上的 Tensorflow 对象检测 API - 错误“ModuleNotFoundError: No module named 'utils'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取 TensorFlow 对象检测 API

13) 同样在 Environment Variables 下,编辑 PATH 并添加 %PYTHONPATH%,如下所示:

14) 重新启动以确保这些路径更改生效

15) 拉出命令提示符并运行命令set",验证 PYTHONPATH 是否存在,并且 PYTHONPATH 和 PATH 包含前面步骤中的值.

16) 现在您可以将object_detection_tutorial.py"复制到任何其他目录,它就会运行

解决方案

正如评论中提到的,utils 是一个子模块,因此您实际上需要将 object_detection 添加到 <代码>PYTHONPATH,而不是object_detection/utils.

很高兴它对你有用.

I'm attempting to get the TensorFlow Object Detection API

https://github.com/tensorflow/models/tree/master/research/object_detection

working on Windows by following the install instructions

https://github.com/tensorflow/models/tree/master/research/object_detection

Which seem to be for Linux/Mac. I can only get this to work if I put a script in the directory I cloned the above repo to. If I put the script in any other directory I get this error:

ModuleNotFoundError: No module named 'utils'

I suspect that the cause is not properly doing the Windows equivalent of this command listed on the install instructions above:

# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

I'm using Windows 10, Python 3.6, and TensorFlow 1.4.0 if that matters. Of course, I've Googled on this concern and found various links, for example, this:

https://github.com/tensorflow/models/issues/1747

But this has not resolved the concern. Any suggestions on how to resolve this?

Here are the steps I've done so far specifically:


EDIT: these steps work now after updating to incorporate RecencyEffect's answer

1) Install TensorFlow and related tools via pip3

2) From an administrative command prompt, run the following:

pip3 install pillow
pip3 install lxml
pip3 install jupyter
pip3 install matplotlib

3) Clone the TensorFlow "models" repository to the Documents folder, in my case

C:\Users\cdahms\Documents\models

4) Downloaded Google Protobuf https://github.com/google/protobuf Windows v3.4.0 release "protoc-3.4.0-win32.zip" (I tried the most current 3.5.1 and got errors on the subsequent steps, so I tried 3.4.0 per this vid https://www.youtube.com/watch?v=COlbP62-B-U&list=PLQVvvaa0QuDcNK5GeCQnxYnSSaar2tpku&index=1 and the protobuf compile worked)

5) Extract the Protobuf download to Program Files, specifically

"C:\Program Files\protoc-3.4.0-win32"

6) CD into the models\research directory, specifically

cd C:\Users\cdahms\Documents\models\research

7) Executed the protobuf compile, specifically

"C:\Program Files\protoc-3.4.0-win32\bin\protoc.exe" object_detection/protos/*.proto --python_out=.

Navigate to:

C:\Users\cdahms\Documents\models\research\object_detection\protos

and verify the .py files were created successfully as a result of the compile (only the .proto files were there to begin with)

8) cd to the object_detection directory, ex:

cd C:\Users\cdahms\Documents\models\research\object_detection

then enter the following at a command prompt to start the object_detection_tutorial.ipynb Jupyter Notebook

jupyter notebook

9) In the Jupyter Notebook, choose "object_detection_tutorial.ipynb" -> Cell -> Run all, the example should run within the notebook

10) In the Jupyter Notebook, choose "File" -> "Download As" -> "Python", and save the .py version of the notebook to the same directory, i.e.

C:\Users\cdahms\Documents\models\research\object_detection\object_detection_tutorial.py

You can now open the script in your chosen Python editor (ex. PyCharm) and run it.


EDIT per RecencyEffect's answer below, if you follow these additional steps you will be able to run the object_detection_tutorial.py script from any directory

11) Move the script to any other directory, then attempt to run it and you will find you will get the error:

ModuleNotFoundError: No module named 'utils'

because we have not yet informed Python how to find the utils directory that these lines use:

from utils import label_map_util
from utils import visualization_utils as vis_util

To resolve this . . .

12) Go to System -> Advanced system settings -> Environment Variables . . . -> New, and add a variable with the name PYTHONPATH and these values:

13) Also under Environment Variables, edit PATH and add %PYTHONPATH% like so:

14) Reboot to make sure these path changes take effect

15) Pull up a command prompt and run the command "set", verify PYTHONPATH is there and PYTHONPATH and PATH contained the values from the previous steps.

16) Now you can copy the "object_detection_tutorial.py" to any other directory and it will run

解决方案

As mentioned in the comment, utils is a submodule so you actually need to add object_detection to PYTHONPATH, not object_detection/utils.

I'm glad it worked for you.

这篇关于Windows 上的 Tensorflow 对象检测 API - 错误“ModuleNotFoundError: No module named 'utils'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆