models icon indicating copy to clipboard operation
models copied to clipboard

cannot import name 'estimator' from 'tensorflow.compat.v1'

Open subodh7591 opened this issue 8 months ago • 4 comments

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • [ yes] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • [ Yes] I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • [Yes ] I checked to make sure that this issue has not been filed already.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/tree/master/research/object_detection

2. Describe the bug

I am using tensorflow 2.19 and latest version of the object detection api. While training the models it raises error estimator cannot import name estimator from tensorflow.compat.v1. I found that the last support for the estimator from tensorflow.comapt.v1 was in tensorflow==2.15. I tried downgrading to 2.15 which solves this issue but raises other issues.

3. Steps to reproduce

command = [ "python", "models/research/object_detection/model_main_tf2.py", f"--model_dir={checkpoint_path}", f"--pipeline_config_path={pipeline_config_path}", "--num_train_steps=10000", "--sample_1_of_n_eval_examples=1", "--alsologtostderr" ]

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)

4. Expected behavior

It should have trained the model without raising error.

5. Additional context

Traceback (most recent call last): File "/mnt/d/computer vision code/models/research/object_detection/model_main_tf2.py", line 31, in from object_detection import model_lib_v2 File "/mnt/d/computer vision code/models/research/object_detection/model_lib_v2.py", line 30, in from object_detection import inputs File "/mnt/d/computer vision code/models/research/object_detection/inputs.py", line 24, in from tensorflow.compat.v1 import estimator as tf_estimator ImportError: cannot import name 'estimator' from 'tensorflow.compat.v1' (/home/administrator/miniconda3/envs/object/lib/python3.10/site-packages/tensorflow/_api/v2/compat/v1/init.py)

❌ Training failed for ssd_mobilenet

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • Mobile device name if the issue happens on a mobile device:
  • TensorFlow installed from (source or binary):
  • TensorFlow version (use command below):
  • Python version:
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

subodh7591 avatar Jun 26 '25 08:06 subodh7591

same issue

rorkyendo avatar Jul 03 '25 07:07 rorkyendo

Switch to newer frameworks? Or research through the web.

Petros626 avatar Jul 03 '25 21:07 Petros626

Switch to newer frameworks? Or research through the web.

in my case, i want to train image with ssdmobilenetv2. The framework library was deprecated in google collabs environment. cause it's only work in python 10 but gc env has updated into python 11, and if it can running we can't use GPU for it.

rorkyendo avatar Jul 03 '25 23:07 rorkyendo

I've trained this network several years before with TF 1.15. The installation was a bit tricky, but with information from issues, youtube etc. I managed to create a running setup.

I wouldn't use the provided google colabs from TensorFlow team, instead use directly the python scripts. I used Python 3.7 or 3.8 with TF 1.15 and it worked fine.

Petros626 avatar Jul 04 '25 08:07 Petros626