LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
layer_metric.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_METRIC_LAYER_METRIC_HPP
28 #define LBANN_METRIC_LAYER_METRIC_HPP
29 
31 #include "lbann/metrics/metric.hpp"
32 
33 namespace lbann {
34 
35 class layer_metric : public metric
36 {
37 
38 public:
39  layer_metric(lbann_comm* comm = nullptr,
40  std::string name = "",
41  std::string unit = "");
42  layer_metric(const layer_metric& other) = default;
43  layer_metric& operator=(const layer_metric& other) = default;
44  virtual ~layer_metric() = default;
45  layer_metric* copy() const override { return new layer_metric(*this); }
46 
48  std::string name() const override;
49  std::string get_unit() const override { return m_unit; }
50 
52  template <class Archive>
53  void serialize(Archive& ar);
54 
56  void set_layer(ViewingLayerPtr l);
58  Layer& get_layer();
60  const Layer& get_layer() const;
61 
63  std::vector<ViewingLayerPtr> get_layer_pointers() const override;
65  void set_layer_pointers(std::vector<ViewingLayerPtr> layers) override;
66 
68  bool save_to_checkpoint_shared(persist& p) override;
70  bool load_from_checkpoint_shared(persist& p) override;
71 
72  bool save_to_checkpoint_distributed(persist& p) override;
73  bool load_from_checkpoint_distributed(persist& p) override;
74 
75 protected:
76  void setup(model& m) override;
77  EvalType evaluate(execution_mode mode, int mini_batch_size) override;
78 
84  const AbsDistMat& ground_truth) override;
85 
86 private:
88  std::string m_name;
92  std::string m_unit;
95 
97  /*abstract_evaluation_*/ Layer& get_evaluation_layer();
98 };
99 
100 } // namespace lbann
101 
102 #endif // LBANN_METRIC_LAYER_METRIC_HPP
layer_metric * copy() const override
std::vector< ViewingLayerPtr > get_layer_pointers() const override
El::AbstractDistMatrix< DataType > AbsDistMat
Definition: base.hpp:120
bool save_to_checkpoint_shared(persist &p) override
std::weak_ptr< Layer > ViewingLayerPtr
Smart pointer to reference a layer object.
Definition: layer.hpp:133
Neural network tensor operation.
Definition: layer.hpp:285
EvalType evaluate_compute(const AbsDistMat &prediction, const AbsDistMat &ground_truth) override
bool load_from_checkpoint_distributed(persist &p) override
std::string name() const override
layer_metric & operator=(const layer_metric &other)=default
layer_metric(lbann_comm *comm=nullptr, std::string name="", std::string unit="")
void set_layer_pointers(std::vector< ViewingLayerPtr > layers) override
Abstract base class for neural network models.
Definition: model.hpp:83
EvalType evaluate(execution_mode mode, int mini_batch_size) override
virtual ~layer_metric()=default
Layer & get_evaluation_layer()
execution_mode
Neural network execution mode.
Definition: base.hpp:229
void serialize(Archive &ar)
bool save_to_checkpoint_distributed(persist &p) override
bool load_from_checkpoint_shared(persist &p) override
ViewingLayerPtr m_layer
void setup(model &m) override
double EvalType
Definition: base.hpp:189
std::string get_unit() const override
void set_layer(ViewingLayerPtr l)