Run Yolov5 model in Max engine using Mojo

  Kiến thức lập trình

Issues in loading and compiling the yolov5s.torchscript model in MAX Engine using Mojo.
Referred the documents at https://docs.modular.com/max/mojo/get-started and https://docs.modular.com/max/model-formats, was not able to load the yolov5s model to perform object detection.
Also tried loading the model by referring to the recent published article(https://www.modular.com/blog/bring-your-own-pytorch-model) leading to no success.

# Import necessary modules from MAX Engine
from max.engine import InferenceSession

# Define the main function (entry point)
def main():
    # Specify the path to your TorchScript model file
    var model_path = "/home/user/yolov5s.torchscript"

    # Create an instance of InferenceSession
    var session = InferenceSession()

    # Load the model
    var model = session.load(model_path)

    # Print model information (optional)
    print("Model loaded successfully.")

Tried the above code (worked without errors in the Mojo REPL) and got
mojo user :~$ mojo load_model.mojo
Compiling model…..
Done!
Unhandled exception caught during execution: Torch model is dynamic but does not have input specs set! Please set input specs before compiling the model.
mojo: error: execution exited with a non-zero result: 1

New contributor

Krisha Kapadia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT