Help with training on Windows: ImportError: cannot import name 'tensor' from 'tensorflow.python.framework'

Hi there,

i am having an issue training a model, i am using: ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8 from the model zoo.

i would like to train it with my own dataset.

I am using an up to date install of Windows 10, python 3.8 & Tensorflow 2.10.1.

these is my pip list of the packages i think that matter, if you need more i can include them also.

object-detection 0.1
protobuf 3.19.6
tensorboard 2.10.1
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.1
tensorflow 2.10.1
tensorflow-addons 0.22.0
tensorflow-datasets 4.9.0
tensorflow-estimator 2.10.0
tensorflow-gpu 2.10.1
tensorflow-hub 0.16.1
tensorflow-intel 2.10.1
tensorflow-io 0.31.0
tensorflow-io-gcs-filesystem 0.31.0
tensorflow-metadata 1.13.0
tensorflow-model-optimization 0.7.5
tensorflow-text 2.10.0
termcolor 2.4.0
terminado 0.18.0
text-unidecode 1.3
tf-keras 2.15.0
tf-models-official 2.10.1
tf-slim 1.1.0

everytime i try and run it i get the below error:

c:\python>python train.py
Traceback (most recent call last):
File “c:\python\train.py”, line 6, in
from object_detection import model_main_tf2
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\object_detection\model_main_tf2.py”, line 31, in
from object_detection import model_lib_v2
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\object_detection\model_lib_v2.py”, line 30, in
from object_detection import inputs
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\object_detection\inputs.py”, line 27, in
from object_detection.builders import model_builder
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\object_detection\builders\model_builder.py”, line 70, in
from object_detection.models import ssd_efficientnet_bifpn_feature_extractor as ssd_efficientnet_bifpn
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\object_detection\models\ssd_efficientnet_bifpn_feature_extractor.py”, line 35, in
from official.legacy.image_classification.efficientnet import efficientnet_model
File “C:\python\models\official\legacy\image_classification\efficientnet\efficientnet_model.py”, line 30, in
import tensorflow as tf, tf_keras
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras_init_.py”, line 3, in
from tf_keras import internal
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras_internal__init_.py”, line 3, in
from tf_keras.internal import backend
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras_internal_\backend_init_.py”, line 3, in
from tf_keras.src.backend import initialize_variables as initialize_variables
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src_init
.py", line 21, in
from tf_keras.src import applications
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\applications_init_.py”, line 18, in
from tf_keras.src.applications.convnext import ConvNeXtBase
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\applications\convnext.py”, line 28, in
from tf_keras.src import backend
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\backend.py”, line 35, in
from tf_keras.src.engine import keras_tensor
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\engine\keras_tensor.py”, line 19, in
from tf_keras.src.utils import object_identity
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\utils_init_.py”, line 53, in
from tf_keras.src.utils.feature_space import FeatureSpace
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\utils\feature_space.py”, line 20, in
from tf_keras.src.engine import base_layer
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\engine\base_layer.py”, line 35, in
from tf_keras.src.dtensor import lazy_variable
File “C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tf_keras\src\dtensor\lazy_variable.py”, line 23, in
from tensorflow.python.framework import tensor
ImportError: cannot import name ‘tensor’ from ‘tensorflow.python.framework’ (C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\framework_init_.py)

Now to me reading through the error, it seems like the model i download from tensorflow with:

git clone GitHub - tensorflow/models: Models and examples built with TensorFlow

folowing this tutorial:

download new models that maybe arent compatable with tensorflow 2.10.1, as they require tf-keras, and the oldest version of tf-keras is 2.14.x.

any help resolving this would be very appreciated, i have been trying to figure this out for around 3-4 days now.

Thanks, James.

Hi @James_Morrish, As per my knowledge the tensor module is present starting from tensorflow 2.13. Could you please try by using the tensorflow version >= 2.13. Thank You.