google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.83k stars 5.18k forks source link

Segmentation fault at TfLiteTensorsToDetectionsCalculator::ProcessCPU #5596

Open Danil0v3s opened 3 months ago

Danil0v3s commented 3 months ago

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

None

OS Platform and Distribution

WSL Ubuntu 22.04

MediaPipe version

0.10.15

Bazel version

6.1.1

Solution

Autoflip

Programming Language and version

C++

Describe the actual behavior

Segmentation fault at TfLiteTensorsToDetectionsCalculator::ProcessCPU

Describe the expected behaviour

No segmentation fault

Standalone code/steps you may have used to try to get what you need

Compiled the code with below and no modifications to the original source

bazel build --compilation_mode=dbg --define MEDIAPIPE_DISABLE_GPU=1 --define xnn_enable_avx512fp16=false --define xnn_enable_avxvnni=false --define xnn_enable_avx512amx=false mediapipe/examples/desktop/autoflip:run_autoflip

And ran with

bazel-bin/mediapipe/examples/desktop/autoflip/run_autoflip --calculator_graph_config_file=mediapipe/examples/desktop/autoflip/autoflip_graph.pbtxt --input_side_packets=input_video_path=/absolute/path/to/the/local/video/file,output_video_path=/absolute/path/to/save/the/output/video/file,aspect_ratio=3:4

I can't seem to compile without disabling avx512fp16, avx512amx and avxvnni and when I run the code above it would fail intermittently


### Other info / Complete Logs

image

kuaashish commented 3 months ago

Hi @Danil0v3s,

We regret to inform you that support for Autoflip solutions has been fully discontinued and you can see same information available here https://ai.google.dev/edge/mediapipe/solutions/guide#legacy in our documentation, Although we will no longer provide support, the libraries and documentation will remain accessible in our GitHub repository and through services like Maven and NPM. You may continue using these legacy solutions in your applications, but please be aware that no further support will be available.

Thank you!!!

Danil0v3s commented 3 months ago

Hey @kuaashish, since this is happening within mediapipe core I thought it would be worth reporting... or not at all?

kuaashish commented 3 months ago

Hi @Danil0v3s,

Since you are using legacy solutions that we no longer support or maintain, we regret that we can not assist with any issues related to them. However, we are available to help with any issues related to our currently supported solutions, now called Task APIs, which you can explore through our documentation here https://ai.google.dev/edge/mediapipe/solutions/guide.

Thank you!!

Danil0v3s commented 3 months ago

So, on the mediapipe/calculators/tflite/tflite_tensors_to_detections_calculator.cc there's this

 float max_score = -std::numeric_limits<float>::max();
      // Find the top score for box i.
      for (int score_idx = 0; score_idx < num_classes_; ++score_idx) {
        if (ignore_classes_.find(score_idx) == ignore_classes_.end()) {
          auto score = raw_scores[i * num_classes_ + score_idx];

And being the segmentation fault raised at auto score = raw_scores[i * num_classes_ + score_idx]; I changed the code to

for (int score_idx = 0; score_idx < num_classes_; ++score_idx)
        {
          int score_linear_idx = i * num_classes_ + score_idx;
          if (ignore_classes_.find(score_idx) == ignore_classes_.end() && score_linear_idx < max_score)
          {
            auto score = raw_scores[score_linear_idx];

And it seems to have fixed the issue

kuaashish commented 3 months ago

Hi @Danil0v3s,

Could you please provide the complete standalone code or the specific steps you are following from our documentation to help us better understand the issue? If needed, we will reproduce it on our end. Please note: If this relates to the legacy Autoflip solution, we will be unable to offer support.

Thank you!!

Danil0v3s commented 3 months ago

Hi @Danil0v3s,

Could you please provide the complete standalone code or the specific steps you are following from our documentation to help us better understand the issue? If needed, we will reproduce it on our end. Please note: If this relates to the legacy Autoflip solution, we will be unable to offer support.

Thank you!!

Hey mate, the only usecase I have for this is using autoflip. So by what you say I guess it's not worth bothering. However if someone else finds this, the problem seem to be related with the max_queue_size. Whenever it's unlimited, the class would crash where I said, but with some further debugging my solution wasn't the correct, safe guarding by checking the length of the array is not the solution. Instead, I created a vector std::vector<float> scores_vector(raw_score_tensor->data.f, raw_score_tensor->data.f + num_boxes_ * num_classes_); and use the vector instead of the pointer directly. That seems to eliminate the issue completely

Positliver commented 5 days ago

Hi @Danil0v3s, Could you please provide the complete standalone code or the specific steps you are following from our documentation to help us better understand the issue? If needed, we will reproduce it on our end. Please note: If this relates to the legacy Autoflip solution, we will be unable to offer support. Thank you!!

Hey mate, the only usecase I have for this is using autoflip. So by what you say I guess it's not worth bothering. However if someone else finds this, the problem seem to be related with the max_queue_size. Whenever it's unlimited, the class would crash where I said, but with some further debugging my solution wasn't the correct, safe guarding by checking the length of the array is not the solution. Instead, I created a vector std::vector<float> scores_vector(raw_score_tensor->data.f, raw_score_tensor->data.f + num_boxes_ * num_classes_); and use the vector instead of the pointer directly. That seems to eliminate the issue completely

hello, I have the same problem. Could you provide me with the complete modification code of scores_vector? Thank you very much.

Danil0v3s commented 5 days ago

Hi @Danil0v3s,

Could you please provide the complete standalone code or the specific steps you are following from our documentation to help us better understand the issue? If needed, we will reproduce it on our end. Please note: If this relates to the legacy Autoflip solution, we will be unable to offer support.

Thank you!!

Hey mate, the only usecase I have for this is using autoflip. So by what you say I guess it's not worth bothering. However if someone else finds this, the problem seem to be related with the max_queue_size. Whenever it's unlimited, the class would crash where I said, but with some further debugging my solution wasn't the correct, safe guarding by checking the length of the array is not the solution. Instead, I created a vector std::vector<float> scores_vector(raw_score_tensor->data.f, raw_score_tensor->data.f + num_boxes_ * num_classes_); and use the vector instead of the pointer directly. That seems to eliminate the issue completely

hello, I have the same problem. Could you provide me with the complete modification code of scores_vector? Thank you very much.

https://github.com/Danil0v3s/autoflip