1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
// Copyright 2016, Tobias Hermann.
// https://github.com/Dobiasd/frugally-deep
// Distributed under the MIT License.
// (See accompanying LICENSE file or at
// https://opensource.org/licenses/MIT)
#pragma once
#include "fdeep/layers/layer.hpp"
#include <fplus/fplus.hpp>
#include <cassert>
#include <cstddef>
#include <string>
#include <vector>
namespace fdeep {
namespace internal {
class upsampling_1d_layer : public layer {
public:
explicit upsampling_1d_layer(const std::string& name,
const std::size_t size)
: layer(name)
, size_(size)
{
}
protected:
tensors apply_impl(const tensors& inputs) const override final
{
const auto& input = single_tensor_from_tensors(inputs);
assertion(input.shape().rank() == 2, "invalid input shape for Upsampling1D");
return { upsampling_1d_rank_2(input) };
}
tensor upsampling_1d_rank_2(const tensor& input) const
{
assertion(input.shape().rank() == 2, "invalid rank for upsampling");
tensor out_vol(tensor_shape(
input.shape().width_ * size_,
input.shape().depth_),
0);
for (std::size_t x = 0; x < out_vol.shape().width_; ++x) {
for (std::size_t z = 0; z < out_vol.shape().depth_; ++z) {
const std::size_t x_in = x / size_;
out_vol.set_ignore_rank(tensor_pos(x, z), input.get_ignore_rank(tensor_pos(x_in, z)));
}
}
return { out_vol };
}
std::size_t size_;
};
}
}
|