Tensorflow.js is an open-source library which is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .decodeString() function is used to decode the stated bytes into a string with the help of the given encoding scheme.
Syntax :
tf.decodeString(bytes, encoding?)
Parameters:
- bytes: It is the stated bytes which is to be decoded. It is of type Uint8Array.
- encoding: It is the encoding scheme which is to be used. And the by default value is utf-8.
Return Value: It returns string.
Example 1: When encoding scheme is provided.
Javascript
import * as tf from "@tensorflow/tfjs"
var buffer = new ArrayBuffer(13);
var y = new Uint8Array(buffer);
y[1] = 89;
const str = tf.util.decodeString(y, "ASCII" );
console.log(str);
|
Output:
Y
Example 2: When encoding scheme is not provided.
Javascript
import * as tf from "@tensorflow/tfjs"
var buffer = new ArrayBuffer(13);
var y = new Uint8Array(buffer);
y[1] = 75;
console.log(tf.util.decodeString(y));
|
Output:
K
Reference: https://js.tensorflow.org/api/latest/#decodeString