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

suggestions for integration? #910

Closed
jinzishuai opened this issue Sep 4, 2020 · 5 comments
Closed

suggestions for integration? #910

jinzishuai opened this issue Sep 4, 2020 · 5 comments
Labels
question Further information is requested Stale

Comments

@jinzishuai
Copy link

jinzishuai commented Sep 4, 2020

❔Question

I would like to start using yolov5 in my own project. So far, I haven't found a straight forward way and I had to copy and commit the yolov5 source into my own and start hacking it. I want to know if there is some best practices on how to use yolov5 in other projects.

I wonder if the following is possible

  • create python package using setuptools
  • publish releases in pypi.org so that people could simply do pip install yolov5 to get this module.

Additional context

I am also looking for an API that might take an OpenCV image as input and output a list of detected objects. Right now, all I see from the detect.py is the detect() function that takes images/video files or webcam streams. In my application (I would imagine many others as well), we want to handle the video stream ourselves and do other operations and also don't want to save the images to temporary files. It would be super cool if there is an easy to use function to just do that. I am sure if I take the detect() function apart, I could isolate the a few steps output (which is kind of what I have done). But if this API is offered as part of the python package, then all we might have to do in the future might be

  • import yolov5
  • call yolov5.detect(input_image)

Finally, I truly appreciate this open source effort and would love to contribute if there is some guidance.

@jinzishuai jinzishuai added the question Further information is requested label Sep 4, 2020
@NanoCode012
Copy link
Contributor

Hi, I've definitely seen an attempt PR to do so here #465 (comment) and here #668 .

also don't want to save the images to temporary files

I think you just changed the line below, it should not save images anymore. You can pass "--save-txt" to get the predictions.

save_img = True

In my application (I would imagine many others as well), we want to handle the video stream ourselves and do other operations

I think you could write your custom Dataloader and simply replace here.

yolov5/detect.py

Lines 47 to 55 in 44cdcc7

# Set Dataloader
vid_path, vid_writer = None, None
if webcam:
view_img = True
cudnn.benchmark = True # set True to speed up constant image size inference
dataset = LoadStreams(source, img_size=imgsz)
else:
save_img = True
dataset = LoadImages(source, img_size=imgsz)

and output a list of detected objects

yolov5/detect.py

Lines 99 to 109 in 44cdcc7

# Print results
for c in det[:, -1].unique():
n = (det[:, -1] == c).sum() # detections per class
s += '%g %ss, ' % (n, names[int(c)]) # add to string
# Write results
for *xyxy, conf, cls in reversed(det):
if save_txt: # Write to file
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
with open(txt_path + '.txt', 'a') as f:
f.write(('%g ' * 5 + '\n') % (cls, *xywh)) # label format

@glenn-jocher
Copy link
Member

glenn-jocher commented Sep 4, 2020

@jinzishuai thanks for the suggestions! There is a PR for a pip package as mentioned. We paused work on that at the time but I think the repo is nearing a more mature state that we might look at that again soon, for the convenience perspective as you mentioned. Perhaps you could review the PR and submit any comments you have.

The closest functionality now is torch hub, which only requires torch dependency: https://docs.ultralytics.com/yolov5

import torch

yolov5s = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
detections = yolov5s(image)

@jinzishuai
Copy link
Author

jinzishuai commented Sep 10, 2020

@glenn-jocher I'll have to look more into the torch hub idea. In the same time, I am more than happy to review and test the PR for the pip package. Do you know where it is? I didn't find it.

Thanks a lot.

@glenn-jocher
Copy link
Member

@jinzishuai pip package PR is here: #465

Needs to be dusted off and updated.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

3 participants