Saturday, February 7, 2026
HomeLanguagesJavascriptTensorflow.js tf.GraphModel class .execute() Method

Tensorflow.js tf.GraphModel class .execute() Method

Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The .execute() method is used to implement implication in favor of the given model for the stated input tensors.

Syntax:

execute(inputs, outputs?)

Parameters:  

  • inputs: It is the stated tensor or a tensor array or a tensor map of the inputs in favor of the model, handled via input node designations. It is of type (tf.Tensor|tf.Tensor[]|{[name: string]: tf.Tensor}).
  • outputs: It is the stated output node designation from the stated tensorflow model. If the outputs are not stated, then the by default outputs of the stated model must be applied. Moreover, we can analyze the in between nodes of the specified model by affixing them to the outputs array. It is of type string or string[].

Return Value: It returns  tf.Tensor or tf.Tensor[].

Example 1: In this example, we are loading MobileNetV2 from a URL.

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining tensor input elements
const model_Url =
  
// Calling the loadGraphModel() method
const mymodel = await tf.loadGraphModel(model_Url);
  
// Defining inputs
const inputs = tf.zeros([1, 224, 224, 3]);
  
// Calling execute() method and 
// Printing output
mymodel.execute(inputs).print();


Output:

Tensor
     [[-0.1800361, -0.4059965, 0.8190175, 
     ..., 
     -0.8953396, -1.0841646, 1.2912753],]

Example 2: In this example, we are loading MobileNetV2 from a TF Hub URL.

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining tensor input elements
const model_Url =
  
// Calling the loadGraphModel() method
const mymodel = await tf.loadGraphModel(
        model_Url, {fromTFHub: true});
  
// Defining inputs
const inputs = tf.zeros([1, 224, 224, 3]);
  
// Defining outputs
const outputs = "module_apply_default/MobilenetV2/Logits/output";
  
// Calling execute() method and 
// Printing output
mymodel.execute(inputs, outputs).print();


Output:

Tensor
     [[-1.1690605, 0.0195426, 1.1962479, 
     ..., 
     -0.4825858, -0.0055641, 1.1937635],]

Reference: https://js.tensorflow.org/api/latest/#tf.GraphModel.execute

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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32493 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6864 POSTS0 COMMENTS
Nicole Veronica
11990 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12083 POSTS0 COMMENTS
Shaida Kate Naidoo
7000 POSTS0 COMMENTS
Ted Musemwa
7241 POSTS0 COMMENTS
Thapelo Manthata
6951 POSTS0 COMMENTS
Umr Jansen
6936 POSTS0 COMMENTS