3 #include <torch/data/example.h> 4 #include <torch/data/transforms/collate.h> 5 #include <torch/types.h> 12 namespace transforms {
14 template <
typename T = Example<>>
22 std::vector<torch::Tensor> data, targets;
23 data.reserve(examples.size());
24 targets.reserve(examples.size());
25 for (
auto& example : examples) {
26 data.push_back(std::move(example.data));
27 targets.push_back(std::move(example.target));
29 return {torch::stack(data), torch::stack(targets)};
37 :
public Collation<Example<Tensor, example::NoTarget>> {
38 TensorExample apply_batch(std::vector<TensorExample> examples)
override {
39 std::vector<torch::Tensor> data;
40 data.reserve(examples.size());
41 for (
auto& example : examples) {
42 data.push_back(std::move(example.data));
44 return torch::stack(data);
An Example from a dataset.