ホーム › AI.MachineLearning.DirectML › DML_ROI_POOLING_OPERATOR_DESC
DML_ROI_POOLING_OPERATOR_DESC
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| InputTensor | DML_TENSOR_DESC* | 8/4 | +0 | +0 | { BatchCount, ChannelCount, InputHeight, InputWidth } の次元を持つ入力データを格納するテンソルです。 |
| ROITensor | DML_TENSOR_DESC* | 8/4 | +8 | +4 | 関心領域 (ROI) のデータを格納するテンソルです。ROITensor に想定される次元は { 1, 1, NumROIs, 5 } で、各 ROI のデータは [BatchID, x1, y1, x2, y2] です。x1、y1、x2、y2 は各 ROI の角の座標 (両端を含む) であり、x2 >= x1、y2 >= y1 でなければなりません。 |
| OutputTensor | DML_TENSOR_DESC* | 8/4 | +16 | +8 | 出力データを格納するテンソルです。OutputTensor に想定される次元は { NumROIs, InputChannelCount, PooledSize.Height, PooledSize.Width } です。 |
| SpatialScale | FLOAT | 4 | +24 | +12 | ROI の座標を入力のスケールからプーリング時に使用されるスケールへ変換するために使用する、乗算的な空間スケール係数です。 |
| PooledSize | DML_SIZE_2D | 8 | +28 | +16 | ROI プールの出力サイズ (高さ、幅) です。OutputTensor の最後の 2 つの次元と一致していなければなりません。 |
公式ドキュメント
関心領域 (ROI) に従って、入力テンソル全体に MaxPool 関数を適用します。各出力要素について、入力内の対応する ROI の座標は次の式で計算されます。
Y を InputTensor ({ BatchSize, ChannelCount, **height**, width }) の 3 番目の次元へのインデックスとします。
X を InputTensor ({ BatchSize, ChannelCount, height, **width** }) の 4 番目の次元へのインデックスとします。
x1 = round(RoiX1 * SpatialScale)
x2 = round(RoiX2 * SpatialScale)
y1 = round(RoiY1 * SpatialScale)
y2 = round(RoiY2 * SpatialScale)
RegionHeight = y2 - y1 + 1
RegionWidth = x2 - x1 + 1
StartY = (OutputIndices.Y * RegionHeight) / PooledSize.Height + y1
StartX = (OutputIndices.X * RegionWidth) / PooledSize.Width + x1
EndY = ((OutputIndices.Y + 1) * RegionHeight + PooledSize.Height - 1) / PooledSize.Height + y1
EndX = ((OutputIndices.X + 1) * RegionWidth + PooledSize.Width - 1) / PooledSize.Width + x1
計算された座標が範囲外になる場合は、入力の境界にクランプされます。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// DML_SIZE_2D (x64 8 / x86 8 バイト)
typedef struct DML_SIZE_2D {
DWORD Width;
DWORD Height;
} DML_SIZE_2D;
// DML_ROI_POOLING_OPERATOR_DESC (x64 40 / x86 24 バイト)
typedef struct DML_ROI_POOLING_OPERATOR_DESC {
DML_TENSOR_DESC* InputTensor;
DML_TENSOR_DESC* ROITensor;
DML_TENSOR_DESC* OutputTensor;
FLOAT SpatialScale;
DML_SIZE_2D PooledSize;
} DML_ROI_POOLING_OPERATOR_DESC;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DML_SIZE_2D
{
public uint Width;
public uint Height;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DML_ROI_POOLING_OPERATOR_DESC
{
public IntPtr InputTensor;
public IntPtr ROITensor;
public IntPtr OutputTensor;
public float SpatialScale;
public DML_SIZE_2D PooledSize;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DML_SIZE_2D
Public Width As UInteger
Public Height As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DML_ROI_POOLING_OPERATOR_DESC
Public InputTensor As IntPtr
Public ROITensor As IntPtr
Public OutputTensor As IntPtr
Public SpatialScale As Single
Public PooledSize As DML_SIZE_2D
End Structureimport ctypes
from ctypes import wintypes
class DML_SIZE_2D(ctypes.Structure):
_fields_ = [
("Width", wintypes.DWORD),
("Height", wintypes.DWORD),
]
class DML_ROI_POOLING_OPERATOR_DESC(ctypes.Structure):
_fields_ = [
("InputTensor", ctypes.c_void_p),
("ROITensor", ctypes.c_void_p),
("OutputTensor", ctypes.c_void_p),
("SpatialScale", ctypes.c_float),
("PooledSize", DML_SIZE_2D),
]#[repr(C)]
pub struct DML_SIZE_2D {
pub Width: u32,
pub Height: u32,
}
#[repr(C)]
pub struct DML_ROI_POOLING_OPERATOR_DESC {
pub InputTensor: *mut core::ffi::c_void,
pub ROITensor: *mut core::ffi::c_void,
pub OutputTensor: *mut core::ffi::c_void,
pub SpatialScale: f32,
pub PooledSize: DML_SIZE_2D,
}import "golang.org/x/sys/windows"
type DML_SIZE_2D struct {
Width uint32
Height uint32
}
type DML_ROI_POOLING_OPERATOR_DESC struct {
InputTensor uintptr
ROITensor uintptr
OutputTensor uintptr
SpatialScale float32
PooledSize DML_SIZE_2D
}type
DML_SIZE_2D = record
Width: DWORD;
Height: DWORD;
end;
DML_ROI_POOLING_OPERATOR_DESC = record
InputTensor: Pointer;
ROITensor: Pointer;
OutputTensor: Pointer;
SpatialScale: Single;
PooledSize: DML_SIZE_2D;
end;const DML_SIZE_2D = extern struct {
Width: u32,
Height: u32,
};
const DML_ROI_POOLING_OPERATOR_DESC = extern struct {
InputTensor: ?*anyopaque,
ROITensor: ?*anyopaque,
OutputTensor: ?*anyopaque,
SpatialScale: f32,
PooledSize: DML_SIZE_2D,
};type
DML_SIZE_2D {.bycopy.} = object
Width: uint32
Height: uint32
DML_ROI_POOLING_OPERATOR_DESC {.bycopy.} = object
InputTensor: pointer
ROITensor: pointer
OutputTensor: pointer
SpatialScale: float32
PooledSize: DML_SIZE_2Dstruct DML_SIZE_2D
{
uint Width;
uint Height;
}
struct DML_ROI_POOLING_OPERATOR_DESC
{
void* InputTensor;
void* ROITensor;
void* OutputTensor;
float SpatialScale;
DML_SIZE_2D PooledSize;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; DML_ROI_POOLING_OPERATOR_DESC サイズ: 24 バイト(x86)
dim st, 6 ; 4byte整数×6(構造体サイズ 24 / 4 切り上げ)
; InputTensor : DML_TENSOR_DESC* (+0, 4byte) varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; ROITensor : DML_TENSOR_DESC* (+4, 4byte) varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+8, 4byte) varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; SpatialScale : FLOAT (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; PooledSize : DML_SIZE_2D (+16, 8byte) varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DML_ROI_POOLING_OPERATOR_DESC サイズ: 40 バイト(x64)
dim st, 10 ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; InputTensor : DML_TENSOR_DESC* (+0, 8byte) varptr(st)+0 を基点に操作(8byte:入れ子/配列)
; ROITensor : DML_TENSOR_DESC* (+8, 8byte) varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+16, 8byte) varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; SpatialScale : FLOAT (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; PooledSize : DML_SIZE_2D (+28, 8byte) varptr(st)+28 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global DML_SIZE_2D
#field int Width
#field int Height
#endstruct
#defstruct global DML_ROI_POOLING_OPERATOR_DESC
#field intptr InputTensor
#field intptr ROITensor
#field intptr OutputTensor
#field float SpatialScale
#field DML_SIZE_2D PooledSize
#endstruct
stdim st, DML_ROI_POOLING_OPERATOR_DESC ; NSTRUCT 変数を確保
st->SpatialScale = 100
mes "SpatialScale=" + st->SpatialScale