Reputation: 372
Am trying to load a pre-trained Keras model to my small react-App. Since with the 2.0 version of TensorFlow, few things were added and changed. I would like to know how one should load the model from the native file system.
import * as tf from "@tensorflow/tfjs";
My directory structure model.json and all .bin files required are located in the same directory as my App.js from which am referring to them.
Load the pre-trained model - docs
model = await tf.loadLayersModel("file://model.json");
Unfortunately am getting failed to fetch error. Can anyone explain me what am I missing?
Upvotes: 1
Views: 1097
Reputation: 1
expo projects doesnt support such structure.
const modelJson = Asset.fromModule(require('./assets/model/model.json'))
const modelWeights = Asset.fromModule(require('./assets/model/weights.bin'))
Upvotes: 0
Reputation: 6799
You have to set the path to the model weights and JSON using require()
const modelJSON = require("../model/model.json");
const modelWeights = require("../model/group1-shard1of1.bin");
const model = await tf.loadLayersModel(bundleResourceIO(modelJSON, modelWeights))
Edit in the case of you having multiple bin files you can only use one bin file with one model.json
The code below converts your keras model to a single bin file and model.json
tensorflowjs_converter --input_format keras --weight_shard_size_bytes 60000000 path_to_model.h5 path_to_save
Upvotes: 3