torch.hub.load very inaccurate compared to running command for yolov7

26 views Asked by At

I've custom trained a yolov7 model. The training process took place in the command prompt like python train.py --workers 1 --device 0 --batch-size 1 --epochs 20 --img 225 225 --data data/custom_data.yaml --hyp data/hyp.scratch.custom.yaml --cfg cfg/training/yolov7-custom.yaml --name v7-card1 --weights best.pt. I reached an accuracy of around 0.8.

When I test it in the command line like python detect.py --weights best.pt --conf 0.5 --img-size 225 --source name.jpg --view-img --no-trace, it gives me good results.

But when I run the same best.pt inside a python file, It gives me very inaccurate results. I need to run it inside python bcuz I want it to access my webcam etc., but I can't get similar results as the command line. Does anyone know why this is happening? Here's the python code:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
path = r'C:/**path....'
model = torch.hub.load("WongKinYiu/yolov7","custom",f"{path}",trust_repo=True)
img_path = "test/paper191.jpg"
results = model(img_path).pandas().xyxy
0

There are 0 answers