Beyond Generative AI Applications

Beyond Generative AI Applications

SeekrFlow can also be used for general machine learning applications such as object detection, image classification, image segmentation, and text classification.

SeekrFlow provides an easy-to-use API to optimize your ML model to run on all supported platforms mentioned above. In this example, we will deploy a YOLO ("You Only Look Once") model for object detection in just 3 lines of code.

YOLO is a type of convolutional neural network for object detection tasks that is well-known for its speed and accuracy in detecting objects in real-time.

If you have a local YOLO model, feel free to use it, otherwise you can download an example trained on COCO from here:

wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8x.pt
import os
from seekrai import SeekrFlow

client = SeekrFlow(api_key=os.environ.get("SEEKR_API_KEY"))

model = client.models.upload("yolov8x.pt", model_type="object_detection")
client.models.promote(model.id)
client.models.predict(model.id, file="persons.jpg")

Here, we have fine-tuned YOLOv8 on the shipsnet from Kaggle. Let's try it on this image:

model = client.models.upload("best.pt", model_type="object_detection")
client.models.promote(model.id)
client.models.predict(model.id, file="ship.jpg")
# Get a list of all the image files in the training images directory
image_files = os.listdir(train_images)

# Choose 16 random image files from the list
random_images = random.sample(image_files, 16)

# Set up the plot
fig, axs = plt.subplots(4, 4, figsize=(16, 16))

# Loop over the random images and plot the object detections
for i, image_file in enumerate(random_images):
    row = i // 4
    col = i % 4

    # Load the image
    image_path = os.path.join(train_images, image_file)
    image = cv2.imread(image_path)

    # Load the labels for this image
    label_file = os.path.splitext(image_file)[0] + ".txt"
    label_path = os.path.join(train_labels, label_file)
    with open(label_path, "r") as f:
        labels = f.read().strip().split("\n")

    # Loop over the labels and plot the object detections
    for label in labels:
        if len(label.split()) != 5:
            continue
        class_id, x_center, y_center, width, height = map(float, label.split())
        x_min = int((x_center - width/2) * image.shape[1])
        y_min = int((y_center - height/2) * image.shape[0])
        x_max = int((x_center + width/2) * image.shape[1])
        y_max = int((y_center + height/2) * image.shape[0])
        cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 255, 0), 3)


    # Show the image with the object detections
    axs[row, col].imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
    axs[row, col].axis('off')

plt.show()

Demote the model when finished using it:

client.models.demote(model.id)