| 12345678910111213141516171819202122232425262728 |
- import * as ort from "onnxruntime-react-native";
- import * as FileSystem from "expo-file-system/legacy";
- import { Asset } from "expo-asset";
- let cachedSession: ort.InferenceSession | null = null;
- export async function loadPlantVillageSession() {
- if (cachedSession) return cachedSession;
- const asset = Asset.fromModule(
- require("../../assets/plantvillage_mnv3s_224.onnx")
- );
- await asset.downloadAsync();
- const modelPath = FileSystem.documentDirectory + "plantvillage_mnv3s_224.onnx";
- const info = await FileSystem.getInfoAsync(modelPath);
- if (!info.exists) {
- await FileSystem.copyAsync({
- from: asset.localUri!,
- to: modelPath,
- });
- }
- cachedSession = await ort.InferenceSession.create(modelPath);
- return cachedSession;
- }
|