diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index e63dc87343..afffb47fa4 100644 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -691,14 +691,14 @@ Status DvppDecodeResizeCropOperation::ValidateParams() { RETURN_STATUS_SYNTAX_ERROR(err_msg); } if (crop_.size() < resize_.size()) { - if (crop_[0] >= MIN(resize_[0], resize_[1])) { + if (crop_[0] > MIN(resize_[0], resize_[1])) { std::string err_msg = "crop size must be smaller than resize size"; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } } if (crop_.size() > resize_.size()) { - if (MAX(crop_[0], crop_[1]) >= resize_[0]) { + if (MAX(crop_[0], crop_[1]) > resize_[0]) { std::string err_msg = "crop size must be smaller than resize size"; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); @@ -706,7 +706,7 @@ Status DvppDecodeResizeCropOperation::ValidateParams() { } if (crop_.size() == resize_.size()) { for (int32_t i = 0; i < crop_.size(); ++i) { - if (crop_[i] >= resize_[i]) { + if (crop_[i] > resize_[i]) { std::string err_msg = "crop size must be smaller than resize size"; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); diff --git a/tests/cxx_st/dataset/test_de.cc b/tests/cxx_st/dataset/test_de.cc index 2d0aaf923f..510324867e 100644 --- a/tests/cxx_st/dataset/test_de.cc +++ b/tests/cxx_st/dataset/test_de.cc @@ -20,10 +20,31 @@ #include "minddata/dataset/include/minddata_eager.h" #include "minddata/dataset/include/vision.h" #include "minddata/dataset/kernels/tensor_op.h" +#include "include/api/model.h" +#include "include/api/serializations.h" +#include "include/api/context.h" using namespace mindspore::api; using namespace mindspore::dataset::vision; +static void SaveFile(int idx, Buffer buffer, int seq) { + std::string path = "mnt/disk1/yolo_dvpp_result/result_Files/output" + std::to_string(idx) + + "_in_YoloV3-DarkNet_coco_bs_dvpp_" + std::to_string(seq) + ".bin"; + FILE *output_file = fopen(path.c_str(), "wb"); + if (output_file == nullptr) { + std::cout << "Write file" << path << "failed when fopen" << std::endl; + return; + } + + size_t wsize = fwrite(buffer.Data(), buffer.DataSize(), sizeof(int8_t), output_file); + if (wsize == 0) { + std::cout << "Write file" << path << " failed when fwrite." << std::endl; + return; + } + fclose(output_file); + std::cout << "Save file " << path << "length" << buffer.DataSize() << " success." << std::endl; +} + class TestDE : public ST::Common { public: TestDE() {} @@ -56,10 +77,44 @@ TEST_F(TestDE, TestDvpp) { for (auto &img : images) { img = Solo(img); + ASSERT_EQ(images[0]->Shape().size(), 3); + ASSERT_EQ(images[0]->Shape()[0], 224 * 224 * 1.5); + ASSERT_EQ(images[0]->Shape()[1], 1); + ASSERT_EQ(images[0]->Shape()[2], 1); } +} - ASSERT_EQ(images[0]->Shape().size(), 3); - ASSERT_EQ(images[0]->Shape()[0], 224 * 224 * 1.5); - ASSERT_EQ(images[0]->Shape()[1], 1); - ASSERT_EQ(images[0]->Shape()[2], 1); +TEST_F(TestDE, TestYoloV3_with_Dvpp) { + std::vector> images; + MIndDataEager::LoadImageFromDir("/home/lizhenglong/val2014", &images); + MindDataEager SingleOp({DvppDecodeResizeCropJpeg({416, 416}, {416, 416})}); + constexpr auto yolo_mindir_file = "/home/zhoufeng/yolov3/yolov3_darknet53.mindir"; + Context::Instance().SetDeviceTarget(kDeviceTypeAscend310).SetDeviceID(1); + auto graph = Serialization::LoadModel(yolo_mindir_file, ModelType::kMindIR); + Model yolov3((GraphCell(graph))); + Status ret = yolov3.Build({{kMOdelOptionInsertOpCfgPath, "/mnt/disk1/yolo_dvpp_result/aipp_resnet50.cfg"}}); + ASSERT_TRUE(ret == SUCCESS); + + std::vector names; + std::vector> shapes; + std::vector data_types; + std::vector mem_sizes; + yolov3.GetOutputsInfo(&names, &shapes, &data_types, &mem_sizes); + std::vector outputs; + std::vector inputs; + + int64_t seq = 0; + for (auto &img : images) { + img = SingleOp(img); + std::vector input_shape = {416, 416}; + input.clear(); + inputs.emplace_back(img->data(), img->DataSize()); + inputs.emplace_back(input_shape.data(), input_shape.size() * sizeof(float)); + ret = yolov3.Predict(inputs, &outputs); + for (size_t i = 0; i < outputs.size(); ++i) { + SaveFile(i, outputs[i], seq); + } + seq++; + ASSERT_TRUE(ret == SUCCESS); + } }