diff --git a/include/fdeep/layers/relu_layer.hpp b/include/fdeep/layers/relu_layer.hpp index 23c866ca..ae8cf0f9 100644 --- a/include/fdeep/layers/relu_layer.hpp +++ b/include/fdeep/layers/relu_layer.hpp @@ -9,6 +9,7 @@ #include "fdeep/layers/activation_layer.hpp" #include +#include #include namespace fdeep { @@ -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(0) && threshold_ == static_cast(0) && max_value_ == std::numeric_limits::max()) { + return transform_tensor([](float_type x) -> float_type { + return std::max(static_cast(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_; diff --git a/include/fdeep/tensor.hpp b/include/fdeep/tensor.hpp index 29f13ee1..99a4a688 100644 --- a/include/fdeep/tensor.hpp +++ b/include/fdeep/tensor.hpp @@ -190,7 +190,10 @@ namespace internal { template tensor transform_tensor(F f, const tensor& m) { - return tensor(m.shape(), fplus::transform_convert(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_to_depth_slices(const tensor& m)