Skip to content

Commit

Permalink
[tfjs-node] add encodeBase64, decodeBase64
Browse files Browse the repository at this point in the history
  • Loading branch information
vabarbosa committed Sep 9, 2019
1 parent ea632d9 commit ec8a768
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tfjs-node/src/nodejs_kernel_backend.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2018 Google Inc. All Rights Reserved.
* Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -20,7 +20,7 @@ import {BackendTimingInfo, DataMover, DataType, fill, KernelBackend, ones, Rank,
import {EPSILON_FLOAT32} from '@tensorflow/tfjs-core/dist/backends/backend';
import {Conv2DInfo, Conv3DInfo} from '@tensorflow/tfjs-core/dist/ops/conv_util';
import {Activation, FusedBatchMatMulConfig} from '@tensorflow/tfjs-core/dist/ops/fused_util';
import {Tensor5D} from '@tensorflow/tfjs-core/dist/tensor';
import {StringTensor, Tensor5D} from '@tensorflow/tfjs-core/dist/tensor';
import {BackendValues, upcastType} from '@tensorflow/tfjs-core/dist/types';
import {isArray, isNullOrUndefined} from 'util';

Expand Down Expand Up @@ -1707,6 +1707,20 @@ export class NodeJSKernelBackend extends KernelBackend {
return this.executeSingleOutput('LinSpace', opAttrs, inputs) as Tensor1D;
}

encodeBase64<T extends StringTensor>(str: StringTensor|Tensor, pad = false):
T {
const opAttrs =
[{name: 'pad', type: this.binding.TF_ATTR_BOOL, value: pad}];
return this.executeSingleOutput('EncodeBase64', opAttrs, [str as Tensor]) as
T;
}

decodeBase64<T extends StringTensor>(str: StringTensor|Tensor): T {
const opAttrs: TFEOpAttr[] = [];
return this.executeSingleOutput('DecodeBase64', opAttrs, [str as Tensor]) as
T;
}

fromPixels(
pixels: ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement,
numChannels: number): Tensor3D {
Expand Down

0 comments on commit ec8a768

Please sign in to comment.