mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* sync SDK changes according to performance benchmarks * fix end-of-file lint * fix clang-format issue * fix clang-format by adding 'clang-format off' * remove useless casts * remove 'data' argument of 'operator()' * change 'Tensor2Img' to 'TensorToImg' according to spec * correct tensor's name according spec Co-authored-by: lvhan028 <lvhan_028@163.com>
52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
#include "transform.h"
|
|
|
|
#include "core/registry.h"
|
|
#include "core/utils/formatter.h"
|
|
|
|
namespace mmdeploy {
|
|
|
|
TransformImpl::TransformImpl(const Value &args) {
|
|
if (args.contains("context")) {
|
|
args["context"]["device"].get_to(device_);
|
|
args["context"]["stream"].get_to(stream_);
|
|
} else {
|
|
throw_exception(eNotSupported);
|
|
}
|
|
}
|
|
std::vector<std::string> TransformImpl::GetImageFields(const Value &input) {
|
|
if (input.contains("img_fields")) {
|
|
if (input["img_fields"].is_string()) {
|
|
return {input["img_fields"].get<std::string>()};
|
|
} else if (input["img_fields"].is_array()) {
|
|
std::vector<std::string> img_fields;
|
|
for (auto &v : input["img_fields"]) {
|
|
img_fields.push_back(v.get<std::string>());
|
|
}
|
|
return img_fields;
|
|
}
|
|
} else {
|
|
return {"img"};
|
|
}
|
|
throw_exception(eInvalidArgument);
|
|
}
|
|
|
|
Transform::Transform(const Value &args) {
|
|
Device device{"cpu"};
|
|
if (args.contains("context")) {
|
|
device = args["context"].value("device", device);
|
|
}
|
|
|
|
Platform platform(device.platform_id());
|
|
specified_platform_ = platform.GetPlatformName();
|
|
|
|
if (!(specified_platform_ == "cpu")) {
|
|
// add cpu platform, so that a transform op can fall back to its cpu
|
|
// version if it hasn't implementation on the specific platform
|
|
candidate_platforms_.push_back("cpu");
|
|
}
|
|
}
|
|
|
|
} // namespace mmdeploy
|