LoginSignup
0
0

More than 1 year has passed since last update.

torch.catを代替

機械学習モデルの入力の前処理で二つのtensorを任意の軸に沿って連結することがある。

import torch
a = torch.ones(1,3,512,512)
b = torch.ones(1,1,512,512)
c = torch.cat((a,b),dim=1)
print(c.shape)
# > torch.Size([1, 4, 512, 512])

CoreMLでモデルを使う際にこれをSwiftで代替したい。

MLMultiArrayのconcatenateで可能

CoreMLのMLMultiArrayでconcatenate初期化がある。

let a = try MLMultiArray(shape: [1, 3, 512, 512], dataType: .int32)
let b = try MLMultiArray(shape: [1, 1, 512, 512], dataType: .int32)

let c = MLMultiArray(concatenating: [a, b],
                               axis: 1,
                               dataType: .int32)

print(c.shape)
// > [1,4,512,512]

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

機械学習、ARアプリ(Web/iOS)を作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium
GitHub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0