EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials TensorFlow Tutorial TensorFlow dense
 

TensorFlow dense

Updated March 15, 2023

TensorFlow dense

 

 

Introduction to TensorFlow dense

Tensorflow dense is the type of layer and function available in Neural networks while implementing Artificial Intelligence and deep learning in a python programming language. Deep connections exist between the neurons in the neural network in dense layers. The pattern followed by them is such that each and every individual neuron gets the input of data from all of the previous layer’s neurons, forming the complex pattern. While on the other end, dense is also a function used in the neural networks of TensorFlow, which produces the output by applying activation of the dot of Kernel and input and adding the bias effect to it.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

In this article, we will first briefly discuss the understanding of tensorflow dense, how to use its function, the parameters and arguments it takes, and operations performed by it, and then study the implementation of the same along with the help of an example.

What is tensorflow dense?

The dense layer in neural networks is the one that executes matrix-vector multiplication. The matrix parameters are retrieved by updating and training using the backpropagation methodology. The final result of the dense layer is the vector of n dimensions. The use of dense layers can be extensively found in scaling, rotating, translating, and manipulating the dimensions of the vector.

Input shape of dense layer function in tensorflow –

Let us consider that we have an n-dimensional tensor with the shape of (size_of_batch, ….,input_dimensions). For example, in the case of 2-dimensional input, the shape will be (size_of_batch, input_dimensions)

Output shape of dense layer function in tensorflow –

The output shape of the N-dimensional tensor model will be (size_of_batch, …., units). For example, in the case of 2d input, the output shape will be (size of batch, units)

How to use function tensorflow dense

You will have to import the tensorflow library in your python program and then use the dense function by following its syntax. The syntax of using the dense function in tensorflow using the python programming language is as specified below –

The fully specified name of the function is tf.keras.layers.Dense and syntax is –

Dense (
Units,
Bias_initializer = “zeros”,
Activity_regularizer = None,
Kernel_regularizer = None,
Activation = None,
Kernel_initializer = “glorot_uniform”
Use_bias = True,
Bias_constraint = None,
Kernel_constraint = None,
** lwargs
)

The above-mentioned is the functional interface of the tensorflow dense() function or dense layer.

Parameters tensorflow dense

Let us understand the arguments or parameters that are to be passed to the tensorflow dense function in detail with the help of the tabular format mentioning the arguments and their corresponding description as shown below –

Arguments Description
Activation This is the function that we will be using. In case we don’t specify any, then none of the application of activations, such as linear or non-linear, will be applied, which also can be enacted as a(t) = t
Units This helps us represent the dimensions required in the output space and should be specified using any positive integer value.
Bias_initializer This is to specify the bias vector initialization.
Kernel_initializer It helps to give an initial value to the weight matrix of the Kernel.
Use_bias It is used for the specification of whether the layer that will be used internally makes the use of a bias vector or not. Therefore, we should specify a Boolean value here.
Kernel_constraint In the case of the kernel weight matrix, what should be the constraint function that should be applied is specified by this argument.
Kernel_regularizer In the case of the kernel weight matrix, this represents the regularizer function that should be applied to it.
Bias_Constraint In the case of a bias vector, what should be the constraint function that should be applied is specified by this argument.
Bias_regularizer In the case of the bias vector, this represents the regularizer function that should be applied to it.
Activity_regularizer In the activation mode function, the function that will be executed for regularizing the output of the layers is specified here.

Operation tensorflow dense

The operation performed by TensorFlow dense function are the output or result = activation (dot (input, kernel) + bias). In this operation, the activation stands for a function passed by the activation argument that performs element-wide activation. The other attributes are Kernel, the matrix of type weights that the dense layer can create. The bias parameter is the value of the vector generated by the dense layer and is applicable only when we set the parameter use_bias to the true value.

Note that once we call the function or layer, the attributes cannot be changed unless it’s a trainable attributes. One of the alternatives to define an external Inputlayer specification is that you can pass a popular kwarg input_shape, which will create the input layer that is inserted even before the current layer.

tensorflow dense Examples

Let us now consider a few examples to understand the implementation of the tensorflow dense in python.

Example #1

We will create a sequential model in tensorflow and then add the first layer of Dense. Further, the input arrays taken by the model will be of shape (Now,16), resulting in the creation of output layers of shape (None, 32). Once you specify the size of the input in the first layer addition, there is no necessity to specify the size from the second layer onwards. Our python code will look like this –

sampleEducbaModelTensorflow = tf.keras.sampleEducbaModelTensorflows.Sequential()
sampleEducbaModelTensorflow.add(tf.keras.Input(shape=(16,)))
sampleEducbaModelTensorflow.add(tf.keras.layers.Dense(32, activation='relu'))
sampleEducbaModelTensorflow.add(tf.keras.layers.Dense(32))
print(sampleEducbaModelTensorflow.output_shape)

The output of the execution of the above code will be as shown below –

TensorFlow dense output 1

Example #2

While using external neural networks involving only a single layer of dense in the tensorflow keras model. Suppose we specify the input shape of 32 and the rectified linear unit, the relu value in the activation function. In that case, the output of the summary method in python will give us the output shape of 32 only.

sampleDemoModel = keras.models.Sequential([
keras.Input(shape = (16, )),
keras.layers.Dense(32, activation='relu')
print(sampleDemoModel.summary())
])

The output of the above code is –

TensorFlow dense output 2

Conclusion

Tensorflow dense layer is used for implementing a dense layer that involves the neurons receiving the input from all the previous neurons that help implement the neural networks.

Recommended Articles

This is a guide to TensorFlow dense. Here we discuss the arguments or parameters to be passed to the tensorflow dense function in detail with the help of the tabular format. You may also have a look at the following articles to learn more –

  1. TensorFlow Load Model
  2. TensorFlow Dataset
  3. GitHub TensorFlow
  4. TensorFlow Probability

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW