TensorFlowASR: Call tflitemodel.invoke() makes program crash

I am working on tf lite version of Conformer, but not succeed yet. When I run tests/conformer/test_conformer.py, program crashed in line “tflitemodel.invoke()”. tflitemodel.set_tensor( input_details[2]["index"], tf.zeros( [config.model_config["prediction_num_rnns"], 2, 1, config.model_config["prediction_rnn_units"]], dtype=tf.float32 ) ) tflitemodel.invoke() hyp = tflitemodel.get_tensor(output_details[0]["index"]) Crash Msg is: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

Environment: tensorflow 2.3.2 TensorFlowASR latest

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18

Most upvoted comments

@usimarit Update After a weekend researching, I got some findings:

  1. With TF 2.3.X, tests/conformer/test_conformer.py run failed on all my machines, it may relativate to PAD opertor, @abattery give me this answer: https://github.com/tensorflow/tensorflow/issues/48106#issuecomment-808969122
  2. With TF 2.4.1, tests/conformer/test_conformer.py also run failed with error “InvalidArgumentError: Attempting to add a duplicate function with the name: __inference_standard_lstm_21488”, maybe someone had met this error. If i remove LSTM layer from Pred Network, it works fine.
  3. With TF-nightly (2.5.0-dev20210210), everything works fine 😃

I am closing this issue, thanks

@usimarit In the following simple program, if test function return tf.signal.rfft(x, [512]), program crash, if test function return tf.reshape(x, [10, -1]), it works fine.

import numpy as np
import tensorflow as tf


class Tester(tf.Module):
    def __init__(self):
        super(Tester, self).__init__()

    @tf.function(input_signature=[tf.TensorSpec(shape=[100], dtype=tf.float32)])
    def test(self, x):
        # return tf.reshape(x, [10, -1])
        return tf.signal.rfft(x, [512])


model = Tester()
concrete_func = model.test.get_concrete_function()
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
# converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir='saved_models/pb/model')
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.experimental_new_converter = True
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
tflite = converter.convert()

TFLITE_FILE_PATH = 'content/tester.tflite'
with open(TFLITE_FILE_PATH, 'wb') as f:
    f.write(tflite)

# Load the TFLite model and allocate tensors.
# interpreter = tf.lite.Interpreter(model_path="content/test_variable.tflite")
interpreter = tf.lite.Interpreter(model_content=tflite)
interpreter.allocate_tensors()

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Test the model on random input data.
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)

interpreter.invoke()

# The function `get_tensor()` returns a copy of the tensor data.
# Use `tensor()` in order to get a pointer to the tensor.
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)

The saved tflite model which return tf.signal.rfft(x, [512]) is sharing with url: https://drive.google.com/file/d/1LY3h4MHIwGGi63TyWsNta6vNKluIdi38/view?usp=sharing

Could you download this file and check if it works fine on your machine, thanks