Use tfjs-react-native with posenet and bundleResourceIO

I want to build an react native app with the use of posenet. A requirement is, that it works offline.

so the examples work fine. when i do:

import * as posenet from '@tensorflow-models/posenet'
this.model = await posenet.load();

so what i did next is converting the model to one weigth file and load the model locally with:

const modelJson = require('./assets/model/original/model-stride32.json');
const modelWeights = require('./assets/model/original/weigth.bin');
    
this.model = await tf.loadGraphModel(
   bundleResourceIO(modelJson, modelWeights)
);

so what i want to do next is to run something like this:

const predictions = await this.model.estimateSinglePose(imageTensor)

but of course this doesn’t work because the model doesn’t know the function.

i know i can instanciate the model by using something like this:

const checkpointLoader = new posenet.CheckpointLoader(checkpoint.url);
const variables = await checkpointLoader.getAllVariables();
const model =  new posenet.MobileNet(variables, checkpoint.architecture);

but the checkpoint loader needs an url. i want to use the local files.

does anyone has a hint for me how to use posenet without rewriting the whole node-module?

thx in advance

1 possible answer(s) on “Use tfjs-react-native with posenet and bundleResourceIO