Upgrade to Pro — share decks privately, control downloads, hide ads and more …

関モバ_20261009.pdf

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for こむぎ こむぎ
October 13, 2026
5

 関モバ_20261009.pdf

Avatar for こむぎ

こむぎ

October 13, 2026

Transcript

  1. iOSで画像生成 有料のAPI Image Playground Core ML Core AI • 高品質

    • 無料 • 無料かつカスタム可 • 無料かつカスタム可 • 高価格 • スタイルが限定 • モデルの性能が低い • モデルの性能が高い 6
  2. 8

  3. 最適化(Python) import torch import torch.nn as nn from torch.export import

    export class OptimizedCoreAIModel(nn.Module): def __init__(self): super().__init__() # ANEのfp16計算誤差を防ぐため、nn.Linearの代わりに1x1 Conv2dを使用 self.conv1x1 = nn.Conv2d(in_channels=256, out_channels=512, kernel_size=1) def forward(self, x): # [B, C, H, W]の形状で処理 return self.conv1x1(x) model = OptimizedCoreAIModel() example_input = torch.randn(1, 256, 1, 1) # Core AIの入り口となるPyTorch標準のエクスポート exported_program = export(model, (example_input,)) 17
  4. モデル読み込み(Swift) import CoreAI func runCoreAIModel() async { do { //

    1. モデル構成の設定 let config = AIModelConfiguration() // 2. 非同期ロード(AOTコンパイル済みなら即時に完了) let model = try await AIModel.load(contentsOf: modelURL, configuration: config) // 3. 入力データの作成(Core AI特有のNDArrayを使用) let inputNDArray = NDArray(myInputData) // 4. 非同期での推論実行 let output = try await model.prediction(from: inputNDArray) print("推論完了: \(output)") } catch { print("Core AI ロードエラー: \(error)") } } 19