tensorflow.python.eager.polymorphic_function No module error on imports

Issue

I have tried checking around for the solution for this error but all solutions I have found are not working. I am requesting for more assistance. I have this tensorflow error

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
c:\Users\lmumelo\Documents\GitHub\NAR_Tensorflow_OD\scripts\modelling\NAR Object Detection Project.ipynb Cell 3 in <cell line: 25>()
     20 #from tflite_model_maker import model_spec
     21 #from tflite_model_maker import object_detector
     23 sys.path.append("..")
---> 25 from object_detection.utils import visualization_utils as vis_util
     26 from object_detection.utils import dataset_util, label_map_util, config_util
     27 from object_detection.protos import string_int_label_map_pb2

File c:\Users\lmumelo\Anaconda3\envs\tensorflow\lib\site-packages\object_detection\utils\visualization_utils.py:39, in <module>
     37 from six.moves import range
     38 from six.moves import zip
---> 39 import tensorflow.compat.v1 as tf
     41 from object_detection.core import keypoint_ops
     42 from object_detection.core import standard_fields as fields

File ~\AppData\Roaming\Python\Python39\site-packages\tensorflow\__init__.py:92, in <module>
     90 from tensorflow.python.eager.backprop import GradientTape
     91 from tensorflow.python.eager.context import executing_eagerly
---> 92 from tensorflow.python.eager.polymorphic_function.polymorphic_function import function
     93 from tensorflow.python.framework.constant_op import constant
     94 from tensorflow.python.framework.device_spec import DeviceSpecV2 as DeviceSpec

ModuleNotFoundError: No module named 'tensorflow.python.eager.polymorphic_function'

The error is being generated from this imports

from object_detection.utils import visualization_utils as vis_util
from object_detection.utils import dataset_util, label_map_util, config_util
from object_detection.protos import string_int_label_map_pb2
from object_detection.utils import ops as utils_ops
from object_detection.protos import pipeline_pb2
from object_detection.builders import model_builder
from google.protobuf import text_format

import tensorflow as tf

And here is a list of installed packages

tb-nightly                    2.11.0a20221023
tensorboard                   2.10.1
tensorboard-data-server       0.6.1
tensorboard-plugin-wit        1.8.0
tensorflow                    2.5.0
tensorflow-addons             0.18.0
tensorflow-datasets           4.7.0
tensorflow-estimator          2.5.0
tensorflow-hub                0.12.0
tensorflow-io                 0.27.0
tensorflow-io-gcs-filesystem  0.27.0
tensorflow-metadata           1.10.0
tensorflow-model-optimization 0.7.3
tensorflow-text               2.10.0
termcolor                     1.1.0
terminado                     0.13.1
testpath                      0.6.0
text-unidecode                1.3
tf-estimator-nightly          2.12.0.dev2022102308
tf-models-official            2.10.0
tf-nightly                    2.12.0.dev20221023
tf_nightly_intel              2.12.0.dev20221023

I have tried

pip uninstall tensorflow
pip install tensorflow --upgrade

But this solutions are not working. Anyone who has ever experienced this error and solved it. NOTE that I am using anaconda environment to develop this tensorflow model and all packages are installed in that environment

Solution

it is easy to backward compatibilities try searching for version compatibilities and checkout from this website TFLite Authoring Tool they had the same problem and me testing it on the same from Git.

I am testing and found that the update link is targeting the incorrect path where I am using AMD. ( Prepending update )

platform_machine != "arm64" or platform_system != "Darwin", 
but you have tensorflow 2.10.0 which is incompatible.

Still building the rest of the package and trying to complied it to simulate following your question but the only thing I found is the miss attached link to target now.

import sys
sys.path.append('C:\\Python310\\object_detection')

import numpy as np
import tensorflow as tf
print(np.__version__)
print(tf.__version__)

from object_detection.utils import visualization_utils as vis_util

from object_detection.utils import ops as utils_ops
from object_detection.utils import label_map_util

# from object_detection.protos import pipeline_pb2
# from object_detection.builders import model_builder
# from object_detection.utils import dataset_util, label_map_util, config_util
# from object_detection.protos import string_int_label_map_pb2


from google.protobuf import text_format

import tensorflow_models as tfm

Sample

Answered By – Jirayu Kaewprateep

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published