2017-02-22 72 views
2

我試着通過本教程構建.apk文件 - https://www.oreilly.com/learning/tensorflow-on-android爲什麼我會收到錯誤:初始化Tensorflow?

我想用我自己的retrained_graph.pb

我改變ClassifierActivity.java(在教程的一個TensorFlowImageListener.java,但我沒有找到這個文件)。 我換成:

private static final int INPUT_SIZE = 299; 
private static final int IMAGE_MEAN = 128; 
private static final float IMAGE_STD = 128; 
private static final String INPUT_NAME = "Mul:0"; 
private static final String OUTPUT_NAME = "final_result:0"; 

private static final String MODEL_FILE = "file:///android_asset/retrained_graph.pb"; 
private static final String LABEL_FILE = "file:///android_asset/retrained_labels.txt"; 

但是,當我在設備上運行的apk - 它Error initializing TensorFlow崩潰。

D/AndroidRuntime(6524): Shutting down VM 
E/AndroidRuntime(6524): FATAL EXCEPTION: main 
E/AndroidRuntime(6524): Process: org.tensorflow.demo, PID: 6524 
E/AndroidRuntime(6524): java.lang.RuntimeException: Error initializing TensorFlow! 
E/AndroidRuntime(6524): at org.tensorflow.demo.ClassifierActivity.onPreviewSizeChosen(ClassifierActivity.java:130) 
E/AndroidRuntime(6524): at org.tensorflow.demo.CameraActivity$1.onPreviewSizeChosen(CameraActivity.java:158) 
E/AndroidRuntime(6524): at org.tensorflow.demo.CameraConnectionFragment.setUpCameraOutputs(CameraConnectionFragment.java:394) 
E/AndroidRuntime(6524): at org.tensorflow.demo.CameraConnectionFragment.openCamera(CameraConnectionFragment.java:411) 
E/AndroidRuntime(6524): at org.tensorflow.demo.CameraConnectionFragment.access$000(CameraConnectionFragment.java:63) 
E/AndroidRuntime(6524): at org.tensorflow.demo.CameraConnectionFragment$1.onSurfaceTextureAvailable(CameraConnectionFragment.java:94) 
E/AndroidRuntime(6524): at android.view.TextureView.getHardwareLayer(TextureView.java:370) 
E/AndroidRuntime(6524): at android.view.View.updateDisplayListIfDirty(View.java:15443) 
E/AndroidRuntime(6524): at android.view.View.getDisplayList(View.java:15488) 
E/AndroidRuntime(6524): at android.view.View.draw(View.java:16258) 
E/AndroidRuntime(6524): at android.view.ViewGroup.drawChild(ViewGroup.java:3713) 
E/AndroidRuntime(6524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3506) 
E/AndroidRuntime(6524): at android.view.View.updateDisplayListIfDirty(View.java:15461) 
E/AndroidRuntime(6524): at android.view.View.getDisplayList(View.java:15488) 
E/AndroidRuntime(6524): at android.view.View.draw(View.java:16258) 
E/AndroidRuntime(6524): at android.view.ViewGroup.drawChild(ViewGroup.java:3713) 
E/AndroidRuntime(6524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3506) 
E/AndroidRuntime(6524): at android.view.View.draw(View.java:16539) 
E/AndroidRuntime(6524): at android.widget.FrameLayout.draw(FrameLayout.java:598) 
E/AndroidRuntime(6524): at android.view.View.updateDisplayListIfDirty(View.java:15466) 
E/AndroidRuntime(6524): at android.view.View.getDisplayList(View.java:15488) 
E/AndroidRuntime(6524): at android.view.View.draw(View.java:16258) 
E/AndroidRuntime(6524): at android.view.ViewGroup.drawChild(ViewGroup.java:3713) 
E/AndroidRuntime(6524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3506) 
E/AndroidRuntime(6524): at android.view.View.updateDisplayListIfDirty(View.java:15461) 
E/AndroidRuntime(6524): at android.view.View.getDisplayList(View.java:15488) 
E/AndroidRuntime(6524): at android.view.View.draw(View.java:16258) 
E/AndroidRuntime(6524): at android.view.ViewGroup.drawChild(ViewGroup.java:3713) 
E/AndroidRuntime(6524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3506) 
E/AndroidRuntime(6524): at android.view.View.updateDisplayListIfDirty(View.java:15461) 
E/AndroidRuntime(6524): at android.view.View.getDisplayList(View.java:15488) 
E/AndroidRuntime(6524): at android.view.View.draw(View.java:16258) 
E/AndroidRuntime(6524): at android.view.ViewGroup.drawChild(ViewGroup.java:3713) 
E/AndroidRuntime(6524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3506) 
E/AndroidRuntime(6524): at android.view.View.draw(View.java:16539) 
E/AndroidRuntime(6524): at android.widget.FrameLayout.draw(FrameLayout.java:598) 
E/AndroidRuntime(6524): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:3111) 
E/AndroidRuntime(6524): at android.view.View.updateDisplayListIfDirty(View.java:15466) 
E/AndroidRuntime(6524): at android.view.View.getDisplayList(View.java:15488) 
E/AndroidRuntime(6524): at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:309) 
E/AndroidRuntime(6524): at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:315) 
E/AndroidRuntime(6524): at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:354) 
E/AndroidRuntime(6524): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2956) 
E/AndroidRuntime(6524): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2753) 
E/AndroidRuntime(6524): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2339) 
E/AndroidRuntime(6524): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1314) 
E/AndroidRuntime(6524): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7057) 
E/AndroidRuntime(6524): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:829) 
E/AndroidRuntime(6524): at android.view.Choreographer.doCallbacks(Choreographer.java:606) 
E/AndroidRuntime(6524): at android.view.Choreographer.doFrame(Choreographer.java:576) 
E/AndroidRuntime(6524): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:815) 
E/AndroidRuntime(6524): at android.os.Handler.handleCallback(Handler.java:739) 
E/AndroidRuntime(6524): at android.os.Handler.dispatchMessage(Handler.java:95) 
E/AndroidRuntime(6524): at android.os.Looper.loop(Looper.java:145) 
E/AndroidRuntime(6524): at android.app.ActivityThread.main(ActivityThread.java:6917) 
E/AndroidRuntime(6524): at java.lang.reflect.Method.invoke(Native Method) 
E/AndroidRuntime(6524): at java.lang.reflect.Method.invoke(Method.java:372) 
E/AndroidRuntime(6524): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
E/AndroidRuntime(6524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
E/AndroidRuntime(6524): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'org.tensorflow.Output org.tensorflow.Operation.output(int)' o 
W/ActivityManager( 783): Force finishing activity 1 org.tensorflow.demo/.ClassifierActivity 
W/ResourcesManager(6576): Asset path '/system/framework/sec_platform_library.jar' does not exist or contains no resources. 
W/ResourcesManager(6576): Asset path '/system/framework/smatlib.jar' does not exist or contains no resources. 
W/ResourcesManager(6576): Asset path '/system/framework/secvisualeffect.jar' does not exist or contains no resources. 
W/ResourcesManager(6576): Asset path '/system/framework/sechardware.jar' does not exist or contains no resources. 
D/InputDispatcher( 783): Focused application set to: xxxx 
D/InputDispatcher( 783): Focus left window: 6524 
D/PointerIcon( 783): setMouseIconStyle1 pointerType: 1001 iconType:101 flag:0 pid:783 uid:1000 
D/PointerIcon( 783): setMouseCustomIcon IconType is same.101 

我發現這個代碼處理異常:

@Override 
    public void onPreviewSizeChosen(final Size size, final int rotation) { 
    final float textSizePx = 
     TypedValue.applyDimension(
      TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE_DIP, getResources().getDisplayMetrics()); 
    borderedText = new BorderedText(textSizePx); 
    borderedText.setTypeface(Typeface.MONOSPACE); 

    try { 
     classifier = 
      TensorFlowImageClassifier.create(
       getAssets(), 
       MODEL_FILE, 
       LABEL_FILE, 
       INPUT_SIZE, 
       IMAGE_MEAN, 
       IMAGE_STD, 
       INPUT_NAME, 
       OUTPUT_NAME); 
    } catch (final Exception e) { 
     throw new RuntimeException("Error initializing TensorFlow!", e); 
    } 

... 

    } 

tensorflow/tensorflow/examples/android/src/org/tensorflow/demo/ClassifierActivity.java

我已經花了2天,你們幫我請!什麼可能是錯誤的原因?

+1

你能重新發布該錯誤包括整個最後線?目前它停在'E/AndroidRuntime(6524):引起:java.lang.NullPointerException:嘗試調用虛方法'org.tensorflow.Output org.tensorflow.Operation.output(int)'o'這表明有更多的東西可能會提供一些線索。 –

+0

@VladB更新! –

+0

在發佈的部分上方應該有更多的上下文,以幫助分析問題。任何以「adb logcat *:E *:tensorflow *:native」記錄的內容都可能有用。 –

回答

1

我解決了這個問題,在Java代碼中的註釋不被更新,現在只是改變:

private static final String INPUT_NAME = "Mul:0"; 
private static final String OUTPUT_NAME = "final_result:0"; 

要:

private static final String INPUT_NAME = "Mul"; 
private static final String OUTPUT_NAME = "final_result"; 
+0

你讓我的一天!謝謝 –

相關問題