0Pricing
Deep Learning Academy · Lektion

Nach ONNX exportieren

Führen Sie Ihr Modell in verschiedenen Runtimes aus.

Nach ONNX exportieren ist eine kostenlose Deep Learning Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Deep Learning Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

One Model, Many Runtimes

Sometimes your model must run somewhere PyTorch is not installed. ONNX is a shared format that lets one model run across many engines. 🌐

What ONNX Stands For

ONNX means Open Neural Network Exchange. It is a vendor-neutral file format that describes your model as a graph of standard operations.

Why Teams Love ONNX

With ONNX you train in PyTorch but deploy on ONNX Runtime, mobile, or the browser, without rewriting the model for each platform.

Export in One Call

You export by giving PyTorch the model and a sample input. The exporter traces the run and writes a portable graph to disk.

import torch
torch.onnx.export(model, sample_input, 'model.onnx')

The Dummy Input Shapes the Graph

That sample tensor must match your real input shape and dtype, because the exporter records the operations the data triggers.

sample_input = torch.randn(1, 3, 224, 224)

Name Your Inputs and Outputs

Give clear input and output names so the serving code can bind data by name instead of guessing positions.

torch.onnx.export(model, x, 'm.onnx',
  input_names=['image'], output_names=['logits'])

Allow Flexible Batch Sizes

By default the batch size is fixed. Mark it as a dynamic axis so the exported model accepts any number of inputs at once.

dynamic_axes={'image': {0: 'batch'}}

Always Check Your Export

Load the file with the onnx library and run the built-in checker to confirm the graph is valid before you ship it. ✅

import onnx
onnx.checker.check_model(onnx.load('model.onnx'))

Run It with ONNX Runtime

ONNX Runtime is a fast engine that executes the exported model on CPU or GPU, often quicker than plain Python inference.

import onnxruntime as ort
session = ort.InferenceSession('model.onnx')

Confirm the Numbers Match

Run the same input through PyTorch and ONNX Runtime and compare outputs. They should match closely, proving the export is faithful.

Mind the Opset Version

Each export targets an opset version, the set of supported operations. Pick a version your target runtime understands to avoid errors.

torch.onnx.export(model, x, 'm.onnx', opset_version=17)

Quick Check

You want a fixed batch to instead accept any size. What do you set?

Recap: Portable Across Runtimes

You exported a PyTorch model to ONNX with a sample input, named axes, validated it, and ran it on ONNX Runtime anywhere. 🎉

Häufig gestellte Fragen

Ist die Lektion „Nach ONNX exportieren“ kostenlos?

Ja — der vollständige Text von „Nach ONNX exportieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Deep Learning Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Nach ONNX exportieren“?

Führen Sie Ihr Modell in verschiedenen Runtimes aus. Du übst Deep Learning Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Deep Learning Academy zu starten?

Keine Vorkenntnisse erforderlich. Deep Learning Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Nach ONNX exportieren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Deep Learning Academy-Lektion Code schreiben und ausführen?

Ja. Jede Deep Learning Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. TorchScript und torch.compile
  2. Nach ONNX exportieren
  3. Quantisierung für kleinere, schnellere Modelle
  4. Mit FastAPI bereitstellen
← Zurück zu Deep Learning Academy