Asked  6 Months ago    Answers:  5   Viewed   2.3k times

I am trying to train my own custom object detector using Tensorflow Object-Detection-API

I installed the tensorflow using "pip install tensorflow" in my google compute engine. Then I followed all the instructions on this site:

When I try to use I am getting this error message:

Traceback (most recent call last): File "", line 49, in from import dataset_builder File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1->py3.6.egg/object_detection/builders/", line 27, in from object_detection.data_decoders import tf_example_decoder File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/data_decoders/", line 27, in slim_example_decoder = tf.contrib.slim.tfexample_decoder AttributeError: module 'tensorflow' has no attribute 'contrib'

Also I am getting different results when I try to learn version of tensorflow.

python3 -c 'import tensorflow as tf; print(tf.version)' : 2.0.0-dev20190422

and when I use

pip3 show tensorflow:

Name: tensorflow Version: 1.13.1 Summary: TensorFlow is an open source machine learning framework for everyone. Home-page: Author: Google Inc. Author-email: License: Apache 2.0 Location: /usr/local/lib/python3.6/dist-packages Requires: gast, astor, absl-py, tensorflow-estimator, keras-preprocessing, grpcio, six, keras-applications, wheel, numpy, tensorboard, protobuf, termcolor Required-by:

    sudo python3 --logtostderr --train_dir=training/ -- 

What should I do to solve this problem? I couldn't find anything about this error message except this: tensorflow 'module' object has no attribute 'contrib'



tf.contrib has moved out of TF starting TF 2.0 alpha.
Take a look at these tf 2.0 release notes
You can upgrade your TF 1.x code to TF 2.x using the tf_upgrade_v2 script

Wednesday, June 9, 2021
answered 6 Months ago

According to TF 1:1 Symbols Map, in TF 2.0 you should use tf.compat.v1.Session() instead of tf.Session()

To get TF 1.x like behaviour in TF 2.0 one can run

import tensorflow.compat.v1 as tf

but then one cannot benefit of many improvements made in TF 2.0. For more details please refer to the migration guide

Sunday, June 20, 2021
answered 6 Months ago

You normally import tensorflow by writing,

import tensorflow as tf

It's possible that you have named a file in your project and the import statement is importing from this file.

Alternatively, you can try this,

from tensorflow.python.framework import ops
Wednesday, July 28, 2021
answered 5 Months ago

I was unable to reproduce with the same versions of the keras and tensorflow, reinstalling keras and tensorflow, may solve the issue, please use commands below:

pip install --upgrade pip setuptools wheel
pip install -I tensorflow
pip install -I keras

NOTE: The -I parameter stands for ignore installed package.

Tuesday, August 3, 2021
answered 4 Months ago

Hope you have Saved the Estimator Model using the code similar to that mentioned below:

input_column = tf.feature_column.numeric_column("x")
estimator = tf.estimator.LinearClassifier(feature_columns=[input_column])

def input_fn():
    ({"x": [1., 2., 3., 4.]}, [1, 1, 0, 0])).repeat(200).shuffle(64).batch(16)

serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
export_path = estimator.export_saved_model(
  "/tmp/from_estimator/", serving_input_fn)

You can Load the Model using the code mentioned below:

imported = tf.saved_model.load(export_path)

To Predict using your Model by passing the Input Features, you can use the below code:

def predict(x):
  example = tf.train.Example()
  return imported.signatures["predict"](examples=tf.constant([example.SerializeToString()]))


For more details, please refer this link in which Saved Models using TF Estimator are explained.

Friday, November 12, 2021
answered 3 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :