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);
            TensorBuffer inputFeature1 = TensorBuffer.createFixedSize(new int[]{1, 4096}, DataType.FLOAT32);

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

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

1 Answer 1


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);
ByteBuffer byteBuffer = tensorImage.getBuffer();

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.