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

DML_RESAMPLE1_OPERATOR_DESC

構造体
サイズx64: 48 バイト / x86: 28 バイト

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

フィールド

フィールドサイズx64x86説明
InputTensorDML_TENSOR_DESC*8/4+0+0入力データを格納するテンソルです。
OutputTensorDML_TENSOR_DESC*8/4+8+4出力データの書き込み先となるテンソルです。
InterpolationModeDML_INTERPOLATION_MODE4+16+8

このフィールドは、出力ピクセルを選択するために使用される補間の種類を決定します。

  • DML_INTERPOLATION_MODE_NEAREST_NEIGHBOR最近傍 アルゴリズムを使用します。このアルゴリズムは、各出力要素について、対応するピクセル中心に最も近い入力要素を選択します。

  • DML_INTERPOLATION_MODE_LINEAR線形補間 アルゴリズムを使用します。このアルゴリズムは、次元ごとに最も近い 2 つの隣接入力要素の加重平均を計算して出力要素を求めます。リサンプリングは 4 次元 (四重線形) までサポートされ、その場合は各出力要素について合計 16 個の入力要素の加重平均が計算されます。

DimensionCountDWORD4+20+12ScalesInputPixelOffsetsOutputPixelOffsets が指す配列内の値の数です。この値は InputTensor および OutputTensor の次元数と一致していなければなりません。
ScalesFLOAT*8/4+24+16入力をリサンプリングするときに適用するスケールです。スケールが 1 より大きい場合はその次元で画像を拡大し、1 より小さい場合は縮小します。スケールは厳密に OutputSize / InputSize である必要はない点に注意してください。スケーリング後の入力が出力の範囲より大きい場合は、出力サイズに合わせて切り取られます。一方、スケーリング後の入力が出力の範囲より小さい場合は、出力の端がクランプされます。
InputPixelOffsetsFLOAT*8/4+32+20リサンプリングの前に入力ピクセルへ適用するオフセットです。この値が 0 の場合、ピクセルの中心ではなく左上隅が使用されるため、通常は期待どおりの結果になりません。ピクセルの中心を使用して画像をリサンプリングし、DML_RESAMPLE_OPERATOR_DESC と同じ動作にするには、この値は 0.5 でなければなりません。
OutputPixelOffsetsFLOAT*8/4+40+24リサンプリングの後に出力ピクセルへ適用するオフセットです。この値が 0 の場合、ピクセルの中心ではなく左上隅が使用されるため、通常は期待どおりの結果になりません。ピクセルの中心を使用して画像をリサンプリングし、DML_RESAMPLE_OPERATOR_DESC と同じ動作にするには、この値は -0.5 でなければなりません。

公式ドキュメント

スケール係数を使用して出力先テンソルのサイズを計算しながら、ソースから出力先テンソルへ要素をリサンプリングします。線形補間モードまたは最近傍補間モードを使用できます。この演算子は 2D だけでなく、複数の次元にわたる補間をサポートします。そのため、空間サイズを同じに保ったまま、チャネル間やバッチ間で補間することもできます。入力座標と出力座標の関係は次のとおりです。

OutputTensorX = (InputTensorX + InputPixelOffset) * Scale + OutputPixelOffset

解説(Remarks)

InputPixelOffsets が 0.5 に、OutputPixelOffsets が -0.5 に設定されている場合、この演算子は DML_RESAMPLE_OPERATOR_DESC と等価です。

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

各言語での定義

#include <windows.h>

// DML_RESAMPLE1_OPERATOR_DESC  (x64 48 / x86 28 バイト)
typedef struct DML_RESAMPLE1_OPERATOR_DESC {
    DML_TENSOR_DESC* InputTensor;
    DML_TENSOR_DESC* OutputTensor;
    DML_INTERPOLATION_MODE InterpolationMode;
    DWORD DimensionCount;
    FLOAT* Scales;
    FLOAT* InputPixelOffsets;
    FLOAT* OutputPixelOffsets;
} DML_RESAMPLE1_OPERATOR_DESC;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DML_RESAMPLE1_OPERATOR_DESC
{
    public IntPtr InputTensor;
    public IntPtr OutputTensor;
    public int InterpolationMode;
    public uint DimensionCount;
    public IntPtr Scales;
    public IntPtr InputPixelOffsets;
    public IntPtr OutputPixelOffsets;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DML_RESAMPLE1_OPERATOR_DESC
    Public InputTensor As IntPtr
    Public OutputTensor As IntPtr
    Public InterpolationMode As Integer
    Public DimensionCount As UInteger
    Public Scales As IntPtr
    Public InputPixelOffsets As IntPtr
    Public OutputPixelOffsets As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class DML_RESAMPLE1_OPERATOR_DESC(ctypes.Structure):
    _fields_ = [
        ("InputTensor", ctypes.c_void_p),
        ("OutputTensor", ctypes.c_void_p),
        ("InterpolationMode", ctypes.c_int),
        ("DimensionCount", wintypes.DWORD),
        ("Scales", ctypes.c_void_p),
        ("InputPixelOffsets", ctypes.c_void_p),
        ("OutputPixelOffsets", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct DML_RESAMPLE1_OPERATOR_DESC {
    pub InputTensor: *mut core::ffi::c_void,
    pub OutputTensor: *mut core::ffi::c_void,
    pub InterpolationMode: i32,
    pub DimensionCount: u32,
    pub Scales: *mut core::ffi::c_void,
    pub InputPixelOffsets: *mut core::ffi::c_void,
    pub OutputPixelOffsets: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type DML_RESAMPLE1_OPERATOR_DESC struct {
	InputTensor uintptr
	OutputTensor uintptr
	InterpolationMode int32
	DimensionCount uint32
	Scales uintptr
	InputPixelOffsets uintptr
	OutputPixelOffsets uintptr
}
type
  DML_RESAMPLE1_OPERATOR_DESC = record
    InputTensor: Pointer;
    OutputTensor: Pointer;
    InterpolationMode: Integer;
    DimensionCount: DWORD;
    Scales: Pointer;
    InputPixelOffsets: Pointer;
    OutputPixelOffsets: Pointer;
  end;
const DML_RESAMPLE1_OPERATOR_DESC = extern struct {
    InputTensor: ?*anyopaque,
    OutputTensor: ?*anyopaque,
    InterpolationMode: i32,
    DimensionCount: u32,
    Scales: ?*anyopaque,
    InputPixelOffsets: ?*anyopaque,
    OutputPixelOffsets: ?*anyopaque,
};
type
  DML_RESAMPLE1_OPERATOR_DESC {.bycopy.} = object
    InputTensor: pointer
    OutputTensor: pointer
    InterpolationMode: int32
    DimensionCount: uint32
    Scales: pointer
    InputPixelOffsets: pointer
    OutputPixelOffsets: pointer
struct DML_RESAMPLE1_OPERATOR_DESC
{
    void* InputTensor;
    void* OutputTensor;
    int InterpolationMode;
    uint DimensionCount;
    void* Scales;
    void* InputPixelOffsets;
    void* OutputPixelOffsets;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; DML_RESAMPLE1_OPERATOR_DESC サイズ: 28 バイト(x86)
dim st, 7    ; 4byte整数×7(構造体サイズ 28 / 4 切り上げ)
; InputTensor : DML_TENSOR_DESC* (+0, 4byte)  varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+4, 4byte)  varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; InterpolationMode : DML_INTERPOLATION_MODE (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; DimensionCount : DWORD (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; Scales : FLOAT* (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; InputPixelOffsets : FLOAT* (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; OutputPixelOffsets : FLOAT* (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DML_RESAMPLE1_OPERATOR_DESC サイズ: 48 バイト(x64)
dim st, 12    ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; InputTensor : DML_TENSOR_DESC* (+0, 8byte)  varptr(st)+0 を基点に操作(8byte:入れ子/配列)
; OutputTensor : DML_TENSOR_DESC* (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; InterpolationMode : DML_INTERPOLATION_MODE (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; DimensionCount : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; Scales : FLOAT* (+24, 8byte)  qpoke st,24,値 / qpeek(st,24)  ※IronHSPのみ。3.7/3.8は lpoke st,24,下位 : lpoke st,28,上位
; InputPixelOffsets : FLOAT* (+32, 8byte)  qpoke st,32,値 / qpeek(st,32)  ※IronHSPのみ。3.7/3.8は lpoke st,32,下位 : lpoke st,36,上位
; OutputPixelOffsets : FLOAT* (+40, 8byte)  qpoke st,40,値 / qpeek(st,40)  ※IronHSPのみ。3.7/3.8は lpoke st,40,下位 : lpoke st,44,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global DML_RESAMPLE1_OPERATOR_DESC
    #field intptr InputTensor
    #field intptr OutputTensor
    #field int InterpolationMode
    #field int DimensionCount
    #field intptr Scales
    #field intptr InputPixelOffsets
    #field intptr OutputPixelOffsets
#endstruct

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