Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – what should be the input and output forom of variables for float object detection model

Posted on November 11, 2022 By

Solution 1 :

I use colaboratory. So I use below code to determine inputs and outputs:

import tensorflow as tf
interpreter = tf.lite.Interpreter('mobilenet_ssd.tflite')
print(interpreter.get_input_details())
print(interpreter.get_output_details())

So unzip the folder, find the file and load it with above code. I did that with above code and the result was:

[{‘name’: ‘Preprocessor/sub’, ‘index’: 165, ‘shape’: array([ 1, 300, 300, 3], dtype=int32), ‘shape_signature’: array([ 1, 300, 300, 3], dtype=int32), ‘dtype’: , ‘quantization’: (0.0, 0), ‘quantization_parameters’: {‘scales’: array([], dtype=float32), ‘zero_points’: array([], dtype=int32), ‘quantized_dimension’: 0}, ‘sparsity_parameters’: {}}]

[{‘name’: ‘concat’, ‘index’: 172, ‘shape’: array([ 1, 1917, 4], dtype=int32), ‘shape_signature’: array([ 1, 1917, 4], dtype=int32), ‘dtype’: , ‘quantization’: (0.0, 0), ‘quantization_parameters’: {‘scales’: array([], dtype=float32), ‘zero_points’: array([], dtype=int32), ‘quantized_dimension’: 0}, ‘sparsity_parameters’: {}}, {‘name’: ‘concat_1’, ‘index’: 173, ‘shape’: array([ 1, 1917, 91], dtype=int32), ‘shape_signature’: array([ 1, 1917, 91], dtype=int32), ‘dtype’: , ‘quantization’: (0.0, 0), ‘quantization_parameters’: {‘scales’: array([], dtype=float32), ‘zero_points’: array([], dtype=int32), ‘quantized_dimension’: 0}, ‘sparsity_parameters’: {}}]

Also inside android you can do:

// Initialize interpreter
@Throws(IOException::class)
private suspend fun initializeInterpreter(app: Application) = withContext(Dispatchers.IO) {
    // Load the TF Lite model from asset folder and initialize TF Lite Interpreter without NNAPI enabled.
    val assetManager = app.assets
    val model = loadModelFile(assetManager, "mobilenet_ssd.tflite")
    val options = Interpreter.Options()
    options.setUseNNAPI(false)
    interpreter = Interpreter(model, options)
    // Reads type and shape of input and output tensors, respectively.
    val imageTensorIndex = 0
    val inputShape: IntArray =
        interpreter.getInputTensor(imageTensorIndex).shape() // {1, length}
    Log.e("INPUT_TENSOR_WHOLE", Arrays.toString(inputShape))
    val imageDataType: DataType =
        interpreter.getInputTensor(imageTensorIndex).dataType()
    Log.e("INPUT_DATA_TYPE", imageDataType.toString())

    //modelInputSize indicates how many bytes of memory we should allocate to store the input for our TensorFlow Lite model.
    //FLOAT_TYPE_SIZE indicates how many bytes our input data type will require. We use float32, so it is 4 bytes.
    //PIXEL_SIZE indicates how many color channels there are in each pixel. Our input image is a colored image, so we have 3 color channel.
    inputImageWidth = inputShape[1]
    inputImageHeight = inputShape[2]
    modelInputSize = FLOAT_TYPE_SIZE * inputImageWidth *
            inputImageHeight * PIXEL_SIZE

    val probabilityTensorIndex = 0
    outputShape =
        interpreter.getOutputTensor(probabilityTensorIndex).shape()// {1, NUM_CLASSES}
    Log.e("OUTPUT_TENSOR_SHAPE", outputShape.contentToString())
    val probabilityDataType: DataType =
        interpreter.getOutputTensor(probabilityTensorIndex).dataType()
    Log.e("OUTPUT_DATA_TYPE", probabilityDataType.toString())
    isInitialized = true
    Log.e(TAG, "Initialized TFLite interpreter.")


    // Inputs outputs
    /*val inputTensorModel: Int = interpreter.getInputIndex("input_1")
    Log.e("INPUT_TENSOR", inputTensorModel.toString())*/

}

@Throws(IOException::class)
private fun loadModelFile(assetManager: AssetManager, filename: String): MappedByteBuffer {
    val fileDescriptor = assetManager.openFd(filename)
    val inputStream = FileInputStream(fileDescriptor.fileDescriptor)
    val fileChannel = inputStream.channel
    val startOffset = fileDescriptor.startOffset
    val declaredLength = fileDescriptor.declaredLength
    return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength)
}

If you need any help tag me.

READ  [FIXED] Wordpress ecommerce site and Android Studio app integration
Powered by Inline Related Posts

Problem :

https://storage.googleapis.com/download.tensorflow.org/models/tflite/mobilenet_ssd_tflite_v1.zip

I am making an android object detection app with gpu delegate support.
The above link is for tensorflow lite object detection float model.
There is no documentation available for this. I want to know the input and output form of the variables for this tflite models so that i can feed it to the interpreter for gpu delegation.
Thanks in advance!

Comments

Comment posted by Farmaker

I printed with above code the results. Check edited answer with the code I provided.

Comment posted by stackoverflow.com/questions/62373305/…

Thanks for the help. I would appreciate if you could answer this

Android Tags:android, kotlin-android-extensions, mobilenet, object-detection-api, tensorflow-lite

Post navigation

Previous Post: [FIXED] Android Studios error : Unable to locate adb location
Next Post: [FIXED] android – Here Maps Navigation samples seem to be missing the Navigation Library

Related Posts

[FIXED] android – how to add ainmation in GoRouter flutter Android
[FIXED] Is it possible to set image to ImageView from a path (external storage) on Android 10 and higher? Android
[FIXED] How can we validate IMEI Number after Android version 10? Android
[FIXED] android – AndroidX: Set Enter key to validate EditTextPreference dialog box Android
[FIXED] android – Caching videos Firestore Android
[FIXED] android – Is there any way of integrating react native with mediapipe? Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme