
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create Input Function to Train Model in TensorFlow
An input function that would be used to train or evaluate the model can be created in Tensorflow by using the ‘from_tensor_slices’ method and creating a dictionary of the features of the iris dataset.
Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?
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.
Example
print("Input function that is used to train or evaluate") def input_fn(features, labels, training=True, batch_size=256): dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels)) if training: dataset = dataset.shuffle(1000).repeat() return dataset.batch(batch_size)
Output
Input function that is used to train or evaluate
Code credit −https://www.tensorflow.org/tutorials/estimator/premade#first_things_first
Explanation
The input function may generate the features dictionary and label list.
Data is loaded using pandas, and an input pipeline is built from this in-memory data