0

I have the following function:

def build_estimator(model_dir, model_type):
    """Build an estimator."""

    # Wide columns and deep columns.
    wide_columns = []

    deep_columns = []

    for c in COLUMNS:
        # Sparse base columns.
        print(">>>>>>>>>>>>>>>>>>>")
        print(c)
        column = tf.contrib.layers.sparse_column_with_hash_bucket(c, hash_bucket_size=10000)
        deep_columns.append(tf.contrib.layers.embedding_column(column, dimension=8))
        #wide_columns.append(column)

    if model_type == "wide":
        m = tf.contrib.learn.LinearClassifier(model_dir=model_dir, 
                                              feature_columns=wide_columns)
    elif model_type == "deep":
        m = tf.contrib.learn.DNNClassifier(model_dir=model_dir, 
                                           feature_columns=deep_columns, 
                                           hidden_units=[100, 50])
    else:
        m = tf.contrib.learn.DNNLinearCombinedClassifier(
            model_dir=model_dir,
            linear_feature_columns=wide_columns,
            dnn_feature_columns=deep_columns,
            dnn_hidden_units=[100, 50])

    return m

But when I run it, I get this exception:

Traceback (most recent call last):
File "ad_tf.py", line 336, in
main([sys.argv[0]] + unparsed)
File "ad_tf.py", line 218, in main
m = build_estimator(model_dir, 'wide_n_deep')
File "ad_tf.py", line 58, in build_estimator
column = tf.contrib.layers.sparse_column_with_hash_bucket(c, hash_bucket_size=10000)
AttributeError: module 'tensorflow' has no attribute 'contrib'

I tried using tensorflow 1.x but it didn't dix anything. What is the replacement to contrib?

4
  • Possible duplicate of stackoverflow.com/questions/55870127/… Commented Jan 16, 2020 at 10:04
  • 1
    I tried applying the solution in the above question, but it didn't work for me. Commented Jan 16, 2020 at 10:08
  • What exactly did you try? What versions of TF have you tried it on? Commented Jan 16, 2020 at 10:50
  • TF 2 and TF 1.4 Commented Jan 16, 2020 at 11:44

1 Answer 1

0

TF.contrib is removed from Tfv 2.x. It is recommended to use latest Tensorflow version 2.x. Convert your code from Tf1.x to Tf 2.x by following migration guide

Remove old tf.contrib.layers and replace them with TF Slim symbols. Also check TF Addons for other tf.contrib symbols.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.