EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials PyTorch Tutorial PyTorch sequential
Secondary Sidebar
PyTorch Tutorial
  • PyTorch
    • PyTorch Image Classification
    • PyTorch Random
    • PyTorch Variable
    • PyTorch Activation Function
    • Python Formatted String
    • PyTorch GPU
    • PyTorch CUDA
    • PyTorch DataLoader
    • PyTorch LSTM
    • PyTorch Pad
    • PyTorch OpenCL
    • PyTorch Lightning
    • PyTorch SoftMax
    • PyTorch Flatten
    • PyTorch gan
    • PyTorch max
    • PyTorch pip
    • PyTorch Parameter
    • PyTorch Load Model
    • PyTorch Distributed
    • PyTorch BERT
    • PyTorch interpolate
    • PyTorch JIT
    • PyTorch expand
    • PyTorch AMD
    • PyTorch GRU
    • PyTorch rnn
    • PyTorch permute
    • PyTorch argmax
    • PyTorch SGD
    • PyTorch nn
    • PyTorch One Hot Encoding
    • PyTorch Tensors
    • What is PyTorch?
    • PyTorch MSELoss()
    • PyTorch NLLLOSS
    • PyTorch MaxPool2d
    • PyTorch Pretrained Models
    • PyTorch Squeeze
    • PyTorch Reinforcement Learning
    • PyTorch zero_grad
    • PyTorch norm
    • PyTorch VAE
    • PyTorch Early Stopping
    • PyTorch requires_grad
    • PyTorch MNIST
    • PyTorch Conv2d
    • Dataset Pytorch
    • PyTorch tanh
    • PyTorch bmm
    • PyTorch profiler
    • PyTorch unsqueeze
    • PyTorch adam
    • PyTorch backward
    • PyTorch concatenate
    • PyTorch Embedding
    • PyTorch Tensor to NumPy
    • PyTorch Normalize
    • PyTorch ReLU
    • PyTorch Autograd
    • PyTorch Transpose
    • PyTorch Object Detection
    • PyTorch Autoencoder
    • PyTorch Loss
    • PyTorch repeat
    • PyTorch gather
    • PyTorch sequential
    • PyTorch U-NET
    • PyTorch Sigmoid
    • PyTorch Neural Network
    • PyTorch Quantization
    • PyTorch Ignite
    • PyTorch Versions
    • PyTorch TensorBoard
    • PyTorch Dropout
    • PyTorch Model
    • PyTorch optimizer
    • PyTorch ResNet
    • PyTorch CNN
    • PyTorch Detach
    • Single Layer Perceptron
    • PyTorch vs Keras
    • torch.nn Module

PyTorch sequential

PyTorch sequential

Definition of  PyTorch sequential

PyTorch provides the different types of classes to the user, in which that sequential is, one of the classes that are used to create the PyTorch neural networks without any explicit class. Basically, the sequential module is a container or we can say that the wrapper class is used to extend the nn modules. The sequential container is added to the constructor otherwise we can use the forward() method to pass the sequential container to the constructor. Normally sequential containers work in a chain manner that is the input of one container we pass to the next container as per our requirement and finally it returns the output of the last modules.

What is PyTorch sequential?

In the sequential container, modules will be added to it in the request they be passed in the constructor. Then again, an OrderedDict of modules can be passed in. The forward() strategy for Sequential acknowledges any info and advances it to the principal module it contains. It then, at that point “chains” yields to inputs successively for each resulting module, at last returning the yield of the last module.

The worth a Sequential give over physically calling a grouping of modules is that it permits regarding the entire holder as a solitary module, with the end goal that playing out a change on the Sequential applies to each of the modules it stores (which are each an enlisted submodule of the Sequential).

What’s the contrast between a Sequential and a torch.nn.ModuleList? A ModuleList is actually what it seems like a rundown for putting away Modules! Then again, the layers in a Sequential are associated in a falling way.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

How to use PyTorch sequential?

Now let’s see how we can use the sequential container as follows. For the implementation of the sequential class, we need to use different steps as follows.

First, we need to import the required packages that we want. After that, we need to create the dataset as per our requirements. After the creation of the dataset, we need to create the Model. Now, you might be pondering with regards to tasks like actuation works and pooling activities, and leveling activities. The majority of the tasks are in the neural organization practical API. Interestingly, PyTorch has wrapped itself within a neural organization module itself.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,560 ratings)

The successive class develops the forward strategy certainly by consecutively constructing network design. PyTorch successive model is a holder class or otherwise called a covering class that permits us to create the neural organization models. We can form any neural organization model together utilizing the Sequential model. This implies that we create layers to create organizations and we can even make different organizations together.

import torch. nn as nn
import torch.nn.functional as Fun

torch.nn.functional as fun permits us to make consecutive models and by being able to characterize our layers, our actuation capacities, our smooth tasks are pulling activities. The principal focal point here is that having these capacities wrapped up as neural organization models permit us to utilize the consecutive class to wrap different modules and create them together. We can form convolutions with max-pooling tasks with ReLU enactment capacities with straightened activities and what this does is permit us to assemble our models in consecutive order.

PyTorch sequential Model

Now let’s see how we can create the sequential Model as follows.

A sequential module is a compartment or covering class that expands the nn. Module base class and permits us to form modules together. We can make any nn.Module within some other nn.Module.

The sequential module is the AI model that info or yield groupings of information. Successive information incorporates text transfers, sound bites, video cuts, time-series information, and so on Intermittent Neural Networks (RNNs) are a famous calculation utilized in grouping models. The Sequential holder is utilized to chain a succession of PyTorch modules, for example, layers of a Neural Network (NN), into a succession (a rundown). The Sequential holder then advances changes to the whole succession of modules without composing extra code. For instance, to be applied on every module in Sequential, and a call to advance will be consequently anchored.
The sequential module is the AI model that informs or yields arrangements of information. Sequential information incorporates text transfers, sound bites, video cuts, time-series information and so forth Intermittent Neural Networks (RNNs) are a famous calculation utilized in succession models.

Creating the sequential network

Now let’s see how we can create the sequential network in PyTorch with an example as follows.

import torch.nn as nn
input_layer = [] input_layer.append(nn.Linear(4, 2))
input_layer.append(nn.Sigmoid())
input_layer.append(nn.Linear(5, 3))
input_layer.append(nn.Sigmoid())
result = nn.Sequential(*input_layer)
print(result)

Explanation

In the above example, we try to implement the PyTorch sequential model, here first we import the torch as shown. After that, we take the input from the different sequential models in a chain manner with the append method and inside the append method, we pass the different arguments as shown. The final output of the above program we illustrated by using the following screenshot as follows.

1

Now let’s see another example as follows.

import torch.nn as nn
input_layer = [] input_layer.append(nn.Linear(6, 1))
input_layer.append(nn.Sigmoid())
input_layer.append(nn.Linear(3, 5))
input_layer.append(nn.Sigmoid())
result = nn.Sequential(*input_layer)
print(result)

Explanation

In the above example, we try to implement the PyTorch sequential model, here first we import the torch as shown. After that, we take the input from the different sequential models in a chain manner with the append method and inside the append method, we pass the different arguments as shown. The final output of the above program we illustrated by using the following screenshot as follows.

2

In the above example, we implement the sequential model in a simple way as shown, but we can also implement this model by using a training dataset as per our requirement.

As per requirement, we can include the loss function into the sequential mode to find out the difference between predicted outcomes and actual outcomes.

Conclusion

We hope from this article you learn more about the PyTorch sequential. From the above article, we have taken in the essential idea of the PyTorch sequential and we also see the representation and example of PyTorch sequential. From this article, we learned how and when we sequential PyTorch.

Recommended Articles

This is a guide to PyTorch sequential. Here we discuss the definition, What is PyTorch sequential, How to use PyTorch sequential, examples. you may also have a look at the following articles to learn more –

  1. Mxnet vs Pytorch
  2. What is PyTorch?
  3. PyTorch vs Keras
  4. PyTorch Versions
Popular Course in this category
Machine Learning Training (20 Courses, 29+ Projects)
  19 Online Courses |  29 Hands-on Projects |  178+ Hours |  Verifiable Certificate of Completion
4.7
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more