vgg.h 2.21 KB
Newer Older
Shahriar's avatar
Shahriar committed
1
2
3
4
#ifndef VGG_H
#define VGG_H

#include <torch/torch.h>
5
#include "general.h"
Shahriar's avatar
Shahriar committed
6
7
8

namespace vision {
namespace models {
9
struct VISION_API VGGImpl : torch::nn::Module {
Shahriar's avatar
Shahriar committed
10
11
12
13
  torch::nn::Sequential features{nullptr}, classifier{nullptr};

  void _initialize_weights();

14
  explicit VGGImpl(
15
      const torch::nn::Sequential& features,
Shahriar's avatar
Shahriar committed
16
17
18
19
20
21
22
      int64_t num_classes = 1000,
      bool initialize_weights = true);

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

// VGG 11-layer model (configuration "A")
23
struct VISION_API VGG11Impl : VGGImpl {
24
25
26
  explicit VGG11Impl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
27
28
29
};

// VGG 13-layer model (configuration "B")
30
struct VISION_API VGG13Impl : VGGImpl {
31
32
33
  explicit VGG13Impl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
34
35
36
};

// VGG 16-layer model (configuration "D")
37
struct VISION_API VGG16Impl : VGGImpl {
38
39
40
  explicit VGG16Impl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
41
42
43
};

// VGG 19-layer model (configuration "E")
44
struct VISION_API VGG19Impl : VGGImpl {
45
46
47
  explicit VGG19Impl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
48
49
50
};

// VGG 11-layer model (configuration "A") with batch normalization
51
struct VISION_API VGG11BNImpl : VGGImpl {
52
53
54
  explicit VGG11BNImpl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
55
56
57
};

// VGG 13-layer model (configuration "B") with batch normalization
58
struct VISION_API VGG13BNImpl : VGGImpl {
59
60
61
  explicit VGG13BNImpl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
62
63
64
};

// VGG 16-layer model (configuration "D") with batch normalization
65
struct VISION_API VGG16BNImpl : VGGImpl {
66
67
68
  explicit VGG16BNImpl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
69
70
71
};

// VGG 19-layer model (configuration 'E') with batch normalization
72
struct VISION_API VGG19BNImpl : VGGImpl {
73
74
75
  explicit VGG19BNImpl(
      int64_t num_classes = 1000,
      bool initialize_weights = true);
Shahriar's avatar
Shahriar committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
};

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