vgg.h 1.91 KB
Newer Older
Shahriar's avatar
Shahriar committed
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef VGG_H
#define VGG_H

#include <torch/torch.h>

namespace vision {
namespace models {
struct VGGImpl : torch::nn::Module {
  torch::nn::Sequential features{nullptr}, classifier{nullptr};

  void _initialize_weights();

  VGGImpl(
      torch::nn::Sequential features,
      int64_t num_classes = 1000,
      bool initialize_weights = true);

  torch::Tensor forward(torch::Tensor x);
};

// VGG 11-layer model (configuration "A")
struct VGG11Impl : VGGImpl {
  VGG11Impl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 13-layer model (configuration "B")
struct VGG13Impl : VGGImpl {
  VGG13Impl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 16-layer model (configuration "D")
struct VGG16Impl : VGGImpl {
  VGG16Impl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 19-layer model (configuration "E")
struct VGG19Impl : VGGImpl {
  VGG19Impl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 11-layer model (configuration "A") with batch normalization
struct VGG11BNImpl : VGGImpl {
  VGG11BNImpl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 13-layer model (configuration "B") with batch normalization
struct VGG13BNImpl : VGGImpl {
  VGG13BNImpl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 16-layer model (configuration "D") with batch normalization
struct VGG16BNImpl : VGGImpl {
  VGG16BNImpl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 19-layer model (configuration 'E') with batch normalization
struct VGG19BNImpl : VGGImpl {
  VGG19BNImpl(int64_t num_classes = 1000, bool initialize_weights = true);
};

TORCH_MODULE(VGG);

TORCH_MODULE(VGG11);
TORCH_MODULE(VGG13);
TORCH_MODULE(VGG16);
TORCH_MODULE(VGG19);

TORCH_MODULE(VGG11BN);
TORCH_MODULE(VGG13BN);
TORCH_MODULE(VGG16BN);
TORCH_MODULE(VGG19BN);

} // namespace models
} // namespace vision

#endif // VGG_H