1
$\begingroup$

I am trying to serve an image caption model based on flickr8k dataset using TensorFlow lite in the android app. I am new to Android App development and stuck at the below code where I need to provide input to Feature0 and Feature1 to my model.

Can someone please guide me how to do so?

try {
            Model3 model = Model3.newInstance(MainActivity.this);

            // Creates inputs for reference.
            TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 37}, DataType.FLOAT32);
            inputFeature0.loadBuffer(byteBuffer);
            TensorBuffer inputFeature1 = TensorBuffer.createFixedSize(new int[]{1, 4096}, DataType.FLOAT32);
            inputFeature1.loadBuffer(byteBuffer);

            // Runs model inference and gets result.
            Model3.Outputs outputs = model.process(inputFeature0, inputFeature1);
            TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();

            // Releases model resources if no longer used.
            model.close();
        } catch (IOException e) {
            // TODO Handle the exception
        }
$\endgroup$

1 Answer 1

0
$\begingroup$

First you need to convert you image to bitmap. Then covert your bitmap into a bytebuffer

TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 37}, DataType.FLOAT32);
TensorImage tensorImage = new TensorImage(DataType.FLOAT32);
tensorImage.load(bitmap);
ByteBuffer byteBuffer = tensorImage.getBuffer();
inputFeature0.loadBuffer(byteBuffer);
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.