ctc_loss.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include "ngraph/op/op.hpp"
20 
21 namespace ngraph
22 {
23  namespace op
24  {
25  namespace v4
26  {
27  class NGRAPH_API CTCLoss : public Op
28  {
29  public:
30  static constexpr NodeTypeInfo type_info{"CTCLoss", 0};
31  const NodeTypeInfo& get_type_info() const override { return type_info; }
32  CTCLoss() = default;
33  /// \brief Constructs a CTCLoss operation
34  ///
35  /// \param logits 3-D tensor of logits
36  /// \param logit_length 1-D tensor of lenght for each object from
37  /// a batch
38  /// \param labels 2-D tensor of labels for which likelyhood
39  /// is estimated using logist
40  /// \param label_length 1-D tensor of length for each label
41  /// sequence
42  /// \param blank_index Scalar used to mark a blank index
43  /// \param preprocess_collapse_repeated Flag for preprocessing labels before loss
44  /// calculation
45  /// \param ctc_merge_repeated Flag for merging repeated characters in a
46  /// potential alignment
47  /// \param unique Flag to find unique elements in a target
48  /// before matching with alignment
49  CTCLoss(const Output<Node>& logits,
50  const Output<Node>& logit_length,
51  const Output<Node>& labels,
52  const Output<Node>& label_length,
53  const bool preprocess_collapse_repeated = false,
54  const bool ctc_merge_repeated = true,
55  const bool unique = false);
56 
57  CTCLoss(const Output<Node>& logits,
58  const Output<Node>& logit_length,
59  const Output<Node>& labels,
60  const Output<Node>& label_length,
61  const Output<Node>& blank_index,
62  const bool preprocess_collapse_repeated = false,
63  const bool ctc_merge_repeated = true,
64  const bool unique = false);
65 
66  void validate_and_infer_types() override;
67  bool visit_attributes(AttributeVisitor& visitor) override;
68  virtual std::shared_ptr<Node>
69  clone_with_new_inputs(const OutputVector& new_args) const override;
70 
71  bool get_preprocess_collapse_repeated() const
72  {
73  return preprocess_collapse_repeated_;
74  }
75  bool get_ctc_merge_repeated() const { return ctc_merge_repeated_; }
76  bool get_unique() const { return unique_; }
77  private:
78  bool preprocess_collapse_repeated_;
79  bool ctc_merge_repeated_;
80  bool unique_;
81  };
82  }
83  }
84 }
ngraph::op::v4::CTCLoss::get_type_info
const NodeTypeInfo & get_type_info() const override
Definition: ctc_loss.hpp:31
ngraph::op::v4::CTCLoss
Definition: ctc_loss.hpp:28
ngraph::op::v4::CTCLoss::CTCLoss
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.
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::op::v4::CTCLoss::validate_and_infer_types
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70
ngraph::op::Op
Root of all actual ops.
Definition: op.hpp:29