Thursday, December 26, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.decodeString() Function

Tensorflow.js tf.decodeString() Function

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




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining array ArrayBuffer
var buffer = new ArrayBuffer(13);
  
// Defining bytes to be decoded
var y = new Uint8Array(buffer);
y[1] = 89;
  
// Calling tf.decodeString() method and
// printing output
const str = tf.util.decodeString(y, "ASCII");
console.log(str);


Output:

Y

Example 2: When encoding scheme is not provided.

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining array ArrayBuffer
var buffer = new ArrayBuffer(13);
  
// Defining bytes to be decoded
var y = new Uint8Array(buffer);
y[1] = 75;
  
// Calling tf.decodeString() method and
// printing output
console.log(tf.util.decodeString(y));


Output:

K

Reference: https://js.tensorflow.org/api/latest/#decodeString

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments