(Android / Tensorflow)打开CameraActivity时活动崩溃

时间:2018-01-30 00:14:44

标签: java android tensorflow

我正在使用Tensorflow创建一个Android图像分类应用程序。当我尝试运行read时,活动崩溃了。我已经参考此链接来开发我的应用https://github.com/MindorksOpenSource/AndroidTensorFlowMachineLearningExample。我不确定有什么问题,所以我可以知道如何解决这个问题?

Logcat错误:CameraActivity.java

调试错误:

Could not load vendor/lib/egl/libGLES_mali_v2.so from sphal namespace: dlopen failed: library "vendor/lib/egl/libGLES_mali_v2.so" not found.

调试错误行:FATAL EXCEPTION: pool-1-thread-1 Process: com.example.nicholas.herb_recognition_test, PID: 15136 java.lang.RuntimeException: Error initializing TensorFlow! at CameraActivity$5.run(CameraActivity.java:122)

错误:classifier = TensorFlowImageClassifier.create

CameraActivity.java

java.util.concurrent.ThreadPoolExecutor.runWorker

TensorFlowImageClassifier.java

public class CameraActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);
    cameraView = (CameraView) findViewById(R.id.cameraView);
    imageViewResult = (ImageView) findViewById(R.id.imageViewResult);
    textViewResult = (TextView) findViewById(R.id.textViewResult);
    textViewResult.setMovementMethod(new ScrollingMovementMethod());

    btnToggleCamera = (Button) findViewById(R.id.btnToggleCamera);
    btnDetectObject = (Button) findViewById(R.id.btnDetectObject);

    cameraView.setCameraListener(new CameraListener() {
        @Override
        public void onPictureTaken(byte[] picture) {
            super.onPictureTaken(picture);

            Bitmap bitmap = BitmapFactory.decodeByteArray(picture, 0, picture.length);

            bitmap = Bitmap.createScaledBitmap(bitmap, INPUT_SIZE, INPUT_SIZE, false);

            imageViewResult.setImageBitmap(bitmap);

            final List<Classifier.Recognition> results = classifier.recognizeImage(bitmap);

            textViewResult.setText(results.toString());
        }
    });

    btnToggleCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cameraView.toggleFacing();
        }
    });

    btnDetectObject.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cameraView.captureImage();
        }
    });

    initTensorFlowAndLoadModel();
}
private void initTensorFlowAndLoadModel() {
    executor.execute(new Runnable() {
        @Override
        public void run() {
            try {
                classifier = TensorFlowImageClassifier.create(
                        getAssets(),
                        MODEL_FILE,
                        LABEL_FILE,
                        INPUT_SIZE,
                        IMAGE_MEAN,
                        IMAGE_STD,
                        INPUT_NAME,
                        OUTPUT_NAME);
                makeButtonVisible();
            } catch (final Exception e) {
                throw new RuntimeException("Error initializing TensorFlow!", e);
            }
        }
    });
}
}

}

2 个答案:

答案 0 :(得分:0)

似乎我的模型文件与TensorFlowImageClassifier.java中实现的体系结构模型存在一些兼容性问题。

答案 1 :(得分:0)

只需将INPUT_NAME和OUTPUT_NAME更改为:

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

它对我有用