ONNX'e Dışa Aktarma
Modelinizi farklı çalışma ortamlarında çalıştırın.
ONNX'e Dışa Aktarma, CoddyKit'te ücretsiz bir Deep Learning Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Deep Learning Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Deep Learning Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
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. 🎉
Sıkça Sorulan Sorular
“ONNX'e Dışa Aktarma” dersi ücretsiz mi?
Evet — “ONNX'e Dışa Aktarma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Deep Learning Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Deep Learning Academy kursu toplamda 4 dersten oluşur.
“ONNX'e Dışa Aktarma” dersinde ne öğreneceğim?
Modelinizi farklı çalışma ortamlarında çalıştırın. Deep Learning Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Deep Learning Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Deep Learning Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.
“ONNX'e Dışa Aktarma” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Deep Learning Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Deep Learning Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- TorchScript ve torch.compile
- ONNX'e Dışa Aktarma
- Daha Küçük ve Hızlı Modeller için Nicemleme
- FastAPI ile Sunma