OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
pooling_layer_3d.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// P O O L I N G L A Y E R 3 D C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#pragma once
10
11#include "layer.h"
12#include "operators.h"
13#include "pooling_layer.h"
14
15namespace opennn
16{
17
19class Pooling3d final : public Layer
20{
21public:
22
27 Pooling3d(const Shape& = {0, 0},
29 const string& = "sequence_pooling_layer");
30
32 Shape get_input_shape() const override { return {sequence_length, input_features}; }
33
35 Shape get_output_shape() const override;
36
37 Index get_sequence_length() const { return sequence_length; }
38 Index get_input_features() const { return input_features; }
39
40 PoolingMethod get_pooling_method() const { return pooling_method; }
41
43 vector<TensorSpec> get_forward_specs(Index batch_size) const override;
44
46 void set(const Shape&, const PoolingMethod&, const string&);
47
49 void set_input_shape(const Shape& new_input_shape) override
50 {
51 set(new_input_shape, pooling_method, get_label());
52 }
53
54 void set_output_shape(const Shape&) override {}
55
58
60 void set_pooling_method(const string&);
61
63 void read_JSON_body(const Json*) override;
64
66 void write_JSON_body(JsonWriter&) const override;
67
68private:
69
70 Index sequence_length = 0;
71 Index input_features = 0;
72
74
75 Pool3dOp pool3d;
76
77 enum Forward { Input, MaximalIndices, Output };
78};
79
80}
81
82// OpenNN: Open Neural Networks Library.
83// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
84// Licensed under the GNU Lesser General Public License v2.1 or later.
Definition json.h:85
Definition json.h:23
const string & get_label() const
Definition layer.h:112
Layer()=default
void set_output_shape(const Shape &) override
Sets the output shape; subclasses override when the output is user-configurable.
Definition pooling_layer_3d.h:54
Shape get_input_shape() const override
Returns the input tensor shape (sequence_length, input_features).
Definition pooling_layer_3d.h:32
void set_pooling_method(PoolingMethod)
Sets the pooling method via enum.
void set_input_shape(const Shape &new_input_shape) override
Updates the layer for a new input shape, preserving pooling method and label.
Definition pooling_layer_3d.h:49
Pooling3d(const Shape &={0, 0}, const PoolingMethod &=PoolingMethod::MaxPooling, const string &="sequence_pooling_layer")
Constructs a sequence pooling layer.
Index get_input_features() const
Definition pooling_layer_3d.h:38
Index get_sequence_length() const
Definition pooling_layer_3d.h:37
vector< TensorSpec > get_forward_specs(Index batch_size) const override
Returns the tensor specifications used during forward propagation.
void set_pooling_method(const string &)
Sets the pooling method by name ("MaxPooling" or "AveragePooling").
void set(const Shape &, const PoolingMethod &, const string &)
Reconfigures the layer with a new input shape, pooling method and name.
void write_JSON_body(JsonWriter &) const override
Writes the layer configuration to a JSON writer.
void read_JSON_body(const Json *) override
Reads the layer configuration from a JSON node.
Shape get_output_shape() const override
Returns the output tensor shape after sequence-axis pooling.
PoolingMethod get_pooling_method() const
Definition pooling_layer_3d.h:40
Definition adaptive_moment_estimation.h:14
PoolingMethod
Pooling reduction method used by Pooling and Pooling3d layers.
Definition pooling_layer.h:19
@ MaxPooling
Definition pooling_layer.h:20
Sequence-wide 1D pooling over the embedding dimension (mean or max).
Definition operators.h:930
Fixed-capacity small-vector describing tensor dimensions (rank up to MaxRank).
Definition tensor_utilities.h:42