28 #include "tiny_dnn/layers/layer.h"
29 #include "tiny_dnn/activations/activation_function.h"
36 template<
typename Activation>
40 :
layer(in_data_type, std_output_order(
true)) {}
42 std::pair<float_t, float_t>
out_value_range()
const override {
return h_.scale(); }
45 void forward_activation(tensor_t& a_tensor, tensor_t& out_tensor) {
46 serial_size_t out_dim =
out_shape()[0].size();
48 for_i(a_tensor.size(), [&](
int sample) {
49 vec_t& out = a_tensor[sample];
50 vec_t& a = out_tensor[sample];
53 h_.itef(out, a, out_dim);
57 void backward_activation(
const tensor_t& prev_delta,
const tensor_t& this_out, tensor_t& curr_delta) {
60 for_i(this_out.size(), [&](serial_size_t sample) {
61 const vec_t& out_vec = this_out[sample];
62 const vec_t& prev_delta_vec = prev_delta[sample];
63 vec_t& curr_delta_vec = curr_delta[sample];
65 const serial_size_t len = static_cast<serial_size_t>(prev_delta_vec.size());
68 for (serial_size_t c = 0; c < len; c++) {
69 curr_delta_vec[c] = prev_delta_vec[c] * h_.df(out_vec[c]);
73 for (serial_size_t c = 0; c < len; c++) {
74 vec_t df = h_.df(out_vec, c);
75 curr_delta_vec[c] = vectorize::dot(&prev_delta_vec[0], &df[0], len);
Definition: activation_function.h:34
single-input, single-output network with activation function
Definition: feedforward_layer.h:37
std::pair< float_t, float_t > out_value_range() const override
return output value range used only for calculating target value from label-id in final(output) layer...
Definition: feedforward_layer.h:42
base class of all kind of NN layers
Definition: layer.h:62
layer(const std::vector< vector_type > &in_type, const std::vector< vector_type > &out_type)
Defaul layer constructor that instantiates a N-input, M-output layer.
Definition: layer.h:76
virtual std::vector< shape3d > out_shape() const =0
array of output shapes (width x height x depth)