Model Pipeline - ONNX export
This pipeline shows how a PyTorch model is trained and then exported to the ONNX format. ONNX allows the model to be used in different environments outside PyTorch.
Jump into concepts and practice - no test required
This pipeline shows how a PyTorch model is trained and then exported to the ONNX format. ONNX allows the model to be used in different environments outside PyTorch.
Loss
0.7 |*
0.6 | *
0.5 | *
0.4 | *
0.3 | *
0.2 | *
0.1 |
+--------
1 2 3 4 5 Epochs| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 0.65 | 0.60 | Loss starts high, accuracy is low but learning begins |
| 2 | 0.48 | 0.75 | Loss decreases, accuracy improves |
| 3 | 0.35 | 0.82 | Model continues to learn, better predictions |
| 4 | 0.28 | 0.87 | Loss decreases steadily, accuracy rises |
| 5 | 0.22 | 0.90 | Training converges with good accuracy |
print(onnx_model.graph.input[0].name) after export?
import torch
import torch.nn as nn
class SimpleModel(nn.Module):
def forward(self, x):
return x * 2
model = SimpleModel()
model.eval()
dummy_input = torch.randn(1, 3)
torch.onnx.export(model, dummy_input, "model.onnx", input_names=["input_tensor"])
import onnx
onnx_model = onnx.load("model.onnx")
print(onnx_model.graph.input[0].name)RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same. What is the best fix?torch.onnx.export to enable this?