-
Notifications
You must be signed in to change notification settings - Fork 0
Yolo examples updates #13
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| #include "inference.h" | ||
| #include <thread> | ||
| #include <future> | ||
|
|
||
| #include <gflags/gflags.h> | ||
|
|
||
|
|
@@ -97,32 +99,94 @@ int main(int argc, char** argv) { | |
| unsigned long long iters = 0; | ||
| // Show progress every 10% | ||
| unsigned long long progress_bar_tick = std::round(video_lenght / 10); | ||
|
|
||
| struct frame_ctx { | ||
| cv::Mat frame; | ||
| cv::Mat scaled_input; | ||
| cv::Mat blob; | ||
| int pad_x; | ||
| int pad_y; | ||
| float scale; | ||
| }; | ||
| std::queue<frame_ctx*> ready_q; | ||
| std::queue<std::pair<frame_ctx*, std::future<cv::Mat>>> scale_q; | ||
| std::queue<std::pair<frame_ctx*, std::future<std::shared_ptr<executorch::aten::Tensor>>>> input_q; | ||
| std::queue<std::pair<frame_ctx*, std::future<executorch::aten::Tensor>>> execute_q; | ||
| std::queue<std::pair<frame_ctx*, std::future<std::vector<Detection>>>> output_q; | ||
| const et_timestamp_t before_execute = et_pal_current_ticks(); | ||
| size_t frame_queue_size = 2; | ||
| while (true) { | ||
| cv::Mat frame; | ||
| cap >> frame; | ||
|
|
||
| if (frame.empty()) | ||
| if (frame.empty() && ready_q.empty() && scale_q.empty() && input_q.empty() && execute_q.empty() && output_q.empty()) | ||
| break; | ||
|
|
||
| const et_timestamp_t before_execute = et_pal_current_ticks(); | ||
| std::vector<Detection> output = | ||
| infer_yolo_once(yolo_module, frame, img_dims, DEFAULT_YOLO_CONFIG); | ||
| if (!frame.empty()) { | ||
| frame_ctx *new_frame_ctx = new frame_ctx; | ||
| new_frame_ctx->frame = frame; | ||
| ready_q.push(new_frame_ctx); | ||
| } | ||
|
|
||
| for (auto& detection : output) { | ||
| draw_detection(frame, detection, cv::Scalar(0, 0, 255)); | ||
| while (!ready_q.empty() && scale_q.size() < frame_queue_size) { | ||
| frame_ctx *scale_f = ready_q.front(); | ||
| scale_q.push(std::make_pair(scale_f, std::async(std::launch::async, scale_with_padding, std::ref(scale_f->frame), &(scale_f->pad_x), &(scale_f->pad_y), &(scale_f->scale), img_dims))); | ||
| ready_q.pop(); | ||
| } | ||
| const et_timestamp_t after_execute = et_pal_current_ticks(); | ||
| time_spent_executing += after_execute - before_execute; | ||
| iters++; | ||
|
|
||
| if (!(iters % progress_bar_tick)) { | ||
| const int precent_ready = (100 * iters) / video_lenght; | ||
| std::cout << iters << " out of " << video_lenght | ||
| << " frames are are processed (" << precent_ready << "\%)" | ||
| << std::endl; | ||
| while (!scale_q.empty() && input_q.size() < frame_queue_size) { | ||
| auto status = scale_q.front().second.wait_for(std::chrono::milliseconds(1)); | ||
| if (status == std::future_status::ready) { | ||
|
Comment on lines
+131
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General questions:
In general - could you please state the motives behind this PR? What are the purpose and improvements this PR introducing?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks |
||
| scale_q.front().first->scaled_input = scale_q.front().second.get(); | ||
| input_q.push(std::make_pair(scale_q.front().first, std::async(std::launch::async, prepare_input, std::ref(scale_q.front().first->scaled_input), std::ref(scale_q.front().first->blob), img_dims))); | ||
| scale_q.pop(); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| while (!input_q.empty() && execute_q.size() < frame_queue_size) { | ||
| auto status = input_q.front().second.wait_for(std::chrono::milliseconds(1)); | ||
| if (status == std::future_status::ready) { | ||
| std::shared_ptr<executorch::aten::Tensor> prepared_input = input_q.front().second.get(); | ||
| execute_q.push(std::make_pair(input_q.front().first, std::async(std::launch::async, execute_frame, std::ref(yolo_module), prepared_input))); | ||
| input_q.pop(); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| while (!execute_q.empty() && output_q.size() < frame_queue_size) { | ||
| auto status = execute_q.front().second.wait_for(std::chrono::milliseconds(1)); | ||
| if (status == std::future_status::ready) { | ||
| executorch::aten::Tensor raw_output = execute_q.front().second.get(); | ||
| output_q.push(std::make_pair(execute_q.front().first, std::async(std::launch::async, process_output, std::ref(raw_output), DEFAULT_YOLO_CONFIG, execute_q.front().first->pad_x, execute_q.front().first->pad_y, execute_q.front().first->scale))); | ||
| execute_q.pop(); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| while (!output_q.empty()) { | ||
| auto status = output_q.front().second.wait_for(std::chrono::milliseconds(1)); | ||
| if (status == std::future_status::ready) { | ||
| std::vector<Detection> output = output_q.front().second.get(); | ||
| for (auto& detection : output) { | ||
| draw_detection(output_q.front().first->frame, detection, cv::Scalar(0, 0, 255)); | ||
| } | ||
| iters++; | ||
|
|
||
| if (!(iters % progress_bar_tick)) { | ||
| const int precent_ready = (100 * iters) / video_lenght; | ||
| std::cout << iters << " out of " << video_lenght | ||
| << " frames are are processed (" << precent_ready << "\%)" | ||
| << std::endl; | ||
| } | ||
| video.write(output_q.front().first->frame); | ||
| output_q.pop(); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| video.write(frame); | ||
| } | ||
| const et_timestamp_t after_execute = et_pal_current_ticks(); | ||
| time_spent_executing = after_execute - before_execute; | ||
|
|
||
| const auto tick_ratio = et_pal_ticks_to_ns_multiplier(); | ||
| constexpr auto NANOSECONDS_PER_MILLISECOND = 1000000; | ||
|
|
@@ -165,4 +229,4 @@ void draw_detection( | |
| cv::Scalar(0, 0, 0), | ||
| 2, | ||
| 0); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| ultralytics==8.3.97 | ||
| ultralytics==8.3.196 |
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.
Why do we need tokenizers and other dependencies for YOLO?
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.
Are you able to build it without these? The yolo example doesn't use them but I thought some dependencies need them. I will check again if we can build without these.
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.
Without these I see the error below:
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, the example was fully functional when it was merged. That's a bit strange, how do you build the example?
You can find a test script over there https://github.com/pytorch/executorch/blob/main/.ci/scripts/test_yolo12.sh
I think meta guys could potentially help with that
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.
The build commands below should work right? I can reproduce with the main branch. I see similar error either with OV backend or XNNPACK by the way. I will ping them in discord.