Skip to content

Commit

Permalink
Merge branch 'opencv' into 'master'
Browse files Browse the repository at this point in the history
Fix opencv image size

See merge request !56
  • Loading branch information
李寅 committed Jan 7, 2019
2 parents ada7068 + 59b0c97 commit 4d0f335
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aibench/benchmark/imagenet/imagenet_preprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,25 @@ Status ImageNetPreProcessor::Run(const std::string &filename,
cv::dnn::blobFromImage(image,
blob,
1.0 / input_var_[0],
cv::Size(image_height, image_width),
cv::Size(image_width, image_height),
cv::Scalar(input_means_[0][0],
input_means_[0][1],
input_means_[0][2]),
channel_order_ == RGB,
true);

MACE_CHECK(blob.isContinuous(), "blob is not continuous.");
std::vector<float>
chw_input_data(blob.begin<float>(), blob.end<float>());
auto input_size = std::distance(blob.begin<float>(), blob.end<float>());
MACE_CHECK(input_size == image_channels * image_height * image_width,
"Wrong input size: ", input_size);
if (data_formats_[0] == NHWC) {
imagenet::TransformCHWToHWC(chw_input_data.data(),
imagenet::TransformCHWToHWC(blob.ptr<float>(),
image_height,
image_width,
image_channels,
input_data);
} else if (data_formats_[0] == NCHW) {
std::copy_n(chw_input_data.data(), chw_input_data.size(), input_data);
std::copy_n(blob.ptr<float>(), input_size, input_data);
} else {
LOG(FATAL) << "Wrong input format: " << data_formats_[0];
}
Expand Down

0 comments on commit 4d0f335

Please sign in to comment.