upsampling.cpp 3.5 KB
Newer Older
openvino-pushbot's avatar
openvino-pushbot committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

///////////////////////////////////////////////////////////////////////////////////////////////////
#include "upsampling_inst.h"
#include "primitive_type_base.h"
#include "error_handler.h"
21
#include <string>
openvino-pushbot's avatar
openvino-pushbot committed
22

23
namespace cldnn {
24
primitive_type_id upsampling::type_id() {
openvino-pushbot's avatar
openvino-pushbot committed
25 26 27 28
    static primitive_type_base<upsampling> instance;
    return &instance;
}

29 30 31
layout upsampling_inst::calc_output_layout(upsampling_node const& node) {
    assert(static_cast<bool>(node.get_primitive()->output_data_type) == false &&
           "Output data type forcing is not supported for upsampling_node!");
openvino-pushbot's avatar
openvino-pushbot committed
32 33 34
    auto desc = node.get_primitive();
    auto input_layout = node.input().get_output_layout();

35 36 37 38
    auto result_sizes = desc->output_size;

    CLDNN_ERROR_NOT_EQUAL(node.id(), "Input batch size", input_layout.size.batch[0], "output batch size", result_sizes.batch[0], "");
    CLDNN_ERROR_NOT_EQUAL(node.id(), "Input feature size", input_layout.size.feature[0], "output feature size", result_sizes.feature[0], "");
openvino-pushbot's avatar
openvino-pushbot committed
39

40
    auto result = layout({input_layout.data_type, input_layout.format, result_sizes});
openvino-pushbot's avatar
openvino-pushbot committed
41 42 43
    return result;
}

44 45 46 47 48 49 50 51
std::string upsampling_inst::to_string(upsampling_node const& node) {
    std::stringstream primitive_description;
    auto desc = node.get_primitive();
    auto& input_1 = node.input();
    auto activation = desc->with_activation ? " true" : "false";
    std::string str_type;
    switch (desc->sample_type) {
        case upsampling_sample_type::nearest:
openvino-pushbot's avatar
openvino-pushbot committed
52 53
            str_type = "nearest";
            break;
54
        case upsampling_sample_type::bilinear:
openvino-pushbot's avatar
openvino-pushbot committed
55 56
            str_type = "bilinear";
            break;
57
        default:
openvino-pushbot's avatar
openvino-pushbot committed
58 59 60 61
            str_type = "not supported sample type";
            break;
    }

62 63
    primitive_description << "id: " << desc->id << ", type: upsampling"
                          << "\n\tinput_1: " << input_1.id() << ", count: " << input_1.get_output_layout().count()
64
                          << ",  size: " << input_1.get_output_layout().size
65 66 67 68 69 70
                          << "\n\tnum_filter: " << desc->num_filter << "\n\tsample_type: " << str_type
                          << "\n\twith activation: " << activation << ", slope: " << desc->activation_negative_slope
                          << "\n\toutput padding lower size: " << desc->output_padding.lower_size()
                          << "\n\toutput padding upper size: " << desc->output_padding.upper_size()
                          << "\n\toutput: count: " << node.get_output_layout().count()
                          << ",  size: " << node.get_output_layout().size << '\n';
openvino-pushbot's avatar
openvino-pushbot committed
71 72 73 74

    return primitive_description.str();
}

75 76 77 78 79
upsampling_inst::typed_primitive_inst(network_impl& network, upsampling_node const& node) : parent(network, node) {
    if (argument.sample_type == upsampling_sample_type::bilinear)
        CLDNN_ERROR_MESSAGE(
            node.id(),
            "Upsampling primitive instance with bilinear filtering should be replaced by deconvolution!");
openvino-pushbot's avatar
openvino-pushbot committed
80
}
81
}  // namespace cldnn