Browse Source

fix opencv launch too many threads

tags/v1.1.0
panfengfeng 5 years ago
parent
commit
9d30ebcfb2
3 changed files with 20 additions and 2 deletions
  1. +14
    -0
      mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc
  2. +6
    -0
      mindspore/ccsrc/minddata/dataset/engine/execution_tree.h
  3. +0
    -2
      mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc

+ 14
- 0
mindspore/ccsrc/minddata/dataset/engine/execution_tree.cc View File

@@ -134,6 +134,20 @@ void ExecutionTree::PrintNode(std::ostream &out, const std::shared_ptr<DatasetOp

// Start the execution of the tree
Status ExecutionTree::Launch() {
// opencv limit too many threads
#ifndef ENABLE_ANDROID
#if !defined(_WIN32) && !defined(_WIN64)
int32_t thread_num = get_nprocs();
if (thread_num == 0) {
std::string err_msg = "Invalid thread number.";
RETURN_STATUS_UNEXPECTED(err_msg);
}
if (thread_num > 8)
cv::setNumThreads(8);
else
cv::setNumThreads(thread_num);
#endif
#endif
// Tree must be built and prepared before it can be launched!
if (tree_state_ != kDeTStateReady) {
std::string err_msg =


+ 6
- 0
mindspore/ccsrc/minddata/dataset/engine/execution_tree.h View File

@@ -21,6 +21,12 @@
#include <stack>
#include <string>
#include <vector>
#ifndef ENABLE_ANDROID
#if !defined(_WIN32) && !defined(_WIN64)
#include <sys/sysinfo.h>
#include <opencv2/imgproc/imgproc.hpp>
#endif
#endif
#include "minddata/dataset/engine/datasetops/dataset_op.h"
#include "minddata/dataset/util/status.h"
#include "mindspore/ccsrc/minddata/dataset/engine/perf/profiling.h"


+ 0
- 2
mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc View File

@@ -97,8 +97,6 @@ Status Resize(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *out
if (input_cv->Rank() != 3 && input_cv->Rank() != 2) {
RETURN_STATUS_UNEXPECTED("Input Tensor is not in shape of <H,W,C> or <H,W>");
}
// OpenCv lanuch too many threads.
cv::setNumThreads(8);
cv::Mat in_image = input_cv->mat();
// resize image too large or too small
if (output_height == 0 || output_height > in_image.rows * 1000 || output_width == 0 ||


Loading…
Cancel
Save