Skip to content

Commit 4dcddc9

Browse files
committed
fix build error after cherry-pick open-mmlab#1353
1 parent 04c9793 commit 4dcddc9

File tree

5 files changed

+51
-199
lines changed

5 files changed

+51
-199
lines changed

csrc/mmdeploy/codebase/mmaction/cuda/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ if (NOT "cuda" IN_LIST MMDEPLOY_TARGET_DEVICES)
44
endif ()
55

66
project(mmdeploy_mmaction_cuda_impl CXX)
7+
include(${CMAKE_SOURCE_DIR}/cmake/modules/FindCUDNN.cmake)
78

8-
add_library(${PROJECT_NAME} OBJECT format_shape_impl.cpp transpose.cu)
9+
add_library(${PROJECT_NAME} OBJECT format_shape_impl.cpp)
910
set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1)
1011
if (NOT (MMDEPLOY_SHARED_LIBS OR MSVC))
1112
target_compile_options(${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fvisibility=hidden>)
1213
endif ()
1314
target_include_directories(${PROJECT_NAME} PRIVATE
1415
${CUDA_INCLUDE_DIRS})
1516
target_link_libraries(${PROJECT_NAME} PRIVATE
16-
mmdeploy::core)
17+
mmdeploy::core
18+
cudnn)
1719
target_link_libraries(mmdeploy_mmaction PRIVATE ${PROJECT_NAME})
1820
mmdeploy_export(${PROJECT_NAME})

csrc/mmdeploy/codebase/mmaction/cuda/transpose.cu

Lines changed: 0 additions & 38 deletions
This file was deleted.

csrc/mmdeploy/codebase/mmocr/rescale_to_height.cpp

Lines changed: 25 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22

33
#include <set>
44

5-
#include "mmdeploy/archive/json_archive.h"
65
#include "mmdeploy/archive/value_archive.h"
76
#include "mmdeploy/core/registry.h"
87
#include "mmdeploy/core/tensor.h"
9-
#include "mmdeploy/core/utils/device_utils.h"
108
#include "mmdeploy/core/utils/formatter.h"
11-
#include "mmdeploy/preprocess/transform/resize.h"
9+
#include "mmdeploy/operation/managed.h"
10+
#include "mmdeploy/operation/vision.h"
1211
#include "mmdeploy/preprocess/transform/transform.h"
13-
#include "opencv2/imgproc.hpp"
14-
#include "opencv_utils.h"
1512

1613
using namespace std;
1714

18-
namespace mmdeploy {
15+
namespace mmdeploy::ocr {
1916

20-
class RescaleToHeightImpl : public Module {
17+
class RescaleToHeight : public transform::Transform {
2118
public:
22-
explicit RescaleToHeightImpl(const Value& args) noexcept {
19+
explicit RescaleToHeight(const Value& args) noexcept {
2320
height_ = args.value("height", height_);
2421
min_width_ = args.contains("min_width") && args["min_width"].is_number_integer()
2522
? args["min_width"].get<int>()
@@ -30,113 +27,59 @@ class RescaleToHeightImpl : public Module {
3027
width_divisor_ = args.contains("width_divisor") && args["width_divisor"].is_number_integer()
3128
? args["width_divisor"].get<int>()
3229
: width_divisor_;
33-
resize_type_ = args.contains("resize_type") && args["resize_type"].is_string()
34-
? args["resize_type"].get<string>()
35-
: resize_type_;
36-
stream_ = args["context"]["stream"].get<Stream>();
30+
resize_ = operation::Managed<operation::Resize>::Create("bilinear");
3731
}
3832

39-
~RescaleToHeightImpl() override = default;
33+
~RescaleToHeight() override = default;
4034

41-
Result<Value> Process(const Value& input) override {
42-
MMDEPLOY_DEBUG("input: {}", input);
35+
Result<void> Apply(Value& data) override {
36+
MMDEPLOY_DEBUG("input: {}", data);
4337
auto dst_height = height_;
4438
auto dst_min_width = min_width_;
4539
auto dst_max_width = max_width_;
4640

4741
std::vector<int> img_shape; // NHWC
48-
from_value(input["img_shape"], img_shape);
42+
from_value(data["img_shape"], img_shape);
4943

5044
std::vector<int> ori_shape; // NHWC
51-
from_value(input["ori_shape"], ori_shape);
45+
from_value(data["ori_shape"], ori_shape);
5246

5347
auto ori_height = ori_shape[1];
5448
auto ori_width = ori_shape[2];
5549
auto valid_ratio = 1.f;
5650

57-
Device host{"cpu"};
58-
auto _img = input["img"].get<Tensor>();
59-
OUTCOME_TRY(auto img, MakeAvailableOnDevice(_img, host, stream_));
60-
stream_.Wait().value();
51+
auto img = data["img"].get<Tensor>();
6152
Tensor img_resize;
6253
auto new_width = static_cast<int>(std::ceil(1.f * dst_height / ori_height * ori_width));
6354
auto width_divisor = width_divisor_;
6455
if (dst_min_width > 0) {
6556
new_width = std::max(dst_min_width, new_width);
6657
}
6758
if (dst_max_width > 0) {
68-
auto resize_width = std::min(dst_max_width, new_width);
59+
new_width = std::min(dst_max_width, new_width);
6960
}
7061
if (new_width % width_divisor != 0) {
7162
new_width = std::round(1.f * new_width / width_divisor) * width_divisor;
7263
}
73-
img_resize = ResizeImage(img, dst_height, new_width);
74-
Value output = input;
75-
output["img"] = img_resize;
76-
output["resize_shape"] = to_value(img_resize.desc().shape);
77-
output["pad_shape"] = output["resize_shape"];
78-
output["ori_shape"] = input["ori_shape"];
79-
output["scale"] = to_value(std::vector<int>({new_width, dst_height}));
80-
output["valid_ratio"] = valid_ratio;
81-
MMDEPLOY_DEBUG("output: {}", to_json(output).dump(2));
82-
return output;
83-
}
84-
85-
Tensor ResizeImage(const Tensor& img, int dst_h, int dst_w) {
86-
TensorDesc desc = img.desc();
87-
assert(desc.shape.size() == 4);
88-
assert(desc.data_type == DataType::kINT8);
89-
int h = desc.shape[1];
90-
int w = desc.shape[2];
91-
int c = desc.shape[3];
92-
assert(c == 3 || c == 1);
93-
cv::Mat src_mat, dst_mat;
94-
if (3 == c) { // rgb
95-
src_mat = cv::Mat(h, w, CV_8UC3, const_cast<uint8_t*>(img.data<uint8_t>()));
96-
} else { // gray
97-
src_mat = cv::Mat(h, w, CV_8UC1, const_cast<uint8_t*>(img.data<uint8_t>()));
98-
}
99-
cv::Size size{dst_w, dst_h};
100-
cv::resize(src_mat, dst_mat, size, cv::INTER_LINEAR);
101-
return Tensor({desc.device, desc.data_type, {1, dst_h, dst_w, c}, ""},
102-
{dst_mat.data, [mat = dst_mat](void* ptr) {}});
64+
OUTCOME_TRY(resize_.Apply(img, img_resize, dst_height, new_width));
65+
data["img"] = img_resize;
66+
data["resize_shape"] = to_value(img_resize.desc().shape);
67+
data["pad_shape"] = data["resize_shape"];
68+
data["ori_shape"] = data["ori_shape"];
69+
data["scale"] = to_value(std::vector<int>({new_width, dst_height}));
70+
data["valid_ratio"] = valid_ratio;
71+
MMDEPLOY_DEBUG("output: {}", data);
72+
return success();
10373
}
10474

10575
protected:
76+
operation::Managed<operation::Resize> resize_;
10677
int height_{-1};
10778
int min_width_{-1};
10879
int max_width_{-1};
10980
bool keep_aspect_ratio_{true};
11081
int width_divisor_{1};
111-
std::string resize_type_{"Resize"};
112-
Stream stream_;
11382
};
11483

115-
MMDEPLOY_CREATOR_SIGNATURE(RescaleToHeightImpl,
116-
std::unique_ptr<RescaleToHeightImpl>(const Value& config));
117-
118-
MMDEPLOY_DEFINE_REGISTRY(RescaleToHeightImpl);
119-
120-
MMDEPLOY_REGISTER_FACTORY_FUNC(RescaleToHeightImpl, (cpu, 0), [](const Value& config) {
121-
return std::make_unique<RescaleToHeightImpl>(config);
122-
});
123-
124-
class RescaleToHeight : public Transform {
125-
public:
126-
explicit RescaleToHeight(const Value& args) : Transform(args) {
127-
impl_ = Instantiate<RescaleToHeightImpl>("RescaleToHeight", args);
128-
}
129-
~RescaleToHeight() override = default;
130-
131-
Result<Value> Process(const Value& input) override { return impl_->Process(input); }
132-
133-
private:
134-
std::unique_ptr<RescaleToHeightImpl> impl_;
135-
static const std::string name_;
136-
};
137-
138-
MMDEPLOY_REGISTER_FACTORY_FUNC(Transform, (ResizeOCR, 0), [](const Value& config) {
139-
return std::make_unique<RescaleToHeight>(config);
140-
});
141-
142-
} // namespace mmdeploy
84+
MMDEPLOY_REGISTER_TRANSFORM(RescaleToHeight);
85+
} // namespace mmdeploy::ocr

csrc/mmdeploy/codebase/mmocr/short_scale_aspect_jitter.cpp

Lines changed: 22 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22

33
#include <set>
44

5-
#include "mmdeploy/archive/json_archive.h"
65
#include "mmdeploy/archive/value_archive.h"
76
#include "mmdeploy/core/registry.h"
87
#include "mmdeploy/core/tensor.h"
9-
#include "mmdeploy/core/utils/device_utils.h"
108
#include "mmdeploy/core/utils/formatter.h"
11-
#include "mmdeploy/preprocess/transform/resize.h"
9+
#include "mmdeploy/operation/managed.h"
10+
#include "mmdeploy/operation/vision.h"
1211
#include "mmdeploy/preprocess/transform/transform.h"
13-
#include "opencv2/imgproc.hpp"
14-
#include "opencv_utils.h"
1512

1613
using namespace std;
1714

18-
namespace mmdeploy {
15+
namespace mmdeploy::ocr {
1916

20-
class ShortScaleAspectJitterImpl : public Module {
17+
class ShortScaleAspectJitter : public transform::Transform {
2118
public:
22-
explicit ShortScaleAspectJitterImpl(const Value& args) noexcept {
19+
explicit ShortScaleAspectJitter(const Value& args) noexcept {
2320
short_size_ = args.contains("short_size") && args["short_size"].is_number_integer()
2421
? args["short_size"].get<int>()
2522
: short_size_;
@@ -41,16 +38,13 @@ class ShortScaleAspectJitterImpl : public Module {
4138
scale_divisor_ = args.contains("scale_divisor") && args["scale_divisor"].is_number_integer()
4239
? args["scale_divisor"].get<int>()
4340
: scale_divisor_;
44-
resize_type_ = args.contains("resize_type") && args["resize_type"].is_string()
45-
? args["resize_type"].get<string>()
46-
: resize_type_;
47-
stream_ = args["context"]["stream"].get<Stream>();
41+
resize_ = operation::Managed<operation::Resize>::Create("bilinear");
4842
}
4943

50-
~ShortScaleAspectJitterImpl() override = default;
44+
~ShortScaleAspectJitter() override = default;
5145

52-
Result<Value> Process(const Value& input) override {
53-
MMDEPLOY_DEBUG("input: {}", input);
46+
Result<void> Apply(Value& data) override {
47+
MMDEPLOY_DEBUG("input: {}", data);
5448
auto short_size = short_size_;
5549
auto ratio_range = ratio_range_;
5650
auto aspect_ratio_range = aspect_ratio_range_;
@@ -62,18 +56,15 @@ class ShortScaleAspectJitterImpl : public Module {
6256
return Status(eNotSupported);
6357
}
6458
std::vector<int> img_shape; // NHWC
65-
from_value(input["img_shape"], img_shape);
59+
from_value(data["img_shape"], img_shape);
6660

6761
std::vector<int> ori_shape; // NHWC
68-
from_value(input["ori_shape"], ori_shape);
62+
from_value(data["ori_shape"], ori_shape);
6963

7064
auto ori_height = ori_shape[1];
7165
auto ori_width = ori_shape[2];
7266

73-
Device host{"cpu"};
74-
auto _img = input["img"].get<Tensor>();
75-
OUTCOME_TRY(auto img, MakeAvailableOnDevice(_img, host, stream_));
76-
stream_.Wait().value();
67+
auto img = data["img"].get<Tensor>();
7768
Tensor img_resize;
7869
auto scale = static_cast<float>(1.0 * short_size / std::min(img_shape[1], img_shape[2]));
7970
auto dst_height = static_cast<int>(std::round(scale * img_shape[1]));
@@ -83,69 +74,23 @@ class ShortScaleAspectJitterImpl : public Module {
8374
std::vector<float> scale_factor = {(float)1.0 * dst_width / img_shape[2],
8475
(float)1.0 * dst_height / img_shape[1]};
8576

86-
img_resize = ResizeImage(img, dst_height, dst_width);
87-
Value output = input;
88-
output["img"] = img_resize;
89-
output["resize_shape"] = to_value(img_resize.desc().shape);
90-
output["scale"] = to_value(std::vector<int>({dst_width, dst_height}));
91-
output["scale_factor"] = to_value(scale_factor);
92-
MMDEPLOY_DEBUG("output: {}", to_json(output).dump(2));
93-
return output;
94-
}
95-
96-
Tensor ResizeImage(const Tensor& img, int dst_h, int dst_w) {
97-
TensorDesc desc = img.desc();
98-
assert(desc.shape.size() == 4);
99-
assert(desc.data_type == DataType::kINT8);
100-
int h = desc.shape[1];
101-
int w = desc.shape[2];
102-
int c = desc.shape[3];
103-
assert(c == 3 || c == 1);
104-
cv::Mat src_mat, dst_mat;
105-
if (3 == c) { // rgb
106-
src_mat = cv::Mat(h, w, CV_8UC3, const_cast<uint8_t*>(img.data<uint8_t>()));
107-
} else { // gray
108-
src_mat = cv::Mat(h, w, CV_8UC1, const_cast<uint8_t*>(img.data<uint8_t>()));
109-
}
110-
cv::Size size{dst_w, dst_h};
111-
cv::resize(src_mat, dst_mat, size, cv::INTER_LINEAR);
112-
return Tensor({desc.device, desc.data_type, {1, dst_h, dst_w, c}, ""},
113-
{dst_mat.data, [mat = dst_mat](void* ptr) {}});
77+
OUTCOME_TRY(resize_.Apply(img, img_resize, dst_height, dst_width));
78+
data["img"] = img_resize;
79+
data["resize_shape"] = to_value(img_resize.desc().shape);
80+
data["scale"] = to_value(std::vector<int>({dst_width, dst_height}));
81+
data["scale_factor"] = to_value(scale_factor);
82+
MMDEPLOY_DEBUG("output: {}", data);
83+
return success();
11484
}
11585

11686
protected:
87+
operation::Managed<operation::Resize> resize_;
11788
int short_size_{736};
11889
std::vector<float> ratio_range_{0.7, 1.3};
11990
std::vector<float> aspect_ratio_range_{0.9, 1.1};
12091
int scale_divisor_{1};
121-
std::string resize_type_{"Resize"};
122-
Stream stream_;
123-
};
124-
125-
MMDEPLOY_CREATOR_SIGNATURE(ShortScaleAspectJitterImpl,
126-
std::unique_ptr<ShortScaleAspectJitterImpl>(const Value& config));
127-
MMDEPLOY_DEFINE_REGISTRY(ShortScaleAspectJitterImpl);
128-
129-
MMDEPLOY_REGISTER_FACTORY_FUNC(ShortScaleAspectJitterImpl, (cpu, 0), [](const Value& config) {
130-
return std::make_unique<ShortScaleAspectJitterImpl>(config);
131-
});
132-
133-
class ShortScaleAspectJitter : public Transform {
134-
public:
135-
explicit ShortScaleAspectJitter(const Value& args) : Transform(args) {
136-
impl_ = Instantiate<ShortScaleAspectJitterImpl>("ShortScaleAspectJitter", args);
137-
}
138-
~ShortScaleAspectJitter() override = default;
139-
140-
Result<Value> Process(const Value& input) override { return impl_->Process(input); }
141-
142-
private:
143-
std::unique_ptr<ShortScaleAspectJitterImpl> impl_;
144-
static const std::string name_;
14592
};
14693

147-
MMDEPLOY_REGISTER_FACTORY_FUNC(Transform, (ShortScaleAspectJitter, 0), [](const Value& config) {
148-
return std::make_unique<ShortScaleAspectJitter>(config);
149-
});
94+
MMDEPLOY_REGISTER_TRANSFORM(ShortScaleAspectJitter);
15095

151-
} // namespace mmdeploy
96+
} // namespace mmdeploy::ocr

csrc/mmdeploy/preprocess/transform/pad.h

Whitespace-only changes.

0 commit comments

Comments
 (0)