!10113 Add YoloV3 with dvpp preprocess test

From: @lizhenglong1992
Reviewed-by: @jonyguo,@liucunwei,@pandoublefeng
Signed-off-by: @liucunwei
pull/10113/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit eb1fd8bd1c

@ -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);

@ -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<std::shared_ptr<Tensor>> 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<std::string> names;
std::vector<std::vector<int64_t>> shapes;
std::vector<DataType> data_types;
std::vector<size_t> mem_sizes;
yolov3.GetOutputsInfo(&names, &shapes, &data_types, &mem_sizes);
std::vector<Buffer> outputs;
std::vector<Buffer> inputs;
int64_t seq = 0;
for (auto &img : images) {
img = SingleOp(img);
std::vector<float> 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);
}
}

Loading…
Cancel
Save