Caffe2 - C++ API
A deep learning, cross platform ML framework
base.h
1 #pragma once
2 
3 #include <torch/types.h>
4 
5 #include <utility>
6 #include <vector>
7 
8 namespace torch {
9 namespace data {
10 namespace transforms {
11 
13 template <typename InputBatch, typename OutputBatch>
15  public:
16  using InputBatchType = InputBatch;
17  using OutputBatchType = OutputBatch;
18 
19  virtual ~BatchTransform() = default;
20 
22  virtual OutputBatch apply_batch(InputBatch input_batch) = 0;
23 };
24 
31 template <typename Input, typename Output>
32 class Transform
33  : public BatchTransform<std::vector<Input>, std::vector<Output>> {
34  public:
35  using InputType = Input;
36  using OutputType = Output;
37 
39  virtual OutputType apply(InputType input) = 0;
40 
42  std::vector<Output> apply_batch(std::vector<Input> input_batch) override {
43  std::vector<Output> output_batch;
44  output_batch.reserve(input_batch.size());
45  for (auto&& input : input_batch) {
46  output_batch.push_back(apply(std::move(input)));
47  }
48  return output_batch;
49  }
50 };
51 } // namespace transforms
52 } // namespace data
53 } // namespace torch
Definition: static.cpp:76
virtual OutputBatch apply_batch(InputBatch input_batch)=0
Applies the transformation to the given input_batch.
Definition: jit_type.h:17
A transformation of a batch to a new batch.
Definition: base.h:14
A transformation of individual input examples to individual output examples.
Definition: base.h:32
std::vector< Output > apply_batch(std::vector< Input > input_batch) override
Applies the transformation over the entire input_batch.
Definition: base.h:42