ctc_loss.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include "ngraph/op/op.hpp"
8 
9 namespace ngraph
10 {
11  namespace op
12  {
13  namespace v4
14  {
15  class NGRAPH_API CTCLoss : public Op
16  {
17  public:
18  static constexpr NodeTypeInfo type_info{"CTCLoss", 0};
19  const NodeTypeInfo& get_type_info() const override { return type_info; }
20  CTCLoss() = default;
21  /// \brief Constructs a CTCLoss operation
22  ///
23  /// \param logits 3-D tensor of logits
24  /// \param logit_length 1-D tensor of length for each object from
25  /// a batch
26  /// \param labels 2-D tensor of labels for which likelyhood
27  /// is estimated using logist
28  /// \param label_length 1-D tensor of length for each label
29  /// sequence
30  /// \param blank_index Scalar used to mark a blank index
31  /// \param preprocess_collapse_repeated Flag for preprocessing labels before loss
32  /// calculation
33  /// \param ctc_merge_repeated Flag for merging repeated characters in a
34  /// potential alignment
35  /// \param unique Flag to find unique elements in a target
36  /// before matching with alignment
37  CTCLoss(const Output<Node>& logits,
38  const Output<Node>& logit_length,
39  const Output<Node>& labels,
40  const Output<Node>& label_length,
41  const bool preprocess_collapse_repeated = false,
42  const bool ctc_merge_repeated = true,
43  const bool unique = false);
44 
45  CTCLoss(const Output<Node>& logits,
46  const Output<Node>& logit_length,
47  const Output<Node>& labels,
48  const Output<Node>& label_length,
49  const Output<Node>& blank_index,
50  const bool preprocess_collapse_repeated = false,
51  const bool ctc_merge_repeated = true,
52  const bool unique = false);
53 
54  void validate_and_infer_types() override;
55  bool visit_attributes(AttributeVisitor& visitor) override;
56  virtual std::shared_ptr<Node>
57  clone_with_new_inputs(const OutputVector& new_args) const override;
58 
59  bool get_preprocess_collapse_repeated() const
60  {
61  return preprocess_collapse_repeated_;
62  }
63  bool get_ctc_merge_repeated() const { return ctc_merge_repeated_; }
64  bool get_unique() const { return unique_; }
65 
66  private:
67  bool preprocess_collapse_repeated_;
68  bool ctc_merge_repeated_;
69  bool unique_;
70  };
71  } // namespace v4
72  } // namespace op
73 } // namespace ngraph
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:59
A handle for one of a node's outputs.
Definition: node_output.hpp:33
Root of all actual ops.
Definition: op.hpp:17
Definition: ctc_loss.hpp:16
CTCLoss(const Output< Node > &logits, const Output< Node > &logit_length, const Output< Node > &labels, const Output< Node > &label_length, const bool preprocess_collapse_repeated=false, const bool ctc_merge_repeated=true, const bool unique=false)
Constructs a CTCLoss operation.
const NodeTypeInfo & get_type_info() const override
Definition: ctc_loss.hpp:19
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:16
Definition: type.hpp:27