Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions include/fdeep/layers/relu_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "fdeep/layers/activation_layer.hpp"

#include <algorithm>
#include <limits>
#include <string>

namespace fdeep {
Expand All @@ -30,14 +31,20 @@ namespace internal {
protected:
tensor transform_input(const tensor& in_vol) const override
{
auto activation_function = [&](float_type x) -> float_type {
if (negative_slope_ == static_cast<float_type>(0) && threshold_ == static_cast<float_type>(0) && max_value_ == std::numeric_limits<float_type>::max()) {
return transform_tensor([](float_type x) -> float_type {
return std::max(static_cast<float_type>(0), x);
},
in_vol);
}
return transform_tensor([&](float_type x) -> float_type {
if (x >= max_value_)
return max_value_;
if (threshold_ <= x && x < max_value_)
return x;
return negative_slope_ * (x - threshold_);
};
return transform_tensor(activation_function, in_vol);
},
in_vol);
}
float_type max_value_;
float_type negative_slope_;
Expand Down
5 changes: 4 additions & 1 deletion include/fdeep/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ namespace internal {
template <typename F>
tensor transform_tensor(F f, const tensor& m)
{
return tensor(m.shape(), fplus::transform_convert<float_vec>(f, *m.as_vector()));
const auto& src = *m.as_vector();
float_vec result(src.size());
std::transform(src.begin(), src.end(), result.begin(), f);
return tensor(m.shape(), std::move(result));
}

inline std::vector<tensor> tensor_to_depth_slices(const tensor& m)
Expand Down