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
56
57
#pragma once
 
#include <torch/nn/pimpl.h>
#include <torch/optim/optimizer.h>
#include <torch/optim/serialize.h>
#include <torch/types.h>
 
#include <utility>
#include <vector>
 
namespace torch {
namespace serialize {
class OutputArchive;
class InputArchive;
} // namespace serialize
} // namespace torch
 
namespace torch {
namespace optim {
 
struct TORCH_API AdagradOptions {
  AdagradOptions(double learning_rate);
  TORCH_ARG(double, learning_rate);
  TORCH_ARG(double, lr_decay) = 0;
  TORCH_ARG(double, weight_decay) = 0;
};
 
class TORCH_API Adagrad : public Optimizer {
 public:
  template <typename ParameterContainer>
  explicit Adagrad(
      ParameterContainer&& parameters,
      const AdagradOptions& options_)
      : Optimizer(std::forward<ParameterContainer>(parameters)),
        options(options_) {}
 
  void step() override;
 
  AdagradOptions options;
 
  void save(serialize::OutputArchive& archive) const override;
  void load(serialize::InputArchive& archive) override;
 
  std::vector<Tensor> sum_buffers;
  std::vector<int64_t> step_buffers;
 
 private:
  Adagrad() : options(0) {}
 
  template <typename Self, typename Archive>
  static void serialize(Self& self, Archive& archive) {
    _TORCH_OPTIM_SERIALIZE(sum_buffers);
    _TORCH_OPTIM_SERIALIZE(step_buffers);
  }
};
} // namespace optim
} // namespace torch