'How to run a pickle file in node js

Working in an AI/ML project, I need a way to run the pickle file inside nodejs so I can use it to run the algorithm on the data they submitted.



Solution 1:[1]

Try to use the node-pickle library to convert the pickle file to the JSON object. Here documentation of node-pickle

const nodePickle = require('node-pickle');

// Convert pickled object to JSON object
nodePickle.load(pickledData)
.then(data => ({
// data is a JSON object here
})

Then you can use tensorflow.js to run that JSON object as a model. Tenrsorflow.js Documentation

Solution 2:[2]

The only one I could find from a quick google search is node-jpickle. According to it's docs, it seems to be able to handle most of the situations pickle can, even some of the more advanced ones such as classes:

function MyClass() {}

var jpickle = require('jpickle');
jpickle.emulated['__main__.MyClass'] = MyClass;
var unpickled = jpickle.loads(pickled);

If you're just trying to pickle/unpickle, you can just do it like you would in Python:

var unpickled = jpickle.loads(pickled);

The docs don't state anything about a normal load function however.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Deshitha Hansajith
Solution 2 zurgeg