问题
I'm trying to use the Tensorflow Object Detection API and I've successfully tested the installation,but we I try to generate the PASCAL VOC TFRecord files with the given command
python object_detection/create_pascal_tf_record.py \
--label_map_path=object_detection/data/pascal_label_map.pbtxt \
--data_dir=VOCdevkit --year=VOC2012 --set=train \
--output_path=pascal_train.record
I encountered the following error:
Traceback (most recent call last):
File "object_detection/create_pascal_tf_record.py", line 36, in <module>
from object_detection.utils import dataset_util
ImportError: No module named object_detection.utils
my PYTHONPATH is:
:/usr/local/lib/python2.7/dist-packages/tensorflow/models:/usr/local/lib/python2.7/dist-packages/tensorflow/models/slim
and I'm running the above command in the /models directory,anyone who knows how to fix this problem?
回答1:
I had the same problem and I solved it by adding :
import os
import sys
sys.path.append(os.path.abspath("./object_detection"))
and
from object_detection.utils import dataset_util
becomes
from utils import dataset_util
回答2:
It's better for you to add 'object_detection' to the env path, not in the python script.
You can do this in the shell, at the 'object_detection' directory.
export PYTHONPATH=$PYTHONPATH:`pwd`
Or add the path to .bashrc/.zshrc (depend on your shell), so don‘t need to export every time.
echo "export PYTHONPATH=$PYTHONPATH:`pwd` >> ~/.bashrc
来源:https://stackoverflow.com/questions/45254975/tensorflow-object-detection-api-importerror-when-generating-pascal-tfrecord-file