1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include <vpu/frontend/frontend.hpp>
8 #include <unordered_set>
15 VPU_DECLARE_ENUM(ResampleType,
22 class ResampleStage final : public StageNode {
24 StagePtr cloneImpl() const override {
25 return std::make_shared<ResampleStage>(*this);
28 void propagateDataOrderImpl() const override {
29 IE_ASSERT(_inputEdges.size() == 1);
30 IE_ASSERT(_outputEdges.size() == 1);
32 auto input = _inputEdges[0]->input();
34 _orderInfo.setOutput(_outputEdges[0], input->desc().dimsOrder());
37 void getDataStridesRequirementsImpl() const override {
40 void finalizeDataLayoutImpl() override {
43 void getBatchSupportInfoImpl() const override {
44 IE_ASSERT(_inputEdges.size() == 1);
45 IE_ASSERT(_outputEdges.size() == 1);
47 _batchInfo.setInput(_inputEdges[0], BatchSupport::Split);
48 _batchInfo.setOutput(_outputEdges[0], BatchSupport::Split);
51 void finalCheckImpl() const override {
54 void serializeParamsImpl(BlobSerializer& serializer) const override {
55 auto antialias = attrs().get<bool>("antialias");
56 auto factor = attrs().get<float>("factor");
57 auto sampleType = attrs().get<ResampleType>("type");
59 serializer.append(static_cast<int32_t>(antialias));
60 serializer.append(static_cast<float>(factor));
61 serializer.append(static_cast<uint32_t>(sampleType));
64 void serializeDataImpl(BlobSerializer& serializer) const override {
65 IE_ASSERT(_inputEdges.size() == 1);
66 IE_ASSERT(_outputEdges.size() == 1);
67 IE_ASSERT(_tempBufferEdges.empty());
69 auto input = _inputEdges[0]->input();
70 auto output = _outputEdges[0]->output();
72 input->serializeOldBuffer(handle_from_this(), serializer);
73 output->serializeOldBuffer(handle_from_this(), serializer);
79 void FrontEnd::parseResample(
80 const Model::Ptr& model,
81 const ie::CNNLayerPtr& layer,
82 const DataVector& inputs,
83 const DataVector& outputs) {
84 IE_ASSERT(inputs.size() == 1);
85 IE_ASSERT(outputs.size() == 1);
87 ie::details::CaselessEq<std::string> cmp;
89 auto stage = model->addNewStage<ResampleStage>(
96 stage->attrs().set<bool>("antialias", layer->GetParamAsInt("antialias", 0));
97 stage->attrs().set<float>("factor", layer->GetParamAsInt("factor", -1.0f));
99 auto method = layer->GetParamAsString("type", "caffe.ResampleParameter.NEAREST");
100 if (cmp(method, "caffe.ResampleParameter.NEAREST")) {
101 stage->attrs().set<ResampleType>("type", ResampleType::Nearest);
103 stage->attrs().set<ResampleType>("type", ResampleType::Bilinear);