27 #ifndef LBANN_LAYERS_LOSS_CATEGORICAL_ACCURACY_HPP_INCLUDED 28 #define LBANN_LAYERS_LOSS_CATEGORICAL_ACCURACY_HPP_INCLUDED 32 #include "lbann/proto/layers.pb.h" 47 template <
typename TensorDataType, data_layout T_layout, El::Device Dev>
65 template <
typename ArchiveT>
70 std::string
get_type()
const override {
return "categorical accuracy"; }
77 void fill_onnx_node(onnx::GraphProto& graph)
const override;
78 #endif // LBANN_HAS_ONNX 92 template <
typename T, data_layout L, El::Device D>
94 lbann_data::Layer& proto)
const 96 proto.set_datatype(proto::ProtoDataType<T>);
97 proto.mutable_categorical_accuracy();
100 #ifdef LBANN_HAS_ONNX 101 template <
typename T, data_layout L, El::Device D>
103 onnx::GraphProto& graph)
const 105 auto* shape = graph.add_initializer();
107 shape->set_data_type(onnx::TensorProto::INT64);
109 shape->add_int64_data(0);
110 shape->add_int64_data(-1);
111 shape->set_doc_string(this->
get_name() +
" shape");
113 auto* equal = graph.add_node();
116 size_t idx = parent->find_child_layer_index(*
this);
121 auto* reshape = graph.add_node();
122 reshape->add_input(parent->get_name() +
"_" +
std::to_string(idx));
123 reshape->add_input(this->
get_name() +
"_shape_0");
124 reshape->add_output(this->
get_name() +
"_reshape_" +
127 reshape->set_op_type(
"Reshape");
128 reshape->set_domain(
"");
129 reshape->set_doc_string(
"Reshape node for Categorical Accuracy Layer");
133 auto* argmax = graph.add_node();
134 argmax->add_input(reshape->output(0));
135 auto* attribute = argmax->add_attribute();
136 attribute->set_name(
"axis");
137 attribute->set_type(onnx::AttributeProto::INT);
138 attribute->set_i(-1);
141 argmax->set_op_type(
"ArgMax");
142 argmax->set_domain(
"");
143 argmax->set_doc_string(
"Argmax node for Categorical Accuracy Layer");
146 equal->add_input(argmax->output(0));
148 equal->add_output(this->
get_name() +
"_equal_0");
149 equal->set_name(this->
get_name() +
"_equal_0");
150 equal->set_op_type(
"Equal");
151 equal->set_domain(
"");
152 equal->set_doc_string(
"Equal node for Categorical Accuracy Layer");
155 auto* cast = graph.add_node();
156 cast->add_input(equal->output(0));
157 auto* attribute = cast->add_attribute();
158 attribute->set_name(
"to");
159 attribute->set_type(onnx::AttributeProto::INT);
160 attribute->set_i(onnx::TensorProto::FLOAT);
165 cast->set_name(this->
get_name() +
"_cast_0");
166 cast->set_op_type(
"Cast");
167 cast->set_domain(
"");
168 cast->set_doc_string(
"Cast node for Categorical Accuracy Layer");
170 #endif // LBANN_HAS_ONNX 172 #ifndef LBANN_CATEGORICAL_ACCURACY_LAYER_INSTANTIATE 174 #define PROTO_DEVICE(T, Device) \ 175 extern template class categorical_accuracy_layer<T, \ 176 data_layout::DATA_PARALLEL, \ 178 extern template class categorical_accuracy_layer< \ 180 data_layout::MODEL_PARALLEL, \ 186 #endif // LBANN_CATEGORICAL_ACCURACY_LAYER_INSTANTIATE 190 #endif // LBANN_LAYERS_LOSS_CATEGORICAL_ACCURACY_HPP_INCLUDED El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
void write_specific_proto(lbann_data::Layer &proto) const final
categorical_accuracy_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
void setup_dims() override
Setup tensor dimensions Called by the 'setup' function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
friend class cereal::access
constexpr El::Device Device
size_t find_parent_layer_index(const Layer &l) const
std::string to_string(El::Device const &d)
void fp_compute() override
Apply layer operation. Called by the 'forward_prop' function. Given the input tensors, the output tensors are populated with computed values.
std::vector< const Layer * > get_parent_layers() const
categorical_accuracy_layer()
categorical_accuracy_layer(lbann_comm *comm)
void serialize(ArchiveT &ar)
std::string get_name() const
Get the layer instance's name.
std::vector< const Layer * > get_child_layers() const
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
data_layout
Data layout that is optimized for different modes of parallelism.
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
size_t find_child_layer_index(const Layer &l) const
std::string get_type() const override
Get the layer type's name.
void set_name(const std::string name)
Set the layer instance's name. Each layer in a model should have a unique, preferably human-readable...
int m_expected_num_parent_layers