Defined in File functional.h
FunctionalImpl: public torch::nn::Cloneable<FunctionalImpl>¶
Wraps a function in a
Sequential sequential( Linear(3, 4), Functional(torch::relu), BatchNorm1d(3), Functional(torch::elu, /*alpha=*/1));
Functionalmodule only accepts a single
Tensoras input, it is possible for the the wrapped function to accept further arguments. However, these have to be bound at construction time. For example, if you want to wrap
torch::leaky_relu, which accepts a
slopescalar as its second argument, with a particular value for its
Functionalmodule, you could write
The value of
0.5is then stored within the
Functionalobject and supplied to the function call at invocation time. Note that such bound values are evaluated eagerly and stored a single time. See the documentation of std::bind for more information on the semantics of argument binding.
After passing any bound arguments, the function must accept a single tensor and return a single tensor.
Functionaloverloads the call operator (
operator()) such that you can invoke it with
template<typename SomeFunction, typename... Args, typename = torch::enable_if_t<(sizeof...(Args) > 0> FunctionalImpl (SomeFunction original_function, Args &&...args)
reset()must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.
pretty_print(std::ostream &stream) const override¶
Pretty prints the
Functionalmodule into the given
inputtensor to the underlying (bound) function object.