'Error while running subprocess to run yolov5 detect.py file

I need to run detect.py file to detect objects from images in a folder from a python script. When I try running the script I keep getting this pickle invalid load error.

import os
import subprocess


img_fdr="./img"
weights_fdr="/runs/train/exp7/weights/best.pt"

subprocess.run(["python3","detect.py","--weights",weights_fdr,"--source",img_fdr])

I tried several ways of passing the arguments , still I keep getting the same error.

error message



Solution 1:[1]

This line

subprocess.run(["python3","detect.py","--weights",weights_fdr,"--source",img_fdr])

should look like this:

subprocess.run(f"python3 detect.py --weights {weights_fdr} --source {img_fdr}")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gerda die gandalfziege