resample2d.https.any.js (19178B)
1 // META: title=test WebNN API resample2d operation 2 // META: global=window 3 // META: variant=?cpu 4 // META: variant=?gpu 5 // META: variant=?npu 6 // META: script=../resources/utils.js 7 // META: timeout=long 8 9 'use strict'; 10 11 // https://www.w3.org/TR/webnn/#api-mlgraphbuilder-resample2d-method 12 // Resample the tensor values from the source to the destination spatial 13 // dimensions according to the scaling factors. 14 // 15 // enum MLInterpolationMode { 16 // "nearest-neighbor", 17 // "linear" 18 // }; 19 // 20 // dictionary MLResample2dOptions { 21 // MLInterpolationMode mode = "nearest-neighbor"; 22 // sequence<float> scales; 23 // sequence<[EnforceRange] unsigned long> sizes; 24 // sequence<[EnforceRange] unsigned long> axes; 25 // }; 26 // 27 // MLOperand resample2d( 28 // MLOperand input, optional MLResample2dOptions options = {}); 29 30 const resample2dTests = [ 31 { 32 'name': 'resample2d float32 4D tensor default options', 33 'graph': { 34 'inputs': { 35 'resample2dInput': { 36 'data': [ 37 3.8600528240203857, 45.18463134765625, 87.67153930664062, 38 98.7821044921875, 66.3741455078125, 3.411583423614502, 39 86.14930725097656, 95.98133850097656, 76.87126159667969, 40 16.52591323852539, 65.98783111572266, 25.470922470092773, 41 22.56010627746582, 92.08479309082031, 85.80876922607422, 42 92.63166046142578, 29.916208267211914, 75.40460968017578, 43 62.06375503540039, 1.7712159156799316, 99.4723129272461, 44 11.440549850463867, 25.396343231201172, 67.0217514038086 45 ], 46 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 47 } 48 }, 49 'operators': [{ 50 'name': 'resample2d', 51 'arguments': [{'input': 'resample2dInput'}], 52 'outputs': 'resample2dOutput' 53 }], 54 'expectedOutputs': { 55 'resample2dOutput': { 56 'data': [ 57 3.8600528240203857, 45.18463134765625, 87.67153930664062, 58 98.7821044921875, 66.3741455078125, 3.411583423614502, 59 86.14930725097656, 95.98133850097656, 76.87126159667969, 60 16.52591323852539, 65.98783111572266, 25.470922470092773, 61 22.56010627746582, 92.08479309082031, 85.80876922607422, 62 92.63166046142578, 29.916208267211914, 75.40460968017578, 63 62.06375503540039, 1.7712159156799316, 99.4723129272461, 64 11.440549850463867, 25.396343231201172, 67.0217514038086 65 ], 66 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 67 } 68 } 69 } 70 }, 71 { 72 'name': 'resample2d(upsample) float32 4D tensor options.scales', 73 'graph': { 74 'inputs': { 75 'resample2dInput': { 76 'data': [ 77 59.92947006225586, 41.98918914794922, 66.39534759521484, 78 90.7006607055664, 86.95105743408203, 79.10005187988281 79 ], 80 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 81 } 82 }, 83 'operators': [{ 84 'name': 'resample2d', 85 'arguments': 86 [{'input': 'resample2dInput'}, {'options': {'scales': [2, 2]}}], 87 'outputs': 'resample2dOutput' 88 }], 89 'expectedOutputs': { 90 'resample2dOutput': { 91 'data': [ 92 59.92947006225586, 59.92947006225586, 41.98918914794922, 93 41.98918914794922, 66.39534759521484, 66.39534759521484, 94 59.92947006225586, 59.92947006225586, 41.98918914794922, 95 41.98918914794922, 66.39534759521484, 66.39534759521484, 96 90.7006607055664, 90.7006607055664, 86.95105743408203, 97 86.95105743408203, 79.10005187988281, 79.10005187988281, 98 90.7006607055664, 90.7006607055664, 86.95105743408203, 99 86.95105743408203, 79.10005187988281, 79.10005187988281 100 ], 101 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 102 } 103 } 104 } 105 }, 106 { 107 'name': 'resample2d(upsample) float32 4D tensor options.sizes', 108 'graph': { 109 'inputs': { 110 'resample2dInput': { 111 'data': [ 112 59.92947006225586, 41.98918914794922, 66.39534759521484, 113 90.7006607055664, 86.95105743408203, 79.10005187988281 114 ], 115 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 116 } 117 }, 118 'operators': [{ 119 'name': 'resample2d', 120 'arguments': 121 [{'input': 'resample2dInput'}, {'options': {'sizes': [4, 6]}}], 122 'outputs': 'resample2dOutput' 123 }], 124 'expectedOutputs': { 125 'resample2dOutput': { 126 'data': [ 127 59.92947006225586, 59.92947006225586, 41.98918914794922, 128 41.98918914794922, 66.39534759521484, 66.39534759521484, 129 59.92947006225586, 59.92947006225586, 41.98918914794922, 130 41.98918914794922, 66.39534759521484, 66.39534759521484, 131 90.7006607055664, 90.7006607055664, 86.95105743408203, 132 86.95105743408203, 79.10005187988281, 79.10005187988281, 133 90.7006607055664, 90.7006607055664, 86.95105743408203, 134 86.95105743408203, 79.10005187988281, 79.10005187988281 135 ], 136 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 137 } 138 } 139 } 140 }, 141 { 142 'name': 143 'resample2d(upsample) float32 4D tensor options.sizes ignored options.scales', 144 'graph': { 145 'inputs': { 146 'resample2dInput': { 147 'data': [ 148 59.92947006225586, 41.98918914794922, 66.39534759521484, 149 90.7006607055664, 86.95105743408203, 79.10005187988281 150 ], 151 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 152 } 153 }, 154 'operators': [{ 155 'name': 'resample2d', 156 'arguments': [ 157 {'input': 'resample2dInput'}, 158 {'options': {'scales': [0.5, 0.5], 'sizes': [4, 6]}} 159 ], 160 'outputs': 'resample2dOutput' 161 }], 162 'expectedOutputs': { 163 'resample2dOutput': { 164 'data': [ 165 59.92947006225586, 59.92947006225586, 41.98918914794922, 166 41.98918914794922, 66.39534759521484, 66.39534759521484, 167 59.92947006225586, 59.92947006225586, 41.98918914794922, 168 41.98918914794922, 66.39534759521484, 66.39534759521484, 169 90.7006607055664, 90.7006607055664, 86.95105743408203, 170 86.95105743408203, 79.10005187988281, 79.10005187988281, 171 90.7006607055664, 90.7006607055664, 86.95105743408203, 172 86.95105743408203, 79.10005187988281, 79.10005187988281 173 ], 174 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 175 } 176 } 177 } 178 }, 179 { 180 'name': 'resample2d(upsample) float32 4D tensor options.axes=[1, 2]', 181 'graph': { 182 'inputs': { 183 'resample2dInput': { 184 'data': [ 185 59.92947006225586, 41.98918914794922, 66.39534759521484, 186 90.7006607055664, 86.95105743408203, 79.10005187988281 187 ], 188 'descriptor': {shape: [1, 2, 3, 1], dataType: 'float32'} 189 } 190 }, 191 'operators': [{ 192 'name': 'resample2d', 193 'arguments': [ 194 {'input': 'resample2dInput'}, 195 {'options': {'sizes': [4, 6], 'axes': [1, 2]}} 196 ], 197 'outputs': 'resample2dOutput' 198 }], 199 'expectedOutputs': { 200 'resample2dOutput': { 201 'data': [ 202 59.92947006225586, 59.92947006225586, 41.98918914794922, 203 41.98918914794922, 66.39534759521484, 66.39534759521484, 204 59.92947006225586, 59.92947006225586, 41.98918914794922, 205 41.98918914794922, 66.39534759521484, 66.39534759521484, 206 90.7006607055664, 90.7006607055664, 86.95105743408203, 207 86.95105743408203, 79.10005187988281, 79.10005187988281, 208 90.7006607055664, 90.7006607055664, 86.95105743408203, 209 86.95105743408203, 79.10005187988281, 79.10005187988281 210 ], 211 'descriptor': {shape: [1, 4, 6, 1], dataType: 'float32'} 212 } 213 } 214 } 215 }, 216 { 217 'name': 218 'resample2d(upsample) float32 4D tensor explicit options.axes=[2, 3]', 219 'graph': { 220 'inputs': { 221 'resample2dInput': { 222 'data': [ 223 59.92947006225586, 41.98918914794922, 66.39534759521484, 224 90.7006607055664, 86.95105743408203, 79.10005187988281 225 ], 226 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 227 } 228 }, 229 'operators': [{ 230 'name': 'resample2d', 231 'arguments': [ 232 {'input': 'resample2dInput'}, 233 {'options': {'sizes': [4, 6], 'axes': [2, 3]}} 234 ], 235 'outputs': 'resample2dOutput' 236 }], 237 'expectedOutputs': { 238 'resample2dOutput': { 239 'data': [ 240 59.92947006225586, 59.92947006225586, 41.98918914794922, 241 41.98918914794922, 66.39534759521484, 66.39534759521484, 242 59.92947006225586, 59.92947006225586, 41.98918914794922, 243 41.98918914794922, 66.39534759521484, 66.39534759521484, 244 90.7006607055664, 90.7006607055664, 86.95105743408203, 245 86.95105743408203, 79.10005187988281, 79.10005187988281, 246 90.7006607055664, 90.7006607055664, 86.95105743408203, 247 86.95105743408203, 79.10005187988281, 79.10005187988281 248 ], 249 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 250 } 251 } 252 } 253 }, 254 { 255 'name': 256 'resample2d(upsample) float32 4D tensor explicit options.axes=[3, 2]', 257 'graph': { 258 'inputs': { 259 'resample2dInput': { 260 'data': [ 261 59.92947006225586, 41.98918914794922, 66.39534759521484, 262 90.7006607055664, 86.95105743408203, 79.10005187988281 263 ], 264 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 265 } 266 }, 267 'operators': [{ 268 'name': 'resample2d', 269 'arguments': [ 270 {'input': 'resample2dInput'}, 271 {'options': {'sizes': [6, 4], 'axes': [3, 2]}} 272 ], 273 'outputs': 'resample2dOutput' 274 }], 275 'expectedOutputs': { 276 'resample2dOutput': { 277 'data': [ 278 59.92947006225586, 59.92947006225586, 41.98918914794922, 279 41.98918914794922, 66.39534759521484, 66.39534759521484, 280 59.92947006225586, 59.92947006225586, 41.98918914794922, 281 41.98918914794922, 66.39534759521484, 66.39534759521484, 282 90.7006607055664, 90.7006607055664, 86.95105743408203, 283 86.95105743408203, 79.10005187988281, 79.10005187988281, 284 90.7006607055664, 90.7006607055664, 86.95105743408203, 285 86.95105743408203, 79.10005187988281, 79.10005187988281 286 ], 287 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 288 } 289 } 290 } 291 }, 292 { 293 'name': 294 'resample2d(upsample) float32 4D tensor explicit options.mode=\'nearest-neighbor\'', 295 'graph': { 296 'inputs': { 297 'resample2dInput': { 298 'data': [ 299 59.92947006225586, 41.98918914794922, 66.39534759521484, 300 90.7006607055664, 86.95105743408203, 79.10005187988281 301 ], 302 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 303 } 304 }, 305 'operators': [{ 306 'name': 'resample2d', 307 'arguments': [ 308 {'input': 'resample2dInput'}, 309 {'options': {'mode': 'nearest-neighbor', 'sizes': [4, 6]}} 310 ], 311 'outputs': 'resample2dOutput' 312 }], 313 'expectedOutputs': { 314 'resample2dOutput': { 315 'data': [ 316 59.92947006225586, 59.92947006225586, 41.98918914794922, 317 41.98918914794922, 66.39534759521484, 66.39534759521484, 318 59.92947006225586, 59.92947006225586, 41.98918914794922, 319 41.98918914794922, 66.39534759521484, 66.39534759521484, 320 90.7006607055664, 90.7006607055664, 86.95105743408203, 321 86.95105743408203, 79.10005187988281, 79.10005187988281, 322 90.7006607055664, 90.7006607055664, 86.95105743408203, 323 86.95105743408203, 79.10005187988281, 79.10005187988281 324 ], 325 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 326 } 327 } 328 } 329 }, 330 { 331 'name': 332 'resample2d(upsample) float32 4D tensor options.scales options.mode=\'linear\'', 333 'graph': { 334 'inputs': { 335 'resample2dInput': { 336 'data': [ 337 59.92947006225586, 41.98918914794922, 66.39534759521484, 338 90.7006607055664, 86.95105743408203, 79.10005187988281 339 ], 340 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 341 } 342 }, 343 'operators': [{ 344 'name': 'resample2d', 345 'arguments': [ 346 {'input': 'resample2dInput'}, 347 {'options': {'mode': 'linear', 'scales': [2, 2]}} 348 ], 349 'outputs': 'resample2dOutput' 350 }], 351 'expectedOutputs': { 352 'resample2dOutput': { 353 'data': [ 354 59.92947006225586, 55.444400787353516, 46.47425842285156, 355 48.090728759765625, 60.29380798339844, 66.39534759521484, 356 67.62226867675781, 64.02411651611328, 56.82780838012695, 357 57.31512451171875, 65.48605346679688, 69.57152557373047, 358 83.00786590576172, 81.18354797363281, 77.534912109375, 359 75.76390838623047, 75.87055206298828, 75.92387390136719, 360 90.7006607055664, 89.76325988769531, 87.88845825195312, 361 84.9883041381836, 81.06280517578125, 79.10005187988281 362 ], 363 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 364 } 365 } 366 } 367 }, 368 { 369 'name': 370 'resample2d(upsample) float32 4D tensor options.sizes options.mode=\'linear\'', 371 'graph': { 372 'inputs': { 373 'resample2dInput': { 374 'data': [ 375 59.92947006225586, 41.98918914794922, 66.39534759521484, 376 90.7006607055664, 86.95105743408203, 79.10005187988281 377 ], 378 'descriptor': {shape: [1, 1, 2, 3], dataType: 'float32'} 379 } 380 }, 381 'operators': [{ 382 'name': 'resample2d', 383 'arguments': [ 384 {'input': 'resample2dInput'}, 385 {'options': {'mode': 'linear', 'sizes': [4, 6]}} 386 ], 387 'outputs': 'resample2dOutput' 388 }], 389 'expectedOutputs': { 390 'resample2dOutput': { 391 'data': [ 392 59.92947006225586, 55.444400787353516, 46.47425842285156, 393 48.090728759765625, 60.29380798339844, 66.39534759521484, 394 67.62226867675781, 64.02411651611328, 56.82780838012695, 395 57.31512451171875, 65.48605346679688, 69.57152557373047, 396 83.00786590576172, 81.18354797363281, 77.534912109375, 397 75.76390838623047, 75.87055206298828, 75.92387390136719, 398 90.7006607055664, 89.76325988769531, 87.88845825195312, 399 84.9883041381836, 81.06280517578125, 79.10005187988281 400 ], 401 'descriptor': {shape: [1, 1, 4, 6], dataType: 'float32'} 402 } 403 } 404 } 405 }, 406 { 407 'name': 408 'resample2d(upsample) float32 4D tensor options.axes=[1, 2] options.mode=\'linear\'', 409 'graph': { 410 'inputs': { 411 'resample2dInput': { 412 'data': [ 413 59.92947006225586, 41.98918914794922, 66.39534759521484, 414 90.7006607055664, 86.95105743408203, 79.10005187988281 415 ], 416 'descriptor': {shape: [1, 2, 3, 1], dataType: 'float32'} 417 } 418 }, 419 'operators': [{ 420 'name': 'resample2d', 421 'arguments': [ 422 {'input': 'resample2dInput'}, 423 {'options': {'mode': 'linear', 'sizes': [4, 6], 'axes': [1, 2]}} 424 ], 425 'outputs': 'resample2dOutput' 426 }], 427 'expectedOutputs': { 428 'resample2dOutput': { 429 'data': [ 430 59.92947006225586, 55.444400787353516, 46.47425842285156, 431 48.090728759765625, 60.29380798339844, 66.39534759521484, 432 67.62226867675781, 64.02411651611328, 56.82780838012695, 433 57.31512451171875, 65.48605346679688, 69.57152557373047, 434 83.00786590576172, 81.18354797363281, 77.534912109375, 435 75.76390838623047, 75.87055206298828, 75.92387390136719, 436 90.7006607055664, 89.76325988769531, 87.88845825195312, 437 84.9883041381836, 81.06280517578125, 79.10005187988281 438 ], 439 'descriptor': {shape: [1, 4, 6, 1], dataType: 'float32'} 440 } 441 } 442 } 443 }, 444 { 445 'name': 'resample2d(upsample) float32 4D tensor options.axes=[0, 1]', 446 'graph': { 447 'inputs': { 448 'resample2dInput': { 449 'data': [ 450 59.92947006225586, 90.7006607055664, 41.98918914794922, 451 86.95105743408203, 66.39534759521484, 79.10005187988281 452 ], 453 'descriptor': {shape: [3, 2, 1, 1], dataType: 'float32'} 454 } 455 }, 456 'operators': [{ 457 'name': 'resample2d', 458 'arguments': [ 459 {'input': 'resample2dInput'}, 460 {'options': {'sizes': [6, 4], 'axes': [0, 1]}} 461 ], 462 'outputs': 'resample2dOutput' 463 }], 464 'expectedOutputs': { 465 'resample2dOutput': { 466 'data': [ 467 59.92947006225586, 59.92947006225586, 90.7006607055664, 468 90.7006607055664, 59.92947006225586, 59.92947006225586, 469 90.7006607055664, 90.7006607055664, 41.98918914794922, 470 41.98918914794922, 86.95105743408203, 86.95105743408203, 471 41.98918914794922, 41.98918914794922, 86.95105743408203, 472 86.95105743408203, 66.39534759521484, 66.39534759521484, 473 79.10005187988281, 79.10005187988281, 66.39534759521484, 474 66.39534759521484, 79.10005187988281, 79.10005187988281 475 ], 476 'descriptor': {shape: [6, 4, 1, 1], dataType: 'float32'} 477 } 478 } 479 } 480 }, 481 { 482 'name': 'resample2d(upsample) float32 4D tensor options.axes=[1, 0]', 483 'graph': { 484 'inputs': { 485 'resample2dInput': { 486 'data': [ 487 59.92947006225586, 90.7006607055664, 41.98918914794922, 488 86.95105743408203, 66.39534759521484, 79.10005187988281 489 ], 490 'descriptor': {shape: [3, 2, 1, 1], dataType: 'float32'} 491 } 492 }, 493 'operators': [{ 494 'name': 'resample2d', 495 'arguments': [ 496 {'input': 'resample2dInput'}, 497 {'options': {'sizes': [4, 6], 'axes': [1, 0]}} 498 ], 499 'outputs': 'resample2dOutput' 500 }], 501 'expectedOutputs': { 502 'resample2dOutput': { 503 'data': [ 504 59.92947006225586, 59.92947006225586, 90.7006607055664, 505 90.7006607055664, 59.92947006225586, 59.92947006225586, 506 90.7006607055664, 90.7006607055664, 41.98918914794922, 507 41.98918914794922, 86.95105743408203, 86.95105743408203, 508 41.98918914794922, 41.98918914794922, 86.95105743408203, 509 86.95105743408203, 66.39534759521484, 66.39534759521484, 510 79.10005187988281, 79.10005187988281, 66.39534759521484, 511 66.39534759521484, 79.10005187988281, 79.10005187988281 512 ], 513 'descriptor': {shape: [6, 4, 1, 1], dataType: 'float32'} 514 } 515 } 516 } 517 } 518 ]; 519 520 webnn_conformance_test( 521 resample2dTests, buildAndExecuteGraph, getPrecisionTolerance);