reid from https://github.com/michuanhaohao/reid-strong-baseline
zhangmeng
2020-01-10 c3765bd24fe73747688a0ec2a550f219c9acb384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
 
#include <torch/types.h>
 
namespace torch {
namespace data {
 
/// An `Example` from a dataset.
///
/// A dataset consists of data and an associated target (label).
template <typename Data = Tensor, typename Target = Tensor>
struct Example {
  using DataType = Data;
  using TargetType = Target;
 
  Example() = default;
  Example(Data data, Target target)
      : data(std::move(data)), target(std::move(target)) {}
 
  Data data;
  Target target;
};
 
namespace example {
using NoTarget = void;
} //  namespace example
 
/// A specialization for `Example` that does not have have a target.
///
/// This class exists so that code can be written for a templated `Example`
/// type, and work both for labeled and unlabeled datasets.
template <typename Data>
struct Example<Data, example::NoTarget> {
  using DataType = Data;
  using TargetType = example::NoTarget;
 
  Example() = default;
  /* implicit */ Example(Data data) : data(std::move(data)) {}
 
  // When a DataLoader returns an Example like this, that example should be
  // implicitly convertible to the underlying data type.
 
  operator Data&() {
    return data;
  }
  operator const Data&() const {
    return data;
  }
 
  Data data;
};
 
using TensorExample = Example<Tensor, example::NoTarget>;
} // namespace data
} // namespace torch