How do I load a yolov5l model with custom weights into torch in python?
I have trained a yolov5l model for object detection and classification. I want to use the exported weights to identify images in a program I am creating. I am having trouble finding much of anything on how to use .pt weights in a python program.
I believe I use the &quot;torch.load&quot; method from the pytorch library, but when I try: torch.load(path_to_weights)
I get a ModuleNotFoundError for not having a module named 'models'.
Any help is much appreciated. Thank you very much.

You should use torch.load_state_dict() method to load your trained parameters to your model in addition to torch.load().
There are some issues with your torch.load() method. You should provide your path parameter as a either string or os.PathLike object. (These are written in the docs).
I am going to provide a simple code block to show you the way.
#Initializing model

model = Model() # Assuming your model's name is Model

model.load_state_dict(torch.load(path_to_weights))

But don't forget that your path_to_weights parameter must be either string or os.PathLike object.
