# How can Tensorflow be used with Estimators to return a two element tuple?

A two-element tuple can be returned by processing iris flower dataset by creating a method that takes the features and labels, and returns them as Numpy arrays.

We will use the Keras Sequential API, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.

A neural network that contains at least one layer is known as a convolutional layer. We can use the Convolutional Neural Network to build learning model.

TensorFlow Text contains collection of text related classes and ops that can be used with TensorFlow 2.0. The TensorFlow Text can be used to preprocess sequence modelling.

We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.

An Estimator is TensorFlow's high-level representation of a complete model. It is designed for easy scaling and asynchronous training.

The model is trained using iris data set. There are 4 features, and one label.

• sepal length
• sepal width
• petal length
• petal width

## Example

print("Function that returns a two-element tuple")
def input_evaluation_set():
features = {'SepalLength': np.array([6.4, 5.0]),
'SepalWidth': np.array([2.8, 2.3]),
'PetalLength': np.array([5.6, 3.3]),
'PetalWidth': np.array([2.2, 1.0])}
labels = np.array([2, 1])
return features, labels

## Output

Function that returns a two-element tuple

## Explanation

• Once the data is set up, the model can be defined using Tensorflow estimator.

• An Estimator is any class derived from tf.estimator.Estimator

• One or more input functions are created.

• The model's feature columns are defined.

• An Estimator is instantiated, where the feature columns and various hyperparameters are specified.

• One or more methods on the Estimator object is called, and appropriate inout function is passed as source.

Updated on: 22-Feb-2021

126 Views