vgg.h 2.03 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
14
  torch::nn::Sequential features{nullptr}, classifier{nullptr};

  void _initialize_weights();

  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 {
Shahriar's avatar
Shahriar committed
24
25
26
27
  VGG11Impl(int64_t num_classes = 1000, bool initialize_weights = true);
};

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

// VGG 16-layer model (configuration "D")
33
struct VISION_API VGG16Impl : VGGImpl {
Shahriar's avatar
Shahriar committed
34
35
36
37
  VGG16Impl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 19-layer model (configuration "E")
38
struct VISION_API VGG19Impl : VGGImpl {
Shahriar's avatar
Shahriar committed
39
40
41
42
  VGG19Impl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 11-layer model (configuration "A") with batch normalization
43
struct VISION_API VGG11BNImpl : VGGImpl {
Shahriar's avatar
Shahriar committed
44
45
46
47
  VGG11BNImpl(int64_t num_classes = 1000, bool initialize_weights = true);
};

// VGG 13-layer model (configuration "B") with batch normalization
48
struct VISION_API VGG13BNImpl : VGGImpl {
Shahriar's avatar
Shahriar committed
49
50
51
52
  VGG13BNImpl(int64_t num_classes = 1000, bool initialize_weights = true);
};

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

// VGG 19-layer model (configuration 'E') with batch normalization
58
struct VISION_API VGG19BNImpl : VGGImpl {
Shahriar's avatar
Shahriar committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  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