0

I am trying to find how I can pass a dynamic-sized array (not fixed size) into my TensorFlow.

I am building an Android App to read Accelerometer values and predict an activity. I have built a TensorFlow model and am able to successfully import .tflite file into my Android.

converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()

# save the model
with open("model-v2.tflite", "wb") as f:
    f.write(tflite_model)

In my case, the number of Accelerometer X, Y, Z values I would be passing to my TensorFlow model will vary each time. I could pass a series of 10 values or 100 values. So I am trying to find how I can make the TensorFlow model accept a dynamic-sized array instead of a fixed size.

I am new to TensorFlow. So is this something that can be easily achieved?

SyncMaster
  • 9,754
  • 34
  • 94
  • 137
  • 1
    To my knowledge you are restricted to fixed inputs and outputs with Tensorflow. Similar: [How to train with inputs of variable size?](https://stackoverflow.com/q/46179973/295004) If you are doing over-time data, look at how audio processing is handled, or [text processing](https://www.tensorflow.org/tutorials/keras/text_classification). – Morrison Chang Feb 05 '23 at 22:08

1 Answers1

0

Assuming you are following the latest steps to use TFLite as of 2023, you would be able to achieve somewhat dynamic behaviors using tf.function by setting a TensorShape with some Nones in it. An example from the steps mentioned above:

  @tf.function(input_signature=[
      tf.TensorSpec([None, IMG_SIZE, IMG_SIZE], tf.float32),
  ])
  def infer(self, x):
StevenHe
  • 262
  • 4
  • 4