Преобразование растрового изображения в массив 4D в Android - PullRequest
0 голосов
/ 10 февраля 2020

Обычно это то, что можно сделать в Python с помощью numpy, но я использую модель tflite, которая может классифицировать изображения в android. Модель принимает массив Float32 Numpy [1] [200] [200] [3] и выводит двумерный массив Float32 [1] [5] . В android мне нужно преобразовать растровое изображение, полученное с камеры, и преобразовать его в массив 4D.

Ниже приведен код, который я до сих пор использовал:

        ImageProcessor imageProcessor =
                new ImageProcessor.Builder()
                        .add(new ResizeOp(200, 200, ResizeOp.ResizeMethod.BILINEAR))
                        .build();

        // Create a TensorImage object, this creates the tensor the TensorFlow Lite
        // interpreter needs
        TensorImage tImage = new TensorImage(DataType.FLOAT32);

        // Analysis code for every frame
        // Preprocess the image
        tImage.load(bitmap);
        tImage = imageProcessor.process(tImage);


        try{
            tflite=new Interpreter(loadModelFile(Camera.this, modelFile));
        } catch (IOException e){
            Log.e("tfliteSupport", "Error reading model", e);
        }

        float prediction = doInferece(tImage);

        // Running inference

    }

    private float doInferece(TensorImage tImage) {
        float[][][][] inputValue = new float[1][200][200][3];
        inputValue = ((float) tImage); //produces error saying: "Cannot cast TensorImage to float"

Заранее спасибо

...