Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@usyntest
Copy link
Contributor

@usyntest usyntest commented Jan 23, 2024

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

fix: #24424 Update DNN Optical Flow sample with RAFT model
I implemented both RAFT and FlowNet v2 leaving it to the user which one he wants to use to estimate the optical flow.

@fengyuentau
Copy link
Member

Thank you for your contribution! Have you run these two models with dnn and record the inference speed? I would like to know which runs faster.

@asmorkalov asmorkalov requested a review from dkurt January 24, 2024 15:53
@usyntest
Copy link
Contributor Author

Have you run these two models with dnn and record the inference speed? I would like to know which runs faster

Average Inference Time for FlowNet v2: 0.83 seconds per frame
Average Inference Time for RAFT: 1.2 seconds per frame

This is how I calculated

start_time = cv.getTickCount()
flow = self.net.forward()
end_time = cv.getTickCount()
inference_time = (end_time - start_time) / cv.getTickFrequency()
self.total_time += inference_time
avg_time = opt_flow.total_time / num_frames

I used the model weights mentioned in the sample code file.

@fengyuentau
Copy link
Member

Have you run these two models with dnn and record the inference speed? I would like to know which runs faster

Average Inference Time for FlowNet v2: 0.83 seconds per frame Average Inference Time for RAFT: 1.2 seconds per frame

This is how I calculated

start_time = cv.getTickCount()
flow = self.net.forward()
end_time = cv.getTickCount()
inference_time = (end_time - start_time) / cv.getTickFrequency()
self.total_time += inference_time
avg_time = opt_flow.total_time / num_frames

I used the model weights mentioned in the sample code file.

That's useful information. Thank you!

caffemodel = open(args.model, 'rb').read()
opt_flow = OpticalFlow(caffemodel, var['ADAPTED_HEIGHT'], var['ADAPTED_WIDTH'], bytearray(config.encode()))
else:
opt_flow = OpticalFlow(args.model, 360, 480)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use args.height and args.width

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model weights/trained model I acquired takes the input of 360x480 only, that's why I had to hard code these values.

Screenshot 2024-01-27 at 12 09 44 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think I should leave this as it is? Or, should I find a new model or train a new model?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that 360x480 gives the best accuracy but using lower resolutions might be faster. But yes, let’s keep original shapes and merge this PR.

@usyntest
Copy link
Contributor Author

@fengyuentau If there are no reviews can you approve these changes, so this PR can be merged?

Copy link
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@asmorkalov asmorkalov merged commit 0399416 into opencv:4.x Jan 29, 2024
@usyntest usyntest deleted the optical-flow-sample-raft branch January 29, 2024 16:10
JStech pushed a commit to JStech/opencv that referenced this pull request Jan 29, 2024
Raft support added in this sample code opencv#24913

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake

fix: opencv#24424 Update DNN Optical Flow sample with RAFT model
I implemented both RAFT and FlowNet v2 leaving it to the user which one he wants to use to estimate the optical flow.

Co-authored-by: Uday Sharma <[email protected]>
@asmorkalov asmorkalov mentioned this pull request Feb 3, 2024
@asmorkalov asmorkalov mentioned this pull request Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update DNN Optical Flow sample with RAFT model

4 participants