tensorflow / models

Models and examples built with TensorFlow
Other
77.05k stars 45.77k forks source link

In object_detection_tutorial #1591

Closed yuanzhuohao closed 7 years ago

yuanzhuohao commented 7 years ago

ImportError Traceback (most recent call last)

in () ----> 1 from utils import label_map_util 2 3 from utils import visualization_utils as vis_util ~/lab/dl/models/object_detection/utils/label_map_util.py in () 20 import tensorflow as tf 21 from google.protobuf import text_format ---> 22 from object_detection.protos import string_int_label_map_pb2 23 24 ImportError: cannot import name 'string_int_label_map_pb2'
zakizhou commented 7 years ago

you forgot to run this

From tensorflow/models/

protoc object_detection/protos/*.proto --python_out=.

chbaumgaertner commented 7 years ago

I get an equal error after running

#From tensorflow/models/
protoc object_detection/protos/*.proto --python_out=.
Traceback (most recent call last):
  File "create_pet_tf_record.py", line 40, in <module>
    from object_detection.utils import label_map_util
  File "/home/chris/tensorflow-models/models/object_detection/utils/label_map_util.py", line 22, in <module>
    import string_int_label_map_pb2
ImportError: No module named string_int_label_map_pb2
jch1 commented 7 years ago

@chbaumgaertner - Were there an error messages when you ran the protoc command? If it was successful, then you should see a bunch of extra files in the object_detection/protos directory of the form "xxx_pb2.py"

Anuraag-Advani commented 7 years ago

from object_detection.protos import string_int_label_map_pb2

Got this error, shouldn't it be
from protos import string_int_label_map_pb2

june9713 commented 7 years ago

@jessyuan24 @zakizhou @chbaumgaertner @jch1 @Anuraag-Advani

I found some of reason. but I dont know how to solve it. ipython notebook example file is in "object_detection" folder. So , print(os.getcwd()) will show you "/models/object_detection" but , "from object_detection.utils import label_map_util" this line load utils from "/models" current directory "/models/object_detection" but utils recognize current directory as "/models" So, one trick is work. "from object_detection.utils import label_map_util" --> "from utils import label_map_util" And it works.

But this is just trick. this is not perfact solution. somebody can solve this in windows enviorment please?

Vikramank commented 7 years ago

Hi guys, I had the same problem. But after running the protoc object_detection/protos/*.proto --python_out=. it worked fine. But my classes name and scores are not printed. Any suggestions? do I need to raise a separate issue?

june9713 commented 7 years ago

@Vikramank jessyuan24 is aleady run protoc, but he said error is still showing. And I've had same problem in windows. :-)

yuanzhuohao commented 7 years ago

@june9713 Maybe I should install protoc first

june9713 commented 7 years ago

@jessyuan24 Do you use windows virsion? or linux? If you are using windows, try my suggestion. :-)

chbaumgaertner commented 7 years ago

@june9713 your trick worked for now, thanks!

Vikramank commented 7 years ago

@june9713 @jessyuan24 great!

jemgold commented 7 years ago

I'm getting this when trying to run protoc

~/models# protoc object_detection/protos/*.proto --python_out=.
object_detection/protos/anchor_generator.proto:11:3: Expected "required", "optional", or "repeated".
object_detection/protos/anchor_generator.proto:11:32: Missing field number.

Any ideas? Using the dl-docker image on a Mac


EDIT: fixed - https://github.com/tensorflow/models/issues/1570

Anuraag-Advani commented 7 years ago

I am not being able to use any model but the 'ssd_mobilenet_v1_coco_11_06_2017' one. I get this error with 'MODEL_NAME = 'faster_rcnn_resnet101_coco_11_06_2017''

DecodeError                               Traceback (most recent call last)
<ipython-input-57-57652895f483> in <module>()
      4     with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
      5         serialized_graph = fid.read()
----> 6         od_graph_def.ParseFromString(serialized_graph)
      7         tf.import_graph_def(od_graph_def, name='')

DecodeError: Error parsing message
yuanzhuohao commented 7 years ago

@june9713 No, I use mac osx

astrung commented 7 years ago

For window users : Use protobuf binary : protoc-3.3.0-win32.zip then : \link\to\protoc object_detection/protos/*.proto --python_out=. > then you can import string_int_label_map_pb2

astrung commented 7 years ago

Also, can we using transfer-learning for running locally ? i see that we have a doc about transfer learning on cloud but i can not find any documents that write about transfer learning on local machine . I expected it in pipeline but i can not find it. So how can we config transfer learning on running locally

ghost commented 7 years ago

how to run this command? protoc object_detection/protos/*.proto --python_out=.

cmd or python is error

C:\Users\insor\Downloads\protoc-3.3.0-win32\bin>protoc.exe to C:\Users\insor\Desktop\k35 main\object detection\object_detection/protos/*.proto --python_out=. to: No such file or directory

yuanzhuohao commented 7 years ago

@astrung Thanks it works. @insort protoc install at https://github.com/google/protobuf

astrung commented 7 years ago

Also, can any one know about how to config for transfer learning on local machine ?

june9713 commented 7 years ago

@astrung transfer learning? Could you tell me what does it mean? Actually , I wanna train from scratch , but many error is occured. I followed instruction from "Quick Start: Training a pet detector" and "Running locally" (is mixed)

1 . I downloaded pet image files and annotate files from http://www.robots.ox.ac.uk/~vgg/data/pets/

  1. pet_label_map.pbtxt is already exist in data folder.

  2. make record file(https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_pets.md) python object_detection/create_pet_tf_record.py \ --label_map_path=object_detection/data/pet_label_map.pbtxt \ --data_dir=pwd \ --output_dir=pwd

  3. most confusing thing is pipeline config file. I dont know how to make config file exactly. /models/object_detection/samples/configs/ directory has some of sample config files. I just choose one file. I choose "faster_rcnn_resnet101_pets.config"

  4. edit faster_rcnn_resnet101_pets.config . some of directory and file path should be changing

  5. Now all ready is done.( I think) Lets start traingin.(https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_locally.md)

my pipeline_config_path is : '~/Desktop/models/object_detection/models/models/faster_rcnn_resnet101_pets.config' my train_dir is : ~/Desktop/models/object_detection/models/models/train

run below:

python object_detection/train.py --logtostderr \ --pipeline_config_path='~/Desktop/models/object_detection/models/models/faster_rcnn_resnet101_pets.config' \ --train_dir=~/Desktop/models/object_detection/models/models/train

But failed.

Error Message is as below.

tensorflow.python.framework.errors_impl.NotFoundError: ~/Desktop/models/object_detection/models/models/faster_rcnn_resnet101_pets.config

It means pipeline_config file is not exist. But file is obiously exist!! So I dont know reason. Im finding the reason. If anybody have idea , please help me. Thnaks :-)

astrung commented 7 years ago

@june9713 Pls copy full of your error message. You may need absolute path . Also, transfer learning = train from previous model. You can check here when train in google cloud . But i can not understand why copy previous model to GCS Bucket. can help us to use transfer learning and how can i do same thing when run from local

abhiML commented 7 years ago

I think you just need to put the model for transfer learning(eg. VGG or Resnet) in a folder and specify the path in the config file.

tejus-gupta commented 7 years ago

For pascal_voc, the model configuration says num_classes=20 but the label_map file has an extra class with id=0 and name='none_of_the_above'. Why is this extra label added?

abhiML commented 7 years ago

Background.

daniel0720 commented 7 years ago

Hello, I am in windows OS and downloaded protoc-3.3.0-win32.zip, after run protoc.exe object_detection\protos\*.proto --python_out=., I got a bunch of extra files in the object_detection/protos directory of the form "xxx_pb2.py". But I still cannot run python object_detection\builders\model_builder_test.py. Error is default So what is wrong?

june9713 commented 7 years ago

@daniel0720 This is simple reason.... Run cmd as administrator. you need to run "python3 setup.py build " and "python3 setup.py install" in models folder and /models/slim folder as Superuser(administrator). After that, you can run run test, but if you try to run train, you will meet error again... I wanna tell you reason... but it is too much log histoy about diff of py3 and py2. I think you can solve it if you know what is diff py2 and py3, otherwise, you should bring someones help. :-) 3

daniel0720 commented 7 years ago

@june9713 Thank you very much. I know some diff py2 and py3.

kaseyriver11 commented 7 years ago

I had the same problem. I changed my working directory to where the utils were: os.chdir('.../anaconda/lib/python3.6/site-packages/tensorflow/models')

And the the code worked fine: from object_detection.utils import label_map_util from object_detection.utils import visualization_utils as vis_util

june9713 commented 7 years ago

@kaseyriver11 Copy folder to site packages is good solution, but most easy way and clean way is setup.py insatll at models folder and slim folder to install models library. :-) Just type setup.py install at models folder and slim folder!

chakpongchung commented 7 years ago

Hi all, I had the same problem on ubuntu 16.04 tried:

cpchung:models$ uname -a Linux microway 4.8.0-56-generic #61~16.04.1-Ubuntu SMP Wed Jun 14 11:58:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

cpchung:models$ protoc --version libprotoc 3.2.0

protoc object_detection/protos/*.proto --python_out=. python setup.py install

no warning message found from these, but not working in jupyter-notebook

june9713 commented 7 years ago

@chakpongchung Why dont you show Error message?

chakpongchung commented 7 years ago

@june9713


ImportError Traceback (most recent call last)

in () ----> 1 from utils import label_map_util 2 from utils import visualization_utils as vis_util /local/home/cpchung/software/models/object_detection/utils/label_map_util.py in () 20 import tensorflow as tf 21 from google.protobuf import text_format ---> 22 from object_detection.protos import string_int_label_map_pb2 23 24 ImportError: cannot import name string_int_label_map_pb2
june9713 commented 7 years ago

@chakpongchung Do you use anaconda? Or... is your notebook kernal python2? Run python in console. And type "import object_detection" If there is no error, you need to find out what is kerneal in jupyter notebook

chakpongchung commented 7 years ago

cpchung:~$ python Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://anaconda.org

>>> import object_detection
>>> 

My notebook kernel is python2

june9713 commented 7 years ago

@chakpongchung I dont use anaconda... So I dont know what happens exactly. In my guess , your "setup.py" copies files to your conda path. but your notebook is finding packages from your pure python2.7 path. you need to test "import object_detection" in notebook. What do you think?

chakpongchung commented 7 years ago

@june9713

Thanks for your feedback. But:

cpchung:models$ which jupyter-notebook /local/home/cpchung/anaconda2/bin/jupyter-notebook

FPerezHernandez92 commented 7 years ago

I download the models: https://github.com/tensorflow/models I installed all and I do in directory: /models-master/: $ protoc object_detection/protos/*.proto --python_out=. $ export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim $ python object_detection/builders/model_builder_test.py

All fine, but, If I try do: https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_locally.md First I download annotations and images in directory: /object_detection/ , and I do in directory: /models-master/object_detection/ $ tar -xvf annotations.tar.gz $ tar -xvf images.tar.gz $ python create_pet_tf_record.py --data_dir=pwd --output_dir=pwd

In the pipeline I use the "faster_rcnn_resnet101_pets.config" and I changed the next: fine_tune_checkpoint: "/home/fperez/Descargas/models-master/object_detection/model.ckpt" I don't know, where the model.ckpt is. The other change is: """ train_input_reader: { tf_record_input_reader { input_path: "/home/fperez/Descargas/models-master/object_detection/pet_train.record" } label_map_path: "/home/fperez/Descargas/models-master/object_detection/data/pet_label_map.pbtxt" } eval_config: { num_examples: 2000 } eval_input_reader: { tf_record_input_reader { input_path: "/home/fperez/Descargas/models-master/object_detection/pet_val.record" } label_map_path: "/home/fperez/Descargas/models-master/object_detection/data/pet_label_map.pbtxt" } """

I do in directory: /models-master/ $ python object_detection/train.py --logtostderr --pipeline_config_path=object_detection/ --train_dir=object_detection/ and I had the next error: """ Traceback (most recent call last): File "object_detection/train.py", line 198, in tf.app.run() File "/home/fperez/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "object_detection/train.py", line 143, in main model_config, train_config, input_config = get_configs_from_pipeline_file() File "object_detection/train.py", line 103, in get_configs_from_pipeline_file text_format.Merge(f.read(), pipeline_config) File "/home/fperez/.local/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 125, in read pywrap_tensorflow.ReadFromStream(self._read_buf, length, status)) File "/usr/lib/python2.7/contextlib.py", line 24, in exit self.gen.next() File "/home/fperez/.local/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.FailedPreconditionError: object_detection """

But, when I do "import object_detection" in python terminal, It works fine. What is it my problem? Sorry for the inconvenience

june9713 commented 7 years ago

@FPerezHernandez92 Oh I have same problem either!! So I remove that line inconfig file. Then it works fine but, After traning, Problem occurs when I try freeze ckpt file to .pb file. And I found it is beacause of I removing line about model.ckpt from config file. Im trying to find answer but still didnt. I will let you know If I find somthing :-)

FPerezHernandez92 commented 7 years ago

What line do you say? @june9713 Because, I comment the line: fine_tune_checkpoint: "/home/fperez/Descargas/models-master/object_detection/model.ckpt" And I have the same error than my other message.

june9713 commented 7 years ago

@FPerezHernandez92 Do you install object_detection api to your pc? You need to do setup.py on /models/ folder.

FPerezHernandez92 commented 7 years ago

@june9713 Yes, I do in directory "models-master/: $ python setup.py sdist $ (cd slim && python setup.py sdist )

But the problem, when I do: $ python object_detection/train.py --logtostderr --pipeline_config_path=object_detection/ --train_dir=object_detection/

Is the same that I say in the other message.

vallettea commented 7 years ago

@Anuraag-Advani have you managed to tackle the problem of


DecodeError                               Traceback (most recent call last)
<ipython-input-57-57652895f483> in <module>()
     4     with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
     5         serialized_graph = fid.read()
----> 6         od_graph_def.ParseFromString(serialized_graph)
     7         tf.import_graph_def(od_graph_def, name='')

DecodeError: Error parsing message
``` ?
Anuraag-Advani commented 7 years ago

No

jtn-ms commented 7 years ago

I run the following command in /tensorflow/model protoc object_detection/protos/.proto --python_out=. but it returns the following error. object_detection/protos/.proto: Invalid argument Is there anyone could help me? I used anaconda3-4.2.0, tensorflow1.2.1 on windows8.1.

jtn-ms commented 7 years ago

the problem solved. I run .proto file one by one.

roblee357 commented 7 years ago

Do they have to be ran one by one or is there a better way?

awankuma commented 7 years ago

I got same problem, solved by rerunning export PYTHONPATH=$PYTHONPATH:'pwd':'pwd'/slim

Problem: single quote used for pwd was in some special character, type it after deleting from keyboard.

weogen commented 7 years ago

download the protoc_3.3,can solve this problem $ mkdir protoc_3.3 $ cd protoc_3.3 protoc_3.3$ wget wget https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip protoc_3.3$ chmod 775 protoc-3.3.0-linux-x86_64.zip protoc_3.3$ unzip protoc-3.3.0-linux-x86_64.zip cd ../tensorflow/models/ ../tensorflow/models$ home/../protoc_3.3/bin/protoc object_detection/protos/*.proto --python_out=.

yhmybzc commented 7 years ago

@roblee357 try to add like this: protoc object_detection/protos/.proto --python_out=.

yhmybzc commented 7 years ago

I have passed builder_test.py, but when I try to run locally as in running_locally.md I got following issues:

Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 198, in tf.app.run() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 44, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/root/.local/lib/python2.7/site-packages/object_detection/train.py", line 141, in main assert FLAGS.train_dir, 'train_dir is missing.' AssertionError: train_dir is missing.

then I tried to set default train_dir in trian.py instead of by command line, but another issue occurs:

File "/data/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.FailedPreconditionError: .

any suggestion would be grateful~please help...