facebookresearch / playtorch

PlayTorch is a framework for rapidly creating mobile AI experiences.
https://playtorch.dev/
MIT License
830 stars 101 forks source link

unable to load local .ptl model #211

Open akash-zdaly opened 1 year ago

akash-zdaly commented 1 year ago

Description

Hi,

I want to load a local model located in my project folder at "./models/model.ptl"

i tried using ,

''' // const filePath = await MobileModel.download(MODEL_URL); // model = await torch.jit._loadForMobile('./assets/yolo_zdaly.ptl'); model = await Torch.loadModel(modelPath); console.log(model); console.log('Model successfully loaded');

'''

react-native-pytorch-core": "^0.2.4"

Images

image

Website

NA

Credit (optional)

No response

Source Code (optional)

https://github.com/akash-zdaly/objdet

remod commented 1 year ago

I've managed to make it work using

let path = await MobileModel.download(
  require('./models/model.ptl'),
);
let model = await torch.jit._loadForMobile(path);

Note 1: You need to make sure the ptl file is bundled with your app. To achieve this, make sure you've performed this step.

Note 2: Model::download()is deprecated. It's documentation recommends to "Use third-party file downloader (e.g., expo-file-system or react-native-fs)". But I guess as long as other code in this repo is using the function it is still fine to use :)

bobogogo1990 commented 1 year ago

@remod fixed thanks. And vscode show: The signature '(modelPath: ModelPath): Promise' of 'MobileModel.download' is deprecated.ts(6387).

Is there new method?