MCPcopy Create free account
hub / github.com/tensorflow/tfjs / transform_

Function transform_

tfjs-core/src/ops/image/transform.ts:58–92  ·  view source on GitHub ↗

* Applies the given transform(s) to the image(s). * * @param image 4d tensor of shape `[batch, imageHeight, imageWidth, depth]`. * @param transforms Projective transform matrix/matrices. A tensor1d of length * 8 or tensor of size N x 8. If one row of transforms is [a0, a1, a2, b0, * b1,

(
    image: Tensor4D|TensorLike, transforms: Tensor2D|TensorLike,
    interpolation: 'nearest'|'bilinear' = 'nearest',
    fillMode: 'constant'|'reflect'|'wrap'|'nearest' = 'constant', fillValue = 0,
    outputShape?: [number, number])

Source from the content-addressed store, hash-verified

56 * @doc {heading: 'Operations', subheading: 'Images', namespace: 'image'}
57 */
58function transform_(
59 image: Tensor4D|TensorLike, transforms: Tensor2D|TensorLike,
60 interpolation: 'nearest'|'bilinear' = 'nearest',
61 fillMode: 'constant'|'reflect'|'wrap'|'nearest' = 'constant', fillValue = 0,
62 outputShape?: [number, number]): Tensor4D {
63 const $image = convertToTensor(image, 'image', 'transform', 'float32');
64 const $transforms =
65 convertToTensor(transforms, 'transforms', 'transform', 'float32');
66
67 util.assert(
68 $image.rank === 4,
69 () => 'Error in transform: image must be rank 4,' +
70 `but got rank ${$image.rank}.`);
71
72 util.assert(
73 $transforms.rank === 2 &&
74 ($transforms.shape[0] === $image.shape[0] ||
75 $transforms.shape[0] === 1) &&
76 $transforms.shape[1] === 8,
77 () => `Error in transform: Input transform should be batch x 8 or 1 x 8`);
78
79 util.assert(
80 outputShape == null || outputShape.length === 2,
81 () =>
82 'Error in transform: outputShape must be [height, width] or null, ' +
83 `but got ${outputShape}.`);
84
85 const inputs: TransformInputs = {image: $image, transforms: $transforms};
86 const attrs:
87 TransformAttrs = {interpolation, fillMode, fillValue, outputShape};
88
89 return ENGINE.runKernel(
90 Transform, inputs as unknown as NamedTensorMap,
91 attrs as unknown as NamedAttrMap);
92}
93
94export const transform = /* @__PURE__ */ op({transform_});

Callers

nothing calls this directly

Calls 2

convertToTensorFunction · 0.90
runKernelMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…