1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
5 #include "ext_list.hpp"
6 #include "ext_base.hpp"
9 namespace InferenceEngine {
10 namespace Extensions {
13 class ReorgYoloImpl: public ExtLayerBase {
15 explicit ReorgYoloImpl(const CNNLayer* layer) {
17 if (layer->insData.size() != 1 || layer->outData.empty())
18 THROW_IE_EXCEPTION << "Incorrect number of input/output edges!";
20 stride = layer->GetParamAsInt("stride");
22 addConfig(layer, {DataConfigurator(ConfLayout::PLN)}, {DataConfigurator(ConfLayout::PLN)});
23 } catch (InferenceEngine::details::InferenceEngineException &ex) {
28 StatusCode execute(std::vector<Blob::Ptr>& inputs, std::vector<Blob::Ptr>& outputs,
29 ResponseDesc *resp) noexcept override {
30 const auto *src_data = inputs[0]->cbuffer().as<const float *>();
31 auto *dst_data = outputs[0]->buffer().as<float *>();
33 int IW = (inputs[0]->getTensorDesc().getDims().size() > 3) ? inputs[0]->getTensorDesc().getDims()[3] : 1;
34 int IH = (inputs[0]->getTensorDesc().getDims().size() > 2) ? inputs[0]->getTensorDesc().getDims()[2] : 1;
35 int IC = (inputs[0]->getTensorDesc().getDims().size() > 1) ? inputs[0]->getTensorDesc().getDims()[1] : 1;
36 int B = (inputs[0]->getTensorDesc().getDims().size() > 0) ? inputs[0]->getTensorDesc().getDims()[0] : 1;
38 int ic_off = IC / (stride * stride);
39 int ih_off = IH * stride;
40 int iw_off = IW * stride;
41 for (int b = 0; b < B; b++) {
42 for (int ic = 0; ic < IC; ic++) {
43 for (int ih = 0; ih < IH; ih++) {
44 for (int iw = 0; iw < IW; iw++) {
45 int dstIndex = b * IC * IH * IW + ic * IH * IW + ih * IW + iw;
48 int offset = ic / ic_off;
50 int ow = iw * stride + offset % stride;
51 int oh = ih * stride + offset / stride;
53 int srcIndex = b * ic_off * ih_off * iw_off + oc * ih_off * iw_off + oh * iw_off + ow;
55 dst_data[dstIndex] = src_data[srcIndex];
67 REG_FACTORY_FOR(ImplFactory<ReorgYoloImpl>, ReorgYolo);
70 } // namespace Extensions
71 } // namespace InferenceEngine