gpt4 book ai didi

java - 从 Assets 文件夹加载 ~200mb 文件时出现 OutOfMemoryError

转载 作者:太空狗 更新时间:2023-10-29 13:53:00 24 4
gpt4 key购买 nike

<分区>

当我运行应用程序并想要加载时,Android 无法分配足够的内存

java.lang.OutOfMemoryError: Failed to allocate a 202728962 byte allocation with 14422192 free bytes and 171MB until OOM

另外我之前在这里描述了一个错误:https://github.com/tensorflow/tensorflow/issues/9343

我想我有足够的可用内存(通常有 1.0-1.5 GB 可用):

enter image description here

那么它只是 java android 限制吗?我能以某种方式用java解决它吗?还是只有 NDK 才有可能?

完整错误代码:

04-21 09:40:52.731 31597-31597/org.tensorflow.demo E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.tensorflow.demo, PID: 31597
java.lang.OutOfMemoryError: Failed to allocate a 202728962 byte allocation with 14422192 free bytes and 171MB until OOM
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.loadGraph(TensorFlowInferenceInterface.java:377)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.<init>(TensorFlowInferenceInterface.java:96)
at org.tensorflow.demo.TensorFlowYoloDetector.create(TensorFlowYoloDetector.java:111)
at org.tensorflow.demo.DetectorActivity.onPreviewSizeChosen(DetectorActivity.java:131)
at org.tensorflow.demo.CameraActivity$1.onPreviewSizeChosen(CameraActivity.java:159)
at org.tensorflow.demo.CameraConnectionFragment.setUpCameraOutputs(CameraConnectionFragment.java:421)
at org.tensorflow.demo.CameraConnectionFragment.openCamera(CameraConnectionFragment.java:428)
at org.tensorflow.demo.CameraConnectionFragment.access$000(CameraConnectionFragment.java:64)
at org.tensorflow.demo.CameraConnectionFragment$1.onSurfaceTextureAvailable(CameraConnectionFragment.java:95)
at android.view.TextureView.getHardwareLayer(TextureView.java:368)
at android.view.View.updateDisplayListIfDirty(View.java:15175)
at android.view.View.draw(View.java:15971)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.updateDisplayListIfDirty(View.java:15193)
at android.view.View.draw(View.java:15971)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16204)
at android.view.View.updateDisplayListIfDirty(View.java:15198)
at android.view.View.draw(View.java:15971)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.updateDisplayListIfDirty(View.java:15193)
at android.view.View.draw(View.java:15971)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.updateDisplayListIfDirty(View.java:15193)
at android.view.View.draw(View.java:15971)
at android.view.ViewGroup.drawChild(ViewGroup.java:3610)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3400)
at android.view.View.draw(View.java:16204)
at com.android.internal.policy.PhoneWindow$DecorView.draw(PhoneWindow.java:2690)
at android.view.View.updateDisplayListIfDirty(View.java:15198)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:282)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:288)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:323)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2642)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2461)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2094)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1134)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6045)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
at android.view.Choreographer.doCallbacks(Choreographer.java:672)
at android.view.Choreographer.doFrame(Choreographer.java:608)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
04-21 09:40:52.740 1501-2367/? E/ActivityManager: Invalid thumbnail dimensions: 0x0
TensorFlowInferenceInterface 类的

loadGraph 方法:

private void loadGraph(InputStream var1, Graph var2) throws IOException {
long var3 = System.currentTimeMillis();
Trace.beginSection("initializeTensorFlow");
Trace.beginSection("readGraphDef");
byte[] var5 = new byte[var1.available()];
int var6 = var1.read(var5);
if(var6 != var5.length) {
throw new IOException("read error: read only " + var6 + " of the graph, expected to read " + var5.length);
} else {
Trace.endSection();
Trace.beginSection("importGraphDef");

try {
var2.importGraphDef(var5);
} catch (IllegalArgumentException var9) {
throw new IOException("Not a valid TensorFlow Graph serialization: " + var9.getMessage());
}

Trace.endSection();
Trace.endSection();
long var7 = System.currentTimeMillis();
Log.i("TensorFlowInferenceInterface", "Model load took " + (var7 - var3) + "ms, TensorFlow version: " + TensorFlow.version());
}
}

附注演示应用链接:github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android

我还被提议尝试使用本地代码路径来加载文件:graphsgithub.com/tensorflow/tensorflow/issues/9343#issuecomment-295959477但我对 C++/NDK 不是很好(我只是不使用它)所以有 .cc 文件可用于加载文件。如果有人帮助我将它集成到 TensorFlow 示例 Android 项目中,我将不胜感激。但我仍然希望有没有 NDK 的解决方案,因为 200mb 对于 Android 2016-2017 设备来说真的这么大吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com