• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

Converting a ByteBuffer to segmentation map in tflite Android app

April 10, 2020 by

Questions › Converting a ByteBuffer to segmentation map in tflite Android app
0
Vote Up
Vote Down
Garmaine asked 3 years ago

I have a pretrained semantic segmentation model for tflite. It takes input image of shape 1x224x224x3 while gives the softmax output for three classes of shape 1x50176x3. It works okay in Python as intended. I take argmax for last dimension and reshape 50176 size vector to 224x224 and then for each value in the matrix, I map it to the index of colormap to get segmentation map and show it as overlay on the original image. I have ported the tflite model to Android app and now I am giving the input and taking the output as following:

private static final int[] colormap = {
        0x00000000,     //background
        0x99ffe119,     //healthy
        0x993cb44b,     //disease
};

imgData = ByteBuffer.allocateDirect(4 * 1 * 224 * 224 * 3);
imgData.order(ByteOrder.nativeOrder());
outputBuffer = ByteBuffer.allocateDirect(1 * 50176 * 3 * 4);
outputBuffer.order(ByteOrder.nativeOrder());
convertBitmapToByteBuffer(bitmap);


results = tflite.run(imgData, outputBuffer);

// To Do: Take argmax of outputBuffer. Reshape it to 224x224 and map to the colors to get segmentation map. 
// Show it on original image as overlay.

I have two questions. Is it the right approach to allocate ByteBuffers for both input image and output?

Secondly, how do I map the output ByteBuffer to the segmentation map, similar to the Python counter part?

I am a bit comfortable with working on arrays but when I convert the outputBuffer to array, it gives me unexpected random values as output! May be there is a better way to achieve the goal. I am stuck here for couple of days and have no clue on how to get the result similar to the attached image (which is taken from my Python implementation). A little help would be appreciated.

enter image description here

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: android, image-segmentation, java, semantic-segmentation, tf-lite

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023