mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* unify C API naming * fix demo and move apis/c/* -> apis/c/mmdeploy/* * fix lint * WIP refactor pipeline * backward compatibility * working pipeline demo * add text det-recog demo * add det-pose demo * fix build * fix demo * add environment interface * add environment to pass scheduler & model info at runtime * update demos * add pipeline API for Python * fix `FromPyObject` * fix for opencv-4.2 * environment -> context, improve pipeline * python model interface * fix cmake * fix python & cmake * context & C++ pipeline API * minor fix * improve API * fix shared libs * refresh C/Python API * propagate context * fix python demo * fix * add namespace * fix namespace * fix mis-changed strings * fix * fix python api * rename * clean-up * fix pose detector * clean-up * clean-up * clean-up * fix python API build * fix CI * fix lint * fix lint * fix lint & demo * install pipeline.hpp * fix MSVC shared library build * fix sample * fix MSVC monolithic build * minor fix
103 lines
2.2 KiB
C++
103 lines
2.2 KiB
C++
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
#include <fstream>
|
|
|
|
// clang-format off
|
|
#include "catch.hpp"
|
|
// clang-format on
|
|
|
|
#include "json.hpp"
|
|
#include "mmdeploy/archive/json_archive.h"
|
|
#include "mmdeploy/core/mat.h"
|
|
#include "mmdeploy/core/registry.h"
|
|
#include "mmdeploy/core/utils/formatter.h"
|
|
#include "opencv2/imgcodecs/imgcodecs.hpp"
|
|
#include "opencv_utils.h"
|
|
#include "test_resource.h"
|
|
#include "test_utils.h"
|
|
|
|
using namespace mmdeploy;
|
|
using namespace framework;
|
|
using namespace mmdeploy::test;
|
|
using namespace std;
|
|
using nlohmann::json;
|
|
|
|
static constexpr const char *gPipelineConfig = R"(
|
|
[{
|
|
"type": "LoadImageFromFile"
|
|
},
|
|
{
|
|
"type": "Resize",
|
|
"size": [
|
|
256, -1
|
|
]
|
|
},
|
|
{
|
|
"type": "CenterCrop",
|
|
"crop_size": 224
|
|
},
|
|
{
|
|
"type": "Normalize",
|
|
"mean": [
|
|
123.675,
|
|
116.28,
|
|
103.53
|
|
],
|
|
"std": [
|
|
58.395,
|
|
57.12,
|
|
57.375
|
|
],
|
|
"to_rgb": true
|
|
},
|
|
{
|
|
"type": "ImageToTensor",
|
|
"keys": [
|
|
"img"
|
|
]
|
|
},
|
|
{
|
|
"type": "Collect",
|
|
"keys": [
|
|
"img"
|
|
]
|
|
}
|
|
]
|
|
)";
|
|
|
|
TEST_CASE("transform Compose exceptional case", "[compose]") {
|
|
Value compose_cfg;
|
|
SECTION("wrong transform type") {
|
|
compose_cfg = {{"type", "Compose"}, {"transforms", {{{"type", "collect"}}}}};
|
|
}
|
|
|
|
SECTION("wrong transform parameter") {
|
|
compose_cfg = {{"type", "Compose"}, {"transforms", {{{"type", "Collect"}}}}};
|
|
}
|
|
const Device kHost{"cpu"};
|
|
Stream stream{kHost};
|
|
REQUIRE(CreateTransform(compose_cfg, kHost, stream) == nullptr);
|
|
}
|
|
|
|
TEST_CASE("transform Compose", "[compose]") {
|
|
auto gResource = MMDeployTestResources::Get();
|
|
auto img_list = gResource.LocateImageResources("transform");
|
|
REQUIRE(!img_list.empty());
|
|
|
|
auto img_path = img_list.front();
|
|
cv::Mat bgr_mat = cv::imread(img_path, cv::IMREAD_COLOR);
|
|
auto src_mat = cpu::CVMat2Mat(bgr_mat, PixelFormat::kBGR);
|
|
Value input{{"ori_img", src_mat}};
|
|
|
|
auto json = json::parse(gPipelineConfig);
|
|
auto cfg = ::mmdeploy::from_json<Value>(json);
|
|
Value compose_cfg{{"type", "Compose"}, {"transforms", cfg}};
|
|
|
|
const Device kHost{"cpu"};
|
|
Stream stream{kHost};
|
|
auto transform = CreateTransform(compose_cfg, kHost, stream);
|
|
REQUIRE(transform != nullptr);
|
|
auto res = transform->Process({{"ori_img", src_mat}});
|
|
REQUIRE(!res.has_error());
|
|
}
|