Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check FPS #12414

Closed
1 task done
AbhishekPSI7042 opened this issue Nov 22, 2023 · 5 comments
Closed
1 task done

Check FPS #12414

AbhishekPSI7042 opened this issue Nov 22, 2023 · 5 comments
Labels
question Further information is requested

Comments

@AbhishekPSI7042
Copy link

Search before asking

Question

I want check FPS also while running the detect.py. So, I have added this code in my detect.py is it right or not please tell me.

Stream results

im0 = annotator.result()
fps_text = f"FPS: {1 / dt[1].dt:.2f}"
cv2.putText(im0, fps_text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)

Additional

No response

@AbhishekPSI7042 AbhishekPSI7042 added the question Further information is requested label Nov 22, 2023
@glenn-jocher
Copy link
Member

@AbhishekPSI7042 you can calculate FPS by adding the following code to your detect.py after im0 = annotator.result():

fps_text = f"FPS: {1 / dt[1].dt:.2f}"
cv2.putText(im0, fps_text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)

Your implementation looks correct! This will display the FPS on the output image. Remember to import cv2 if you haven't already. For more details, refer to the documentation at https://docs.ultralytics.com/yolov5/. Keep up the great work!

@AbhishekPSI7042
Copy link
Author

@glenn-jocher hey, thanks I have another question I wan to save my model into fp16 in pytorch format how can do that. And can we improve the fps on cpu currently I'm getting 27fps on my cpu with image size 360 is there any other way to increase fps?

@glenn-jocher
Copy link
Member

@AbhishekPSI7042 you can save the model in fp16 format using PyTorch's torch.save function with torch.half dtype. To increase FPS on CPU, try reducing the image size or using a smaller model variant like YOLOv5s. Keep in mind, increasing FPS on CPU may sacrifice accuracy or vice versa. Always refer to the YOLOv5 documentation at https://docs.ultralytics.com/yolov5/ for best practices. Good luck!

@AbhishekPSI7042
Copy link
Author

@glenn-jocher how can I save the model in pytorch because when I use export.py there is no way to save model in .pt format in fp16.

@glenn-jocher
Copy link
Member

@AbhishekPSI7042 To save the model in PyTorch's .pt format with fp16 precision, you can directly use PyTorch's torch.save function and specify the dtype as torch.half for the model's state dict. For example:

model.half()  # Convert model to half precision
torch.save(model.state_dict(), 'model_fp16.pt')  # Save model with fp16 precision

This will save the model with fp16 precision in .pt format. For more details, refer to the YOLOv5 documentation at https://docs.ultralytics.com/yolov5/. Keep exploring and feel free to reach out with any more questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants