Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 29, 2022 04:52 pm GMT

Convert my Pytorch model to Pytorch Lightning

Hello, everybody! Today I am going to show how you how to convert my model from Pytorch to Pytorch Lightning. Pytorch Lightning is a light-weight deep learning framework built upon Pytorch. It removes a lot of boilerplate code (standard code that can be found in almost any deep learning pipeline) and adds in many functions that helps to interfere training at a specific position.

Firstly, I import the libraries.

pip install pytorch-lightningimport pytorch_lightning as pl

Pytorch LightningModule resembles nn.Module. Forward function can be defined in a pl class.

# an nn class can be converted to a pl class by replacing nn with plclass NeuralNet(nn.Module): # --> class NeuralNet(pl.LightningModule):    def __init__(self, input_size, num_classes):        super(NeuralNet, self).__init__()        self.fc1 = nn.Linear(input_size, 50)        self.fc2 = nn.Linear(50, num_classes)# --> specific functions belong to nn class should not be changed!    def forward(self, x):        out = self.fc1(x)        out = torch.sigmoid(out)        out = self.fc2(out)        return out

Read more here.


Original Link: https://dev.to/qbaocaca/convert-my-pytorch-model-to-pytorch-lightning-8ha

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To