Read PT File
Last modified: Sun Mar 26 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
Machine Learning
A PT file is a machine learning model file generated by PyTorch.
Load Model from PT
import torch
import torch.nn as nn
class ExampleModel(nn.Module):
def __init__(self):
super().__init__()
self.flatten = nn.Flatten()
self.linear_relu_stack = nn.Sequential(
nn.Linear(28*28, 512),
nn.ReLU(),
nn.Linear(512, 10))
def forward(self, x):
x = self.flatten(x)
logits = self.linear_relu_stack(x)
return logits
model = ExampleModel()
model.load_state_dict(torch.load('example.pt'))
print(model)