Win32 API 日本語リファレンス
ホームAI.MachineLearning.DirectML › DML_ROI_ALIGN_OPERATOR_DESC

DML_ROI_ALIGN_OPERATOR_DESC

構造体
サイズx64: 64 バイト / x86: 44 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
InputTensorDML_TENSOR_DESC*8/4+0+0{ BatchCount, ChannelCount, InputHeight, InputWidth } の次元を持つ入力データを格納したテンソルです。
ROITensorDML_TENSOR_DESC*8/4+8+4関心領域 (ROI) のデータを格納したテンソルです。ROITensor に指定できる次元は { NumROIs, 4 }{ 1, NumROIs, 4 }{ 1, 1, NumROIs, 4 } です。各 ROI について、値はその左上隅と右下隅の座標を [x1, y1, x2, y2] の順で表します。
BatchIndicesTensorDML_TENSOR_DESC*8/4+16+8ROI の抽出元となるバッチインデックスを格納したテンソルです。BatchIndicesTensor に指定できる次元は { NumROIs }{ 1, NumROIs }{ 1, 1, NumROIs }{ 1, 1, 1, NumROIs } です。各値は InputTensor のバッチのインデックスです。値が [0, BatchCount) の範囲にない場合の動作は未定義です。
OutputTensorDML_TENSOR_DESC*8/4+24+12出力データを格納したテンソルです。OutputTensor に期待される次元は { NumROIs, ChannelCount, OutputHeight, OutputWidth } です。
ReductionFunctionDML_REDUCE_FUNCTION4+32+161 つの出力要素に寄与するすべての入力サンプルにわたって縮約を行う際に使用する縮約関数です (DML_REDUCE_FUNCTION_AVERAGE または DML_REDUCE_FUNCTION_MAX)。縮約の対象となる入力サンプルの数は、MinimumSamplesPerOutputMaximumSamplesPerOutput によって制限されます。
InterpolationModeDML_INTERPOLATION_MODE4+36+20

領域をリサイズする際に使用する補間モードです。

  • DML_INTERPOLATION_MODE_NEAREST_NEIGHBOR最近傍 (Nearest Neighbor) アルゴリズムを使用します。これは、各出力要素について、対応するピクセル中心に最も近い入力要素を選択します。
  • DML_INTERPOLATION_MODE_LINEARバイリニア (Bilinear) アルゴリズムを使用します。これは、次元ごとに最も近い 2 つの隣接入力要素の加重平均を計算して出力要素を求めます。リサイズされる次元は 2 つだけであるため、加重平均は各出力要素につき合計 4 つの入力要素に対して計算されます。
SpatialScaleXFLOAT4+40+24ROITensor の座標を InputHeight および InputWidth に比例させるために乗算するスケーリング係数の X (幅) 成分です。たとえば、ROITensor が正規化された座標 ([0..1] の範囲の値) を格納している場合、SpatialScaleX は通常 InputWidth と同じ値になります。
SpatialScaleYFLOAT4+44+28ROITensor の座標を InputHeight および InputWidth に比例させるために乗算するスケーリング係数の Y (高さ) 成分です。たとえば、ROITensor が正規化された座標 ([0..1] の範囲の値) を格納している場合、SpatialScaleY は通常 InputHeight と同じ値になります。
OutOfBoundsInputValueFLOAT4+48+32ROI が InputTensor の境界の外にある場合に InputTensor から読み取る値です。これは、ROITensorSpatialScaleX および SpatialScaleY でスケーリングして得られた値が InputWidth および InputHeight より大きい場合に発生することがあります。
MinimumSamplesPerOutputDWORD4+52+36各出力要素に使用する入力サンプルの最小数です。演算子は ScaledCropSize / OutputSize によって入力サンプル数を計算し、その値を MinimumSamplesPerOutputMaximumSamplesPerOutput の範囲にクランプします。
MaximumSamplesPerOutputDWORD4+56+40各出力要素に使用する入力サンプルの最大数です。演算子は ScaledCropSize / OutputSize によって入力サンプル数を計算し、その値を MinimumSamplesPerOutputMaximumSamplesPerOutput の範囲にクランプします。

公式ドキュメント

Mask R-CNN 論文で説明されている ROI align 操作を実行します。要約すると、この操作は入力画像テンソルから切り抜きを抽出し、指定された InterpolationMode を使用して、OutputTensor の末尾 2 次元で指定される共通の出力サイズにリサイズします。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// DML_ROI_ALIGN_OPERATOR_DESC  (x64 64 / x86 44 バイト)
typedef struct DML_ROI_ALIGN_OPERATOR_DESC {
    DML_TENSOR_DESC* InputTensor;
    DML_TENSOR_DESC* ROITensor;
    DML_TENSOR_DESC* BatchIndicesTensor;
    DML_TENSOR_DESC* OutputTensor;
    DML_REDUCE_FUNCTION ReductionFunction;
    DML_INTERPOLATION_MODE InterpolationMode;
    FLOAT SpatialScaleX;
    FLOAT SpatialScaleY;
    FLOAT OutOfBoundsInputValue;
    DWORD MinimumSamplesPerOutput;
    DWORD MaximumSamplesPerOutput;
} DML_ROI_ALIGN_OPERATOR_DESC;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DML_ROI_ALIGN_OPERATOR_DESC
{
    public IntPtr InputTensor;
    public IntPtr ROITensor;
    public IntPtr BatchIndicesTensor;
    public IntPtr OutputTensor;
    public int ReductionFunction;
    public int InterpolationMode;
    public float SpatialScaleX;
    public float SpatialScaleY;
    public float OutOfBoundsInputValue;
    public uint MinimumSamplesPerOutput;
    public uint MaximumSamplesPerOutput;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DML_ROI_ALIGN_OPERATOR_DESC
    Public InputTensor As IntPtr
    Public ROITensor As IntPtr
    Public BatchIndicesTensor As IntPtr
    Public OutputTensor As IntPtr
    Public ReductionFunction As Integer
    Public InterpolationMode As Integer
    Public SpatialScaleX As Single
    Public SpatialScaleY As Single
    Public OutOfBoundsInputValue As Single
    Public MinimumSamplesPerOutput As UInteger
    Public MaximumSamplesPerOutput As UInteger
End Structure
import ctypes
from ctypes import wintypes

class DML_ROI_ALIGN_OPERATOR_DESC(ctypes.Structure):
    _fields_ = [
        ("InputTensor", ctypes.c_void_p),
        ("ROITensor", ctypes.c_void_p),
        ("BatchIndicesTensor", ctypes.c_void_p),
        ("OutputTensor", ctypes.c_void_p),
        ("ReductionFunction", ctypes.c_int),
        ("InterpolationMode", ctypes.c_int),
        ("SpatialScaleX", ctypes.c_float),
        ("SpatialScaleY", ctypes.c_float),
        ("OutOfBoundsInputValue", ctypes.c_float),
        ("MinimumSamplesPerOutput", wintypes.DWORD),
        ("MaximumSamplesPerOutput", wintypes.DWORD),
    ]
#[repr(C)]
pub struct DML_ROI_ALIGN_OPERATOR_DESC {
    pub InputTensor: *mut core::ffi::c_void,
    pub ROITensor: *mut core::ffi::c_void,
    pub BatchIndicesTensor: *mut core::ffi::c_void,
    pub OutputTensor: *mut core::ffi::c_void,
    pub ReductionFunction: i32,
    pub InterpolationMode: i32,
    pub SpatialScaleX: f32,
    pub SpatialScaleY: f32,
    pub OutOfBoundsInputValue: f32,
    pub MinimumSamplesPerOutput: u32,
    pub MaximumSamplesPerOutput: u32,
}
import "golang.org/x/sys/windows"

type DML_ROI_ALIGN_OPERATOR_DESC struct {
	InputTensor uintptr
	ROITensor uintptr
	BatchIndicesTensor uintptr
	OutputTensor uintptr
	ReductionFunction int32
	InterpolationMode int32
	SpatialScaleX float32
	SpatialScaleY float32
	OutOfBoundsInputValue float32
	MinimumSamplesPerOutput uint32
	MaximumSamplesPerOutput uint32
}
type
  DML_ROI_ALIGN_OPERATOR_DESC = record
    InputTensor: Pointer;
    ROITensor: Pointer;
    BatchIndicesTensor: Pointer;
    OutputTensor: Pointer;
    ReductionFunction: Integer;
    InterpolationMode: Integer;
    SpatialScaleX: Single;
    SpatialScaleY: Single;
    OutOfBoundsInputValue: Single;
    MinimumSamplesPerOutput: DWORD;
    MaximumSamplesPerOutput: DWORD;
  end;
const DML_ROI_ALIGN_OPERATOR_DESC = extern struct {
    InputTensor: ?*anyopaque,
    ROITensor: ?*anyopaque,
    BatchIndicesTensor: ?*anyopaque,
    OutputTensor: ?*anyopaque,
    ReductionFunction: i32,
    InterpolationMode: i32,
    SpatialScaleX: f32,
    SpatialScaleY: f32,
    OutOfBoundsInputValue: f32,
    MinimumSamplesPerOutput: u32,
    MaximumSamplesPerOutput: u32,
};
type
  DML_ROI_ALIGN_OPERATOR_DESC {.bycopy.} = object
    InputTensor: pointer
    ROITensor: pointer
    BatchIndicesTensor: pointer
    OutputTensor: pointer
    ReductionFunction: int32
    InterpolationMode: int32
    SpatialScaleX: float32
    SpatialScaleY: float32
    OutOfBoundsInputValue: float32
    MinimumSamplesPerOutput: uint32
    MaximumSamplesPerOutput: uint32
struct DML_ROI_ALIGN_OPERATOR_DESC
{
    void* InputTensor;
    void* ROITensor;
    void* BatchIndicesTensor;
    void* OutputTensor;
    int ReductionFunction;
    int InterpolationMode;
    float SpatialScaleX;
    float SpatialScaleY;
    float OutOfBoundsInputValue;
    uint MinimumSamplesPerOutput;
    uint MaximumSamplesPerOutput;
}

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_ALIGN_OPERATOR_DESC サイズ: 44 バイト(x86)
dim st, 11    ; 4byte整数×11(構造体サイズ 44 / 4 切り上げ)
; InputTensor : DML_TENSOR_DESC* (+0, 4byte)  varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; ROITensor : DML_TENSOR_DESC* (+4, 4byte)  varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; BatchIndicesTensor : DML_TENSOR_DESC* (+8, 4byte)  varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+12, 4byte)  varptr(st)+12 を基点に操作(4byte:入れ子/配列)
; ReductionFunction : DML_REDUCE_FUNCTION (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; InterpolationMode : DML_INTERPOLATION_MODE (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; SpatialScaleX : FLOAT (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; SpatialScaleY : FLOAT (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; OutOfBoundsInputValue : FLOAT (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; MinimumSamplesPerOutput : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; MaximumSamplesPerOutput : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DML_ROI_ALIGN_OPERATOR_DESC サイズ: 64 バイト(x64)
dim st, 16    ; 4byte整数×16(構造体サイズ 64 / 4 切り上げ)
; InputTensor : DML_TENSOR_DESC* (+0, 8byte)  varptr(st)+0 を基点に操作(8byte:入れ子/配列)
; ROITensor : DML_TENSOR_DESC* (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; BatchIndicesTensor : DML_TENSOR_DESC* (+16, 8byte)  varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+24, 8byte)  varptr(st)+24 を基点に操作(8byte:入れ子/配列)
; ReductionFunction : DML_REDUCE_FUNCTION (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; InterpolationMode : DML_INTERPOLATION_MODE (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; SpatialScaleX : FLOAT (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; SpatialScaleY : FLOAT (+44, 4byte)  st.11 = 値  /  値 = st.11   (lpoke/lpeek も可)
; OutOfBoundsInputValue : FLOAT (+48, 4byte)  st.12 = 値  /  値 = st.12   (lpoke/lpeek も可)
; MinimumSamplesPerOutput : DWORD (+52, 4byte)  st.13 = 値  /  値 = st.13   (lpoke/lpeek も可)
; MaximumSamplesPerOutput : DWORD (+56, 4byte)  st.14 = 値  /  値 = st.14   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global DML_ROI_ALIGN_OPERATOR_DESC
    #field intptr InputTensor
    #field intptr ROITensor
    #field intptr BatchIndicesTensor
    #field intptr OutputTensor
    #field int ReductionFunction
    #field int InterpolationMode
    #field float SpatialScaleX
    #field float SpatialScaleY
    #field float OutOfBoundsInputValue
    #field int MinimumSamplesPerOutput
    #field int MaximumSamplesPerOutput
#endstruct

stdim st, DML_ROI_ALIGN_OPERATOR_DESC        ; NSTRUCT 変数を確保
st->ReductionFunction = 100
mes "ReductionFunction=" + st->ReductionFunction