TensorFlow Estimator (Nightly)

raw JSON →
2.16.0.dev2024012409 verified Fri May 01 auth: no python

Nightly build of TensorFlow Estimator, a high-level TensorFlow API that simplifies machine learning model training and evaluation. Current version 2.16.0.dev2024012409, released nightly. Should only be used with matching TensorFlow nightly builds.

pip install tf-estimator-nightly
error ModuleNotFoundError: No module named 'tf_estimator'
cause Attempting to import tf_estimator directly instead of using the TensorFlow submodule.
fix
Use import tensorflow.compat.v1.estimator as estimator
error AttributeError: module 'tensorflow' has no attribute 'estimator'
cause Using TensorFlow 2.x without compat.v1; estimator is removed from TF2 core.
fix
Use import tensorflow.compat.v1.estimator as estimator
error ImportError: cannot import name 'LinearRegressor' from 'tensorflow_estimator.python.estimator.canned.linear' (unknown location)
cause Version mismatch between tf-estimator and tf-nightly.
fix
Reinstall both packages with matching dates: pip install --upgrade tf-nightly tf-estimator-nightly
breaking tf-estimator-nightly requires a matching tf-nightly version. Mixing releases will cause import failures like 'cannot import name'.
fix Install both nightly packages from the same date: pip install tf-nightly tf-estimator-nightly
deprecated TensorFlow Estimator is in maintenance mode; Keras is the preferred high-level API. New features are only added to Keras.
fix Consider migrating to tf.keras or Keras 3 for active development.
gotcha Importing directly from tf_estimator (e.g., import tf_estimator) will fail because the package is a namespace package inside TensorFlow.
fix Use from tensorflow.compat.v1 import estimator

Minimal example using tf.compat.v1.estimator with TF nightly.

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
import tensorflow.compat.v1.estimator as estimator

# Define a simple linear regressor
feature_columns = [tf.feature_column.numeric_column('x', shape=[1])]
regressor = estimator.LinearRegressor(feature_columns=feature_columns)

# Mock input function
def input_fn():
    return {'x': [[1.0], [2.0], [3.0]]}, [1.0, 2.0, 3.0]

# Train
regressor.train(input_fn=input_fn, steps=100)

# Predict
predictions = regressor.predict(input_fn=input_fn)
try:
    for i, p in enumerate(predictions):
        print(p['predictions'])
        if i > 2:
            break
except StopIteration:
    pass