Artificial intelligence
Image recognition using Tensorflow
Last updated
Image recognition using Tensorflow
Last updated
This example shows how to write a Rust function for image recognition, and then offer this function as AI-as-a-Service.
Using machine learning libraries in Rust, such as the Tract crate which supports both Tensorflow and ONNX inference model, we can write AI-as-a-Service functions in Node.js. The functions could take AI models and input data, and return inference results, such as recognized objects on an input image, through a web service.
The example project source code is here.
The following Rust function does the inference.
The infer()
function takes raw bytes for an already-trained Tensorflow model from ImageNet, and an input image.
The infer_impl()
function resizes the image, applies the model to it, and returns the top matched label and probability. The label indicates an object the ImageNet model has been trained to recognize.
The Javascript function reads the model and image files, and calls the Rust function.
Next, build it with ssvmup
, and then run the Javascript file in Node.js.
You can look up the output detected object ID from the imagenet_slim_labels.txt file from ImageNet.
Now, it should be easy for you to turn this example into a Node.js-based web service so that users can send in images and detect objects!