2021-12-07 10:57:55 +08:00
|
|
|
// Copyright (c) OpenMMLab. All rights reserved.
|
|
|
|
|
|
|
|
#include "transform.h"
|
|
|
|
|
|
|
|
#include "core/registry.h"
|
2021-12-16 13:51:22 +08:00
|
|
|
#include "core/utils/formatter.h"
|
2021-12-07 10:57:55 +08:00
|
|
|
|
|
|
|
namespace mmdeploy {
|
|
|
|
|
|
|
|
TransformImpl::TransformImpl(const Value &args) {
|
|
|
|
if (args.contains("context")) {
|
2021-12-16 13:51:22 +08:00
|
|
|
args["context"]["device"].get_to(device_);
|
|
|
|
args["context"]["stream"].get_to(stream_);
|
2021-12-07 10:57:55 +08:00
|
|
|
} else {
|
2021-12-16 13:51:22 +08:00
|
|
|
throw_exception(eNotSupported);
|
2021-12-07 10:57:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|