本地设备ERROR React Native的loadGraphModel模型json



i使用本地设备ERROR React Native中的loadGraphModel模型json我的职能:代码:

async function predictModellocal1() {
console.log("[+] Application started")
const tfReady = await tf.ready();
tf.device_util.isMobile = () => true
tf.device_util.isBrowser = () => false
console.log("[+] Loading  face detection model")
const modelUrl =
'https://storage.googleapis.com/tfjs-models/savedmodel/mobilenet_v2_1.0_224/model.json';
console.log("[+] Loading  face detection model")
const modelPath=
'D:\Code\ReactNative\appAI-mobilenet\assets\facenet\weights_manifest.json';
const modelPath1  = await require("./assets/facenet/weights_manifest.json");
const model = await tf.loadGraphModel(modelPath1);
console.log("[+] Loading model: done")
const imgB64 = await FileSystem.readAsStringAsync(selectedImage.localUri, {
encoding: FileSystem.EncodingType.Base64,
});
const imgBuffer = tf.util.encodeString(imgB64, 'base64').buffer;
const raw = new Uint8Array(imgBuffer)
const imageTensor = decodeJpeg(raw);
const img = tf.image.resizeBilinear(imageTensor, [224,224])
console.log(' Đã chạy')
const img4d = img.reshape([1, 224, 224, 3,]);
const prediction = await model.predict(img4d);
const kq = getTopKClasses(prediction, 5)
console.log(kq,'kq')
setTextshow('ok')
}

modelUrl运行良好。我从谷歌api得到模型。

const modelUrl ='https://storage.googleapis.com/tfjs-models/savedmodel/mobilenet_v2_1.0_224/model.json';

但我想从本地加载GrapModel以使用offine:

const modelPath='D:\Code\ReactNative\appAI-mobilenet\assets\facenet\weights_manifest.json';
const modelPath1  = await require("./assets/facenet/weights_manifest.json");

我的应用程序使用Expo CLI。感谢所有

Error: EISDIR: illegal operation on a directory, read
at Object.readSync (fs.js:523:3)
at tryReadSync (fs.js:348:20)
at Object.readFileSync (fs.js:385:19)
at UnableToResolveError.buildCodeFrameMessage (D:CodeReactNativeappAI-mobilenetnode_modulesmetrosrcnode-hasteDependencyGraphModuleResolution.js:304:17)
at new UnableToResolveError (D:CodeReactNativeappAI-mobilenetnode_modulesmetrosrcnode-hasteDependencyGraphModuleResolution.js:290:35)
at ModuleResolver.resolveDependency (D:CodeReactNativeappAI-mobilenetnode_modulesmetrosrcnode-hasteDependencyGraphModuleResolution.js:168:15)
at DependencyGraph.resolveDependency (D:CodeReactNativeappAI-mobilenetnode_modulesmetrosrcnode-hasteDependencyGraph.js:353:43)
at D:CodeReactNativeappAI-mobilenetnode_modulesmetrosrclibtransformHelpers.js:271:42
at D:CodeReactNativeappAI-mobilenetnode_modulesmetrosrcServer.js:1097:37
at Generator.next (<anonymous>)
[Unhandled promise rejection: TypeError: url.match is not a function. (In 'url.match(HTTPRequest.URL_SCHEME_REGEX)', 'url.match' is undefined)]
at http://192.168.31.235:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:184464:20 in isHTTPScheme
at [native code]:null in every
at httpRouter@http://192.168.31.235:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:184474:26 in <unknown>

在设置modelPath1:的路径时删除await关键字

const modelPath1 = require("./assets/facenet/weights_manifest.json");
const model = await tf.loadGraphModel(modelPath1);

最新更新