I have quantized model with float32. After making tflite model it’s predicting perfectly with single image but when using in while loop it’s showing an error. I tried to follow the instruction of TensorFlow here but didn’t understand their way.
CODE:
def generate_frames(frame):
    while True:

        image = cv2.resize(frame,(256,256))

        #converting into float32
        image = tf.image.convert_image_dtype((image/255.0), dtype=tf.float32).numpy()

        image = run_inference(np.expand_dims(image[:,:,:3], axis=0)) 

        final_result = (image*255).astype(np.uint8)
        
        ret,buffer=cv2.imencode('.jpg',final_result)

        frame=buffer.tobytes()

        return frame


#load model
def load_trained_model():
    global interpreter, input_details, output_details
    interpreter = tf.lite.Interpreter(model_path="quant_model.tflite")
    interpreter.allocate_tensors()
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()


def run_inference(image):
    # perform inference and parse the outputs
    interpreter.set_tensor(input_details[0]['index'], image)
    interpreter.invoke()
    outputs = interpreter.get_tensor(output_details[0]['index'])[0]

    return outputs

if __name__ == '__main__':
    load_trained_model()    
    app.run(debug=True)

ERROR:

RuntimeError: There is at least 1 reference to internal data in the
interpreter in the form of a NumPy array or slice. Be sure to only
hold the function returned from tensor() if you are using raw data
access.