Models: ModuleNotFoundError: No module named 'official'

Created on 13 Mar 2020  路  10Comments  路  Source: tensorflow/models

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 (64 bit)
  • Mobile device (e.g., Pixel 4, Samsung Galaxy 10) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary):
  • TensorFlow version (use command below): 2.1.0
  • Python version: 3.7
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: 10.1
  • GPU model and memory: GTX 1050ti and 4 GB

I am running below script mentioned here and it gives me ModuleNotFoundError: No module named 'official'.

python mnist_main.py \
--model_dir=$MODEL_DIR \
--data_dir=$DATA_DIR \
--train_epochs=10 \
--distribution_strategy=one_device \
--num_gpus=$NUM_GPUS \
--download

official bug

Most helpful comment

For the same issue on Colab:
I had to add the following after cloning the models

!git clone https://github.com/tensorflow/models.git

import os
os.environ['PYTHONPATH'] += ":/content/models"

import sys
sys.path.append("/content/models")...

Thanks to [https://stackoverflow.com/questions/50121477/tensorflow-no-module-named-official]

All 10 comments

If you have cloned the repo,
the first step is to add export PYTHONPATH=$PYTHONPATH:/path/to/models
/path/to/models means the path the "models" folder. Then it can recognize the sub-folder official.

@saberkun Yes I forgot to add path. Thanks

I cloned the repo, added the path, and finished installing the dependencies.
There was no problem with this. However, when I try to run mnist codes, I also gets the same errors.

I had added

export PYTHONPATH=$PYTHONPATH:/path/to/models
````

but still has the same problem as @Eshan-Agarwal.

I am trying to run 

python3 mnist_main.py \
--model_dir=$MODEL_DIR \
--data_dir=$DATA_DIR \
--train_epochs=10 \
--distribution_strategy=one_device \
--num_gpus=$NUM_GPUS \
--download


but gets the same error message

ModuleNotFoundError: No module named 'official'



Here is the full error message in case:

2020-04-17 19:40:19.475339: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory
2020-04-17 19:40:19.475565: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory
2020-04-17 19:40:19.475644: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
Traceback (most recent call last):
File "mnist_main.py", line 28, in
from official.utils.flags import core as flags_core
ModuleNotFoundError: No module named 'official'


does this below command line should be typed in a specific directory such as the top 'models' folder?

export PYTHONPATH=$PYTHONPATH:/path/to/models
```

Or is it another problem?

If you're using fish shell you'll have to use this instead:
set --export PYTHONPATH path/to/models $PYTHONPATH

For the same issue on Colab:
I had to add the following after cloning the models

!git clone https://github.com/tensorflow/models.git

import os
os.environ['PYTHONPATH'] += ":/content/models"

import sys
sys.path.append("/content/models")...

Thanks to [https://stackoverflow.com/questions/50121477/tensorflow-no-module-named-official]

https://github.com/tensorflow/models/issues/8291#issuecomment-661930520

For the same issue on Colab:
I had to add the following after cloning the models

!git clone https://github.com/tensorflow/models.git

import os
os.environ['PYTHONPATH'] += ":/content/models"

import sys
sys.path.append("/content/models")...

Thanks to [https://stackoverflow.com/questions/50121477/tensorflow-no-module-named-official]

thy it fixt it thy

do the following in colab it will work

!apt-get install protobuf-compiler python-pil python-lxml python-tk
!pip install Cython tf_slim
!git clone https://github.com/tensorflow/models.git
%cd /content/models/research
!protoc object_detection/protos/*.proto --python_out=.
%set_env PYTHONPATH=/content/models/research:/content/models/research/slim
import os
os.environ['PYTHONPATH'] += ":/content/models"
import sys
sys.path.append("/content/models")
!python object_detection/builders/model_builder_test.py

I hope using the pip package tf-models-official can help set up the python path.

try in ../models/research pip install tf-models-official

try in ../models/research pip install tf-models-official

Dude i'm getting error model_builder.py. How to set pythonpath to models? i mean from command prompt or environment variables?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ludazhao picture ludazhao  路  111Comments

10183308 picture 10183308  路  50Comments

pjeambrun picture pjeambrun  路  51Comments

ddurgaprasad picture ddurgaprasad  路  48Comments

edwardHujber picture edwardHujber  路  82Comments