(
args:
{backend: BackendWasm, inputs: TransformInputs, attrs: TransformAttrs})
| 50 | } |
| 51 | |
| 52 | function transform( |
| 53 | args: |
| 54 | {backend: BackendWasm, inputs: TransformInputs, attrs: TransformAttrs}): |
| 55 | TensorInfo { |
| 56 | const {backend, inputs, attrs} = args; |
| 57 | const {image, transforms} = inputs; |
| 58 | const {interpolation, fillMode, fillValue, outputShape} = attrs; |
| 59 | |
| 60 | const [batch, imageHeight, imageWidth, numChannels] = image.shape; |
| 61 | const [outHeight, outWidth] = |
| 62 | outputShape != null ? outputShape : [imageHeight, imageWidth]; |
| 63 | const outShape = |
| 64 | [batch, outHeight, outWidth, |
| 65 | numChannels] as [number, number, number, number]; |
| 66 | const inputStrides = |
| 67 | new Uint8Array(new Int32Array(util.computeStrides(image.shape)).buffer); |
| 68 | |
| 69 | const outputStrides = |
| 70 | new Uint8Array(new Int32Array(util.computeStrides(outShape)).buffer); |
| 71 | |
| 72 | const out = backend.makeOutput(outShape, image.dtype); |
| 73 | const outId = backend.dataIdMap.get(out.dataId).id; |
| 74 | |
| 75 | const imageData = backend.dataIdMap.get(image.dataId); |
| 76 | const imageId = imageData.id; |
| 77 | |
| 78 | const transformsData = backend.dataIdMap.get(transforms.dataId); |
| 79 | const transformsId = transformsData.id; |
| 80 | |
| 81 | const interpolationModeId = interpolation === 'nearest' ? 1 : 2; |
| 82 | let fillModeId; |
| 83 | switch (fillMode) { |
| 84 | case 'constant': |
| 85 | fillModeId = 1; |
| 86 | break; |
| 87 | case 'reflect': |
| 88 | fillModeId = 2; |
| 89 | break; |
| 90 | case 'wrap': |
| 91 | fillModeId = 3; |
| 92 | break; |
| 93 | case 'nearest': |
| 94 | fillModeId = 4; |
| 95 | break; |
| 96 | default: |
| 97 | fillModeId = 1; |
| 98 | break; |
| 99 | } |
| 100 | |
| 101 | wasmTransform( |
| 102 | imageId, transformsId, (transforms.shape[0] > 1), batch, outHeight, |
| 103 | outWidth, numChannels, imageWidth, imageHeight, inputStrides, |
| 104 | image.shape.length - 1, outputStrides, outShape.length - 1, |
| 105 | interpolationModeId, fillModeId, fillValue, outId); |
| 106 | |
| 107 | return out; |
| 108 | } |
| 109 |
nothing calls this directly
no test coverage detected
searching dependent graphs…