-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Adding detect_flow
and detect_flows
functions
#5649
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
base: main
Are you sure you want to change the base?
Conversation
- detect_flow: detects optical-flow for a single image-pair - detect_flows: detects optical-flow for a series of image-pairs
💊 CI failures summary and remediationsAs of commit 2b67bfa (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
@datumbox I am not sure if the following is the right place to add this code and if this should go under Also, I will post a correction/update to the RAFT demo with these functions. current path: torchvision/models/optical_flow/detector.py |
@sugatoray First of all thanks for the contribution. It's not clear if this should be handled in the references of TorchVision or if this should be a separate utility added on your own repo. That's because we try to keep references as simple as possible and avoid multiple entry points. I will let @NicolasHug who has led the effort of supporting optical flow to provide input about whether specific optimisations of this PR are worth adopting on the current scripts. A couple of notes that will help you maximise the chances of getting your contributions merged: If a PR touches more than 20 lines of code, it's usually recommended to first open an issue and discuss the changes. Discussing the reported issue with the rest of the community can help us decide if it is indeed an problem and how it should be addressed. For more info on the contribution process please check this |
@datumbox Thank you. I will keep the "20 lines" in mind for future. Out of the two functions, Also, for the demo notebook, I could push a separate PR, to include similar changes, but without the specific function in question ( |
return preprocess(frame).to(device) | ||
|
||
|
||
def detect_flow(frameA: Union[Tensor, List[Tensor]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out the Memory issue! @sugatoray
Hi! @NicolasHug will have a deeper look.
I think that we do lot of implicit assumptions. Such as default model, releasing memory (it might not be needed). Folder name, saving etc.
Maybe adding a note to the gallery example suggesting how CUDA Out of Memory error could be handled could help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oke-aditya About the the assumptions on folder name, saving etc., it was necessary to save the files to disk. Now you may argue (as I debated with myself) that it should be perfectly fine returning just the flow_img
and predicted_flow
and let the user handle saving the files to disk. However, given the memory constraints, it might be useful, if you could just conveniently specify whether you want to save the raw and processed flow data to disk, or you want them returned as well.
Given, you have this function, detect_flow
it all boils down to a single function call for generating optical flows. On the other hand, detect_flows
handles the same for multiple images, which you can now create a video/gif file from.
So, yes, I had envisioned them as parts of utils/
. But, just to begin with, pushed the initial commit to torchvision/models/optical_flow/
.
Thanks a lot for the PR @sugatoray . As @datumbox already noted, this kind of util is usually not included in the
Could you please provide us with some details here? If the example runs out of memory, perhaps there's an issue that we can fix directly there :) |
@NicolasHug Yes, it ran out of memory. This is why I used |
@datumbox So, will it be okay if I move the functions |
@sugatoray Would you mind providing the exact code that caused the memory to run out? If possible, do you still have the error trace? I'm fairly surprised that our example causes a OOM issue, because we're only doing 2 predictions. |
@NicolasHug The memory limit was struck when I tried running the last section to create multiple frames in a loop. Also the for loop had some obvious typos. |
Thanks for the details @sugatoray . We'll be happy to review a PR that fixes these issues in the example. As noted there, this snippet that we commented out is only a starting point, not a full fledge solution. |
@NicolasHug I will send a PR with the fixes to the snippet section. |
@sugatoray Shall we close this PR? I understand we are going ahead with a different approach, right? |
@datumbox Would it be possible to leave this PR to remain open for the time being, while I work on the other PR and submit it? But, I was wondering if these functions could be added to Thank you. |
@sugatoray Happy to leave the PR open if you prefer. Please consider closing it once you are happy with the other PR to keep things tidy. From @NicolasHug's response, I understand that this is not something we probably want on the |
I'm not sure yet whether this would make sense as a util in the references either. It will depend on what are the needed changes to the snippet from the example, and why the changes are needed. It's important to keep in mind that the snippet is really a starting point, it doesn't pretend to be anything else, and there might be blind spots. The typos mentioned by @sugatoray are definitely worth fixing though. |
@datumbox and @NicolasHug Let me send the PR to introduce minimal changes to the RAFT example. Once it is working and the example is updated, perhaps you can take a more objective call on whether the functions in this PR are appropriate for
Does that sound reasonable to you? |
Sounds good but this is definitely something we can't put on |
Added the following two functions to allow users easily create optical flow and optionally save the data (as images and as
.pt
data files respectively).detect_flow
: detects optical-flow for a single image-pairdetect_flows
: detects optical-flow for a series of image-pairsThe
detect_flow()
function makes sure of managing memory (grabage collection + emptying cuda cache), while evaluating and saving optical flow information on a pair of images. When I tried running the RAFT demo to create a series of optical-flow images, I found the colab notebook running out of memory. These functions take care of the memory aspect and make it easier for the user to apply optical flow on image-pairs.Gif Source: LinkedIn Post