An image classification model for detecting car crashes from traffic cams. An easier to run version of Crashly is currently in development. To run this model, use the following code snippet.

import numpy as np
from PIL import Image
import tensorflow as tf

# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="{model_name}.tflite")
interpreter.allocate_tensors()

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

input_shape = input_details[0]['shape']

# Load and preprocess image
def load_image(image_path):
    img = Image.open(image_path).convert('RGB')
    img = img.resize([input_shape[1], input_shape[2]])

    img = np.asarray(img, dtype='float32') / 255
    # Return a scaled array between -1 and 1
    return img * 2 - 1

if __name__ == "__main__":
    input_data =  load_image("/tmp/your-image-here.jpg")
    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)
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model is not currently available via any of the supported Inference Providers.