LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
lbann::callback::confusion_matrix Class Reference

#include <confusion_matrix.hpp>

Inheritance diagram for lbann::callback::confusion_matrix:
[legend]
Collaboration diagram for lbann::callback::confusion_matrix:
[legend]

Public Types

using AbsDistMatType = El::AbstractDistMatrix< DataType >
 

Public Member Functions

 confusion_matrix (std::string &&prediction_layer, std::string &&label_layer, std::string &&prefix)
 
 confusion_matrix (std::string const &prediction_layer, std::string const &label_layer, std::string const &prefix)
 
 confusion_matrix (const confusion_matrix &)
 
confusion_matrixoperator= (const confusion_matrix &)
 
confusion_matrixcopy () const override
 
std::string name () const override
 Return this callback's name. More...
 
void setup (model *m) override
 Called once to set up the callback on the model (after all layers are set up). More...
 
void on_epoch_begin (model *m) override
 Called at the beginning of each epoch. More...
 
void on_epoch_end (model *m) override
 Called immediate after the end of each epoch. More...
 
void on_validation_begin (model *m) override
 Called at the beginning of validation. More...
 
void on_validation_end (model *m) override
 Called immediately after the end of validation. More...
 
void on_test_begin (model *m) override
 Called at the beginning of testing. More...
 
void on_test_end (model *m) override
 Called immediately after the end of testing. More...
 
void on_batch_end (model *m) override
 Called immediately after the end of a (mini-)batch. More...
 
void on_batch_evaluate_end (model *m) override
 Called at the end of a (mini-)batch evaluation (validation / testing). More...
 
- Public Member Functions inherited from lbann::callback_base
 callback_base (int batch_interval=1)
 Initialize a callback with an optional batch interval. More...
 
 callback_base (const callback_base &)=default
 
virtual ~callback_base ()=default
 
virtual void setup (trainer *t)
 Called once to set up the callback on the trainer. More...
 
virtual void on_setup_end (model *m)
 Called at the end of setup. More...
 
virtual void on_train_begin (model *m)
 Called at the beginning of training. More...
 
virtual void on_train_end (model *m)
 Called at the end of training. More...
 
virtual void on_phase_end (model *m)
 Called at the end of every phase (multiple epochs) in a layer-wise model training. More...
 
virtual void on_batch_begin (model *m)
 Called at the beginning of a (mini-)batch. More...
 
virtual void on_forward_prop_begin (model *m)
 Called when a model begins forward propagation. More...
 
virtual void on_forward_prop_begin (model *m, Layer *l)
 Called when a layer begins forward propagation. More...
 
virtual void on_forward_prop_end (model *m)
 Called when a model ends forward propagation. More...
 
virtual void on_forward_prop_end (model *m, Layer *l)
 Called when a layer ends forward propagation. More...
 
virtual void on_backward_prop_begin (model *m)
 Called when a model begins backward propagation. More...
 
virtual void on_backward_prop_begin (model *m, Layer *l)
 Called when a layer begins backward propagation. More...
 
virtual void on_backward_prop_end (model *m)
 Called when a model ends backward propagation. More...
 
virtual void on_backward_prop_end (model *m, Layer *l)
 Called when a layer ends backward propagation. More...
 
virtual void on_optimize_begin (model *m)
 Called when a model begins optimization. More...
 
virtual void on_optimize_begin (model *m, weights *w)
 Called when weights begins optimization. More...
 
virtual void on_optimize_end (model *m)
 Called when a model ends optimization. More...
 
virtual void on_optimize_end (model *m, weights *w)
 Called when weights ends optimization. More...
 
virtual void on_batch_evaluate_begin (model *m)
 Called at the beginning of a (mini-)batch evaluation (validation / testing). More...
 
virtual void on_evaluate_forward_prop_begin (model *m)
 Called when a model begins forward propagation for evaluation (validation / testing). More...
 
virtual void on_evaluate_forward_prop_begin (model *m, Layer *l)
 Called when a layer begins forward propagation for evaluation (validation / testing). More...
 
virtual void on_evaluate_forward_prop_end (model *m)
 Called when a model ends forward propagation for evaluation (validation / testing). More...
 
virtual void on_evaluate_forward_prop_end (model *m, Layer *l)
 Called when a layer ends forward propagation for evaluation (validation / testing). More...
 
int get_batch_interval () const
 Return the batch interval. More...
 
virtual description get_description () const
 Human-readable description. More...
 
template<class Archive >
void serialize (Archive &ar)
 Store state to archive for checkpoint and restart. More...
 
void write_proto (lbann_data::Callback &proto) const
 Write a protobuf description of the callback. More...
 

Private Member Functions

void write_specific_proto (lbann_data::Callback &proto) const final
 
const AbsDistMatTypeget_predictions (const model &m) const
 
const AbsDistMatTypeget_labels (const model &m) const
 
void reset_counts (const model &m)
 
void update_counts (const model &m)
 
void save_confusion_matrix (const model &m)
 

Private Attributes

std::string m_prediction_layer
 
std::string m_label_layer
 
std::string m_prefix
 
std::map< execution_mode, std::vector< El::Int > > m_counts
 
std::unique_ptr< AbsDistMatTypem_predictions_v
 
std::unique_ptr< AbsDistMatTypem_labels_v
 

Additional Inherited Members

- Protected Member Functions inherited from lbann::callback_base
std::string get_multi_trainer_path (const model &m, const std::string &root_dir)
 Build a standard directory hierarchy including trainer ID. More...
 
std::string get_multi_trainer_ec_model_path (const model &m, const std::string &root_dir)
 Build a standard directory hierachy including trainer, execution context, and model information (in that order). More...
 
std::string get_multi_trainer_model_path (const model &m, const std::string &root_dir)
 Build a standard directory hierachy including trainer, model information in that order. More...
 
callback_baseoperator= (const callback_base &)=default
 Copy-assignment operator. More...
 
- Protected Attributes inherited from lbann::callback_base
int m_batch_interval
 Batch methods should once every this many steps. More...
 

Detailed Description

Compute confusion matrix. Confusion matrices are saved in CSV files of the form "<prefix><mode>.csv". The (i,j)-entry is the proportion of samples with prediction i and label j. The prediction and label layers are assumed to output one-hot vectors for each mini-batch sample.

Definition at line 41 of file confusion_matrix.hpp.

Member Typedef Documentation

◆ AbsDistMatType

using lbann::callback::confusion_matrix::AbsDistMatType = El::AbstractDistMatrix<DataType>

Definition at line 44 of file confusion_matrix.hpp.

Constructor & Destructor Documentation

◆ confusion_matrix() [1/3]

lbann::callback::confusion_matrix::confusion_matrix ( std::string &&  prediction_layer,
std::string &&  label_layer,
std::string &&  prefix 
)
Here is the caller graph for this function:

◆ confusion_matrix() [2/3]

lbann::callback::confusion_matrix::confusion_matrix ( std::string const &  prediction_layer,
std::string const &  label_layer,
std::string const &  prefix 
)

◆ confusion_matrix() [3/3]

lbann::callback::confusion_matrix::confusion_matrix ( const confusion_matrix )

Member Function Documentation

◆ copy()

confusion_matrix* lbann::callback::confusion_matrix::copy ( ) const
inlineoverridevirtual

Implements lbann::callback_base.

Definition at line 55 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ get_labels()

const AbsDistMatType& lbann::callback::confusion_matrix::get_labels ( const model m) const
private

Get label matrix.

◆ get_predictions()

const AbsDistMatType& lbann::callback::confusion_matrix::get_predictions ( const model m) const
private

Get prediction matrix.

◆ name()

std::string lbann::callback::confusion_matrix::name ( ) const
inlineoverridevirtual

Return this callback's name.

Implements lbann::callback_base.

Definition at line 59 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_batch_end()

void lbann::callback::confusion_matrix::on_batch_end ( model m)
inlineoverridevirtual

Called immediately after the end of a (mini-)batch.

Reimplemented from lbann::callback_base.

Definition at line 69 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_batch_evaluate_end()

void lbann::callback::confusion_matrix::on_batch_evaluate_end ( model m)
inlineoverridevirtual

Called at the end of a (mini-)batch evaluation (validation / testing).

Reimplemented from lbann::callback_base.

Definition at line 70 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_epoch_begin()

void lbann::callback::confusion_matrix::on_epoch_begin ( model m)
inlineoverridevirtual

Called at the beginning of each epoch.

Reimplemented from lbann::callback_base.

Definition at line 63 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_epoch_end()

void lbann::callback::confusion_matrix::on_epoch_end ( model m)
inlineoverridevirtual

Called immediate after the end of each epoch.

Reimplemented from lbann::callback_base.

Definition at line 64 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_test_begin()

void lbann::callback::confusion_matrix::on_test_begin ( model m)
inlineoverridevirtual

Called at the beginning of testing.

Reimplemented from lbann::callback_base.

Definition at line 67 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_test_end()

void lbann::callback::confusion_matrix::on_test_end ( model m)
inlineoverridevirtual

Called immediately after the end of testing.

Reimplemented from lbann::callback_base.

Definition at line 68 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_validation_begin()

void lbann::callback::confusion_matrix::on_validation_begin ( model m)
inlineoverridevirtual

Called at the beginning of validation.

Reimplemented from lbann::callback_base.

Definition at line 65 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ on_validation_end()

void lbann::callback::confusion_matrix::on_validation_end ( model m)
inlineoverridevirtual

Called immediately after the end of validation.

Reimplemented from lbann::callback_base.

Definition at line 66 of file confusion_matrix.hpp.

Here is the call graph for this function:

◆ operator=()

confusion_matrix& lbann::callback::confusion_matrix::operator= ( const confusion_matrix )

◆ reset_counts()

void lbann::callback::confusion_matrix::reset_counts ( const model m)
private

Reset confusion matrix counts.

Here is the caller graph for this function:

◆ save_confusion_matrix()

void lbann::callback::confusion_matrix::save_confusion_matrix ( const model m)
private

Output confusion matrix to file.

Here is the caller graph for this function:

◆ setup()

void lbann::callback::confusion_matrix::setup ( model m)
overridevirtual

Called once to set up the callback on the model (after all layers are set up).

Reimplemented from lbann::callback_base.

Here is the caller graph for this function:

◆ update_counts()

void lbann::callback::confusion_matrix::update_counts ( const model m)
private

Update confusion matrix counts. Counts are updated with current mini-batch predictions and labels.

Here is the caller graph for this function:

◆ write_specific_proto()

void lbann::callback::confusion_matrix::write_specific_proto ( lbann_data::Callback &  proto) const
finalprivatevirtual

Add callback specific data to prototext

Implements lbann::callback_base.

Here is the caller graph for this function:

Member Data Documentation

◆ m_counts

std::map<execution_mode, std::vector<El::Int> > lbann::callback::confusion_matrix::m_counts
private

Confusion matrix counts. Each vector should be interpreted as a num_classes x num_classes matrix in row-major order. The (i,j)-entry is the number of samples with prediction i and label j.

Definition at line 92 of file confusion_matrix.hpp.

◆ m_label_layer

std::string lbann::callback::confusion_matrix::m_label_layer
private

Name of label layer. This layer is assumed to output one-hot vectors.

Definition at line 83 of file confusion_matrix.hpp.

◆ m_labels_v

std::unique_ptr<AbsDistMatType> lbann::callback::confusion_matrix::m_labels_v
private

"View" into label matrix. This is a CPU matrix. If the label layer keeps data on GPU or in a different distribution than the prediction layer, then this will be a matrix copy rather than a matrix view.

Definition at line 104 of file confusion_matrix.hpp.

◆ m_prediction_layer

std::string lbann::callback::confusion_matrix::m_prediction_layer
private

Name of prediction layer. This layer is assumed to output one-hot vectors.

Definition at line 79 of file confusion_matrix.hpp.

◆ m_predictions_v

std::unique_ptr<AbsDistMatType> lbann::callback::confusion_matrix::m_predictions_v
private

"View" into prediction matrix. This is a CPU matrix. If the prediction layer keeps data on GPU, then this will be a matrix copy rather than a matrix view.

Definition at line 98 of file confusion_matrix.hpp.

◆ m_prefix

std::string lbann::callback::confusion_matrix::m_prefix
private

Prefix for output files.

Definition at line 85 of file confusion_matrix.hpp.


The documentation for this class was generated from the following file: