From d8be7c1dbf4592a9731ce0811b0dfbfc33400f77 Mon Sep 17 00:00:00 2001 From: Vasileios Vryniotis Date: Sat, 24 Oct 2020 23:42:30 +0100 Subject: [PATCH 1/4] Minor refactoring based on static analysis on the code of models: - Convert unnecessary value parameter to constant reference. - Use move to avoid unnecessary copies. - Eliminate unused include. --- torchvision/csrc/models/densenet.cpp | 12 +++++++----- torchvision/csrc/models/inception.cpp | 10 +++++----- torchvision/csrc/models/inception.h | 10 +++++----- torchvision/csrc/models/resnet.cpp | 4 ++-- torchvision/csrc/models/resnet.h | 4 ++-- torchvision/csrc/models/squeezenet.cpp | 1 - torchvision/csrc/models/vgg.cpp | 3 ++- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/torchvision/csrc/models/densenet.cpp b/torchvision/csrc/models/densenet.cpp index 0e3a46e04ff..066c3b12ad4 100644 --- a/torchvision/csrc/models/densenet.cpp +++ b/torchvision/csrc/models/densenet.cpp @@ -1,5 +1,7 @@ #include "densenet.h" +#include + #include "modelsimpl.h" namespace vision { @@ -76,7 +78,7 @@ struct _TransitionImpl : torch::nn::SequentialImpl { torch::nn::Conv2d(Options(num_input_features, num_output_features, 1) .stride(1) .bias(false))); - push_back("pool", torch::nn::Functional([](torch::Tensor input) { + push_back("pool", torch::nn::Functional([](const torch::Tensor& input) { return torch::avg_pool2d(input, 2, 2, 0, false, true); })); } @@ -164,7 +166,7 @@ DenseNet121Impl::DenseNet121Impl( : DenseNetImpl( num_classes, growth_rate, - block_config, + std::move(block_config), num_init_features, bn_size, drop_rate) {} @@ -179,7 +181,7 @@ DenseNet169Impl::DenseNet169Impl( : DenseNetImpl( num_classes, growth_rate, - block_config, + std::move(block_config), num_init_features, bn_size, drop_rate) {} @@ -194,7 +196,7 @@ DenseNet201Impl::DenseNet201Impl( : DenseNetImpl( num_classes, growth_rate, - block_config, + std::move(block_config), num_init_features, bn_size, drop_rate) {} @@ -209,7 +211,7 @@ DenseNet161Impl::DenseNet161Impl( : DenseNetImpl( num_classes, growth_rate, - block_config, + std::move(block_config), num_init_features, bn_size, drop_rate) {} diff --git a/torchvision/csrc/models/inception.cpp b/torchvision/csrc/models/inception.cpp index 625de5c4ab2..002bf7ee2d1 100644 --- a/torchvision/csrc/models/inception.cpp +++ b/torchvision/csrc/models/inception.cpp @@ -49,7 +49,7 @@ InceptionAImpl::InceptionAImpl(int64_t in_channels, int64_t pool_features) register_module("branch_pool", branch_pool); } -torch::Tensor InceptionAImpl::forward(torch::Tensor x) { +torch::Tensor InceptionAImpl::forward(const torch::Tensor& x) { auto branch1x1 = this->branch1x1->forward(x); auto branch5x5 = this->branch5x5_1->forward(x); @@ -76,7 +76,7 @@ InceptionBImpl::InceptionBImpl(int64_t in_channels) register_module("branch3x3dbl_3", branch3x3dbl_3); } -torch::Tensor InceptionBImpl::forward(torch::Tensor x) { +torch::Tensor InceptionBImpl::forward(const torch::Tensor& x) { auto branch3x3 = this->branch3x3->forward(x); auto branch3x3dbl = this->branch3x3dbl_1->forward(x); @@ -115,7 +115,7 @@ InceptionCImpl::InceptionCImpl(int64_t in_channels, int64_t channels_7x7) { register_module("branch_pool", branch_pool); } -torch::Tensor InceptionCImpl::forward(torch::Tensor x) { +torch::Tensor InceptionCImpl::forward(const torch::Tensor& x) { auto branch1x1 = this->branch1x1->forward(x); auto branch7x7 = this->branch7x7_1->forward(x); @@ -151,7 +151,7 @@ InceptionDImpl::InceptionDImpl(int64_t in_channels) register_module("branch7x7x3_4", branch7x7x3_4); } -torch::Tensor InceptionDImpl::forward(torch::Tensor x) { +torch::Tensor InceptionDImpl::forward(const torch::Tensor& x) { auto branch3x3 = this->branch3x3_1->forward(x); branch3x3 = this->branch3x3_2->forward(branch3x3); @@ -185,7 +185,7 @@ InceptionEImpl::InceptionEImpl(int64_t in_channels) register_module("branch_pool", branch_pool); } -torch::Tensor InceptionEImpl::forward(torch::Tensor x) { +torch::Tensor InceptionEImpl::forward(const torch::Tensor& x) { auto branch1x1 = this->branch1x1->forward(x); auto branch3x3 = this->branch3x3_1->forward(x); diff --git a/torchvision/csrc/models/inception.h b/torchvision/csrc/models/inception.h index 46c224752cd..8d1d3707c82 100644 --- a/torchvision/csrc/models/inception.h +++ b/torchvision/csrc/models/inception.h @@ -24,7 +24,7 @@ struct VISION_API InceptionAImpl : torch::nn::Module { InceptionAImpl(int64_t in_channels, int64_t pool_features); - torch::Tensor forward(torch::Tensor x); + torch::Tensor forward(const torch::Tensor& x); }; struct VISION_API InceptionBImpl : torch::nn::Module { @@ -32,7 +32,7 @@ struct VISION_API InceptionBImpl : torch::nn::Module { InceptionBImpl(int64_t in_channels); - torch::Tensor forward(torch::Tensor x); + torch::Tensor forward(const torch::Tensor& x); }; struct VISION_API InceptionCImpl : torch::nn::Module { @@ -43,7 +43,7 @@ struct VISION_API InceptionCImpl : torch::nn::Module { InceptionCImpl(int64_t in_channels, int64_t channels_7x7); - torch::Tensor forward(torch::Tensor x); + torch::Tensor forward(const torch::Tensor& x); }; struct VISION_API InceptionDImpl : torch::nn::Module { @@ -52,7 +52,7 @@ struct VISION_API InceptionDImpl : torch::nn::Module { InceptionDImpl(int64_t in_channels); - torch::Tensor forward(torch::Tensor x); + torch::Tensor forward(const torch::Tensor& x); }; struct VISION_API InceptionEImpl : torch::nn::Module { @@ -62,7 +62,7 @@ struct VISION_API InceptionEImpl : torch::nn::Module { InceptionEImpl(int64_t in_channels); - torch::Tensor forward(torch::Tensor x); + torch::Tensor forward(const torch::Tensor& x); }; struct VISION_API InceptionAuxImpl : torch::nn::Module { diff --git a/torchvision/csrc/models/resnet.cpp b/torchvision/csrc/models/resnet.cpp index ce9e95ecf6f..fe8059a15ec 100644 --- a/torchvision/csrc/models/resnet.cpp +++ b/torchvision/csrc/models/resnet.cpp @@ -28,7 +28,7 @@ BasicBlock::BasicBlock( int64_t inplanes, int64_t planes, int64_t stride, - torch::nn::Sequential downsample, + const torch::nn::Sequential& downsample, int64_t groups, int64_t base_width) : stride(stride), downsample(downsample) { @@ -57,7 +57,7 @@ Bottleneck::Bottleneck( int64_t inplanes, int64_t planes, int64_t stride, - torch::nn::Sequential downsample, + const torch::nn::Sequential& downsample, int64_t groups, int64_t base_width) : stride(stride), downsample(downsample) { diff --git a/torchvision/csrc/models/resnet.h b/torchvision/csrc/models/resnet.h index 16a5f183f25..312ad7102da 100644 --- a/torchvision/csrc/models/resnet.h +++ b/torchvision/csrc/models/resnet.h @@ -36,7 +36,7 @@ struct VISION_API BasicBlock : torch::nn::Module { int64_t inplanes, int64_t planes, int64_t stride = 1, - torch::nn::Sequential downsample = nullptr, + const torch::nn::Sequential& downsample = nullptr, int64_t groups = 1, int64_t base_width = 64); @@ -59,7 +59,7 @@ struct VISION_API Bottleneck : torch::nn::Module { int64_t inplanes, int64_t planes, int64_t stride = 1, - torch::nn::Sequential downsample = nullptr, + const torch::nn::Sequential& downsample = nullptr, int64_t groups = 1, int64_t base_width = 64); diff --git a/torchvision/csrc/models/squeezenet.cpp b/torchvision/csrc/models/squeezenet.cpp index cfb26ea58eb..96a9a1800d0 100644 --- a/torchvision/csrc/models/squeezenet.cpp +++ b/torchvision/csrc/models/squeezenet.cpp @@ -1,6 +1,5 @@ #include "squeezenet.h" -#include #include "modelsimpl.h" namespace vision { diff --git a/torchvision/csrc/models/vgg.cpp b/torchvision/csrc/models/vgg.cpp index f746acf6f34..a9fa8df9ed7 100644 --- a/torchvision/csrc/models/vgg.cpp +++ b/torchvision/csrc/models/vgg.cpp @@ -1,6 +1,7 @@ #include "vgg.h" #include +#include #include "modelsimpl.h" namespace vision { @@ -62,7 +63,7 @@ VGGImpl::VGGImpl( torch::nn::Dropout(), torch::nn::Linear(4096, num_classes)); - this->features = features; + this->features = std::move(features); register_module("features", this->features); register_module("classifier", classifier); From b19bc2fcf2f16d960ed65eb0d5bcd02d99bebd6f Mon Sep 17 00:00:00 2001 From: Vasileios Vryniotis Date: Sun, 25 Oct 2020 01:38:24 +0100 Subject: [PATCH 2/4] Replace moves with const references. --- torchvision/csrc/models/densenet.cpp | 20 +++++++++----------- torchvision/csrc/models/densenet.h | 20 ++++++++++---------- torchvision/csrc/models/vgg.cpp | 5 ++--- torchvision/csrc/models/vgg.h | 20 ++++++++++---------- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/torchvision/csrc/models/densenet.cpp b/torchvision/csrc/models/densenet.cpp index 066c3b12ad4..145748b1449 100644 --- a/torchvision/csrc/models/densenet.cpp +++ b/torchvision/csrc/models/densenet.cpp @@ -1,7 +1,5 @@ #include "densenet.h" -#include - #include "modelsimpl.h" namespace vision { @@ -93,7 +91,7 @@ TORCH_MODULE(_Transition); DenseNetImpl::DenseNetImpl( int64_t num_classes, int64_t growth_rate, - std::vector block_config, + const std::vector& block_config, int64_t num_init_features, int64_t bn_size, double drop_rate) { @@ -159,14 +157,14 @@ torch::Tensor DenseNetImpl::forward(torch::Tensor x) { DenseNet121Impl::DenseNet121Impl( int64_t num_classes, int64_t growth_rate, - std::vector block_config, + const std::vector& block_config, int64_t num_init_features, int64_t bn_size, double drop_rate) : DenseNetImpl( num_classes, growth_rate, - std::move(block_config), + block_config, num_init_features, bn_size, drop_rate) {} @@ -174,14 +172,14 @@ DenseNet121Impl::DenseNet121Impl( DenseNet169Impl::DenseNet169Impl( int64_t num_classes, int64_t growth_rate, - std::vector block_config, + const std::vector& block_config, int64_t num_init_features, int64_t bn_size, double drop_rate) : DenseNetImpl( num_classes, growth_rate, - std::move(block_config), + block_config, num_init_features, bn_size, drop_rate) {} @@ -189,14 +187,14 @@ DenseNet169Impl::DenseNet169Impl( DenseNet201Impl::DenseNet201Impl( int64_t num_classes, int64_t growth_rate, - std::vector block_config, + const std::vector& block_config, int64_t num_init_features, int64_t bn_size, double drop_rate) : DenseNetImpl( num_classes, growth_rate, - std::move(block_config), + block_config, num_init_features, bn_size, drop_rate) {} @@ -204,14 +202,14 @@ DenseNet201Impl::DenseNet201Impl( DenseNet161Impl::DenseNet161Impl( int64_t num_classes, int64_t growth_rate, - std::vector block_config, + const std::vector& block_config, int64_t num_init_features, int64_t bn_size, double drop_rate) : DenseNetImpl( num_classes, growth_rate, - std::move(block_config), + block_config, num_init_features, bn_size, drop_rate) {} diff --git a/torchvision/csrc/models/densenet.h b/torchvision/csrc/models/densenet.h index 3ed6eba0837..731d0c7879f 100644 --- a/torchvision/csrc/models/densenet.h +++ b/torchvision/csrc/models/densenet.h @@ -23,10 +23,10 @@ struct VISION_API DenseNetImpl : torch::nn::Module { torch::nn::Sequential features{nullptr}; torch::nn::Linear classifier{nullptr}; - DenseNetImpl( + explicit DenseNetImpl( int64_t num_classes = 1000, int64_t growth_rate = 32, - std::vector block_config = {6, 12, 24, 16}, + const std::vector& block_config = {6, 12, 24, 16}, int64_t num_init_features = 64, int64_t bn_size = 4, double drop_rate = 0); @@ -35,40 +35,40 @@ struct VISION_API DenseNetImpl : torch::nn::Module { }; struct VISION_API DenseNet121Impl : DenseNetImpl { - DenseNet121Impl( + explicit DenseNet121Impl( int64_t num_classes = 1000, int64_t growth_rate = 32, - std::vector block_config = {6, 12, 24, 16}, + const std::vector& block_config = {6, 12, 24, 16}, int64_t num_init_features = 64, int64_t bn_size = 4, double drop_rate = 0); }; struct VISION_API DenseNet169Impl : DenseNetImpl { - DenseNet169Impl( + explicit DenseNet169Impl( int64_t num_classes = 1000, int64_t growth_rate = 32, - std::vector block_config = {6, 12, 32, 32}, + const std::vector& block_config = {6, 12, 32, 32}, int64_t num_init_features = 64, int64_t bn_size = 4, double drop_rate = 0); }; struct VISION_API DenseNet201Impl : DenseNetImpl { - DenseNet201Impl( + explicit DenseNet201Impl( int64_t num_classes = 1000, int64_t growth_rate = 32, - std::vector block_config = {6, 12, 48, 32}, + const std::vector& block_config = {6, 12, 48, 32}, int64_t num_init_features = 64, int64_t bn_size = 4, double drop_rate = 0); }; struct VISION_API DenseNet161Impl : DenseNetImpl { - DenseNet161Impl( + explicit DenseNet161Impl( int64_t num_classes = 1000, int64_t growth_rate = 48, - std::vector block_config = {6, 12, 36, 24}, + const std::vector& block_config = {6, 12, 36, 24}, int64_t num_init_features = 96, int64_t bn_size = 4, double drop_rate = 0); diff --git a/torchvision/csrc/models/vgg.cpp b/torchvision/csrc/models/vgg.cpp index a9fa8df9ed7..73d32d98214 100644 --- a/torchvision/csrc/models/vgg.cpp +++ b/torchvision/csrc/models/vgg.cpp @@ -1,7 +1,6 @@ #include "vgg.h" #include -#include #include "modelsimpl.h" namespace vision { @@ -51,7 +50,7 @@ void VGGImpl::_initialize_weights() { } VGGImpl::VGGImpl( - torch::nn::Sequential features, + const torch::nn::Sequential& features, int64_t num_classes, bool initialize_weights) { classifier = torch::nn::Sequential( @@ -63,7 +62,7 @@ VGGImpl::VGGImpl( torch::nn::Dropout(), torch::nn::Linear(4096, num_classes)); - this->features = std::move(features); + this->features = features; register_module("features", this->features); register_module("classifier", classifier); diff --git a/torchvision/csrc/models/vgg.h b/torchvision/csrc/models/vgg.h index cc9f98aea77..ebb79a9cf53 100644 --- a/torchvision/csrc/models/vgg.h +++ b/torchvision/csrc/models/vgg.h @@ -11,8 +11,8 @@ struct VISION_API VGGImpl : torch::nn::Module { void _initialize_weights(); - VGGImpl( - torch::nn::Sequential features, + explicit VGGImpl( + const torch::nn::Sequential& features, int64_t num_classes = 1000, bool initialize_weights = true); @@ -21,42 +21,42 @@ struct VISION_API VGGImpl : torch::nn::Module { // VGG 11-layer model (configuration "A") struct VISION_API VGG11Impl : VGGImpl { - VGG11Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG11Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 13-layer model (configuration "B") struct VISION_API VGG13Impl : VGGImpl { - VGG13Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG13Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 16-layer model (configuration "D") struct VISION_API VGG16Impl : VGGImpl { - VGG16Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG16Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 19-layer model (configuration "E") struct VISION_API VGG19Impl : VGGImpl { - VGG19Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG19Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 11-layer model (configuration "A") with batch normalization struct VISION_API VGG11BNImpl : VGGImpl { - VGG11BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG11BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 13-layer model (configuration "B") with batch normalization struct VISION_API VGG13BNImpl : VGGImpl { - VGG13BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG13BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 16-layer model (configuration "D") with batch normalization struct VISION_API VGG16BNImpl : VGGImpl { - VGG16BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG16BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 19-layer model (configuration 'E') with batch normalization struct VISION_API VGG19BNImpl : VGGImpl { - VGG19BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG19BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; TORCH_MODULE(VGG); From 7c4b1517efd781341d52a1674e44ac37f3da3dae Mon Sep 17 00:00:00 2001 From: Vasileios Vryniotis Date: Mon, 26 Oct 2020 10:27:53 +0000 Subject: [PATCH 3/4] Fixing formatting. --- torchvision/csrc/models/vgg.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/torchvision/csrc/models/vgg.h b/torchvision/csrc/models/vgg.h index ebb79a9cf53..b5c600a68ab 100644 --- a/torchvision/csrc/models/vgg.h +++ b/torchvision/csrc/models/vgg.h @@ -21,42 +21,58 @@ struct VISION_API VGGImpl : torch::nn::Module { // VGG 11-layer model (configuration "A") struct VISION_API VGG11Impl : VGGImpl { - explicit VGG11Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG11Impl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; // VGG 13-layer model (configuration "B") struct VISION_API VGG13Impl : VGGImpl { - explicit VGG13Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG13Impl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; // VGG 16-layer model (configuration "D") struct VISION_API VGG16Impl : VGGImpl { - explicit VGG16Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG16Impl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; // VGG 19-layer model (configuration "E") struct VISION_API VGG19Impl : VGGImpl { - explicit VGG19Impl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG19Impl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; // VGG 11-layer model (configuration "A") with batch normalization struct VISION_API VGG11BNImpl : VGGImpl { - explicit VGG11BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG11BNImpl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; // VGG 13-layer model (configuration "B") with batch normalization struct VISION_API VGG13BNImpl : VGGImpl { - explicit VGG13BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG13BNImpl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; // VGG 16-layer model (configuration "D") with batch normalization struct VISION_API VGG16BNImpl : VGGImpl { - explicit VGG16BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG16BNImpl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; // VGG 19-layer model (configuration 'E') with batch normalization struct VISION_API VGG19BNImpl : VGGImpl { - explicit VGG19BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); + explicit VGG19BNImpl( + int64_t num_classes = 1000, + bool initialize_weights = true); }; TORCH_MODULE(VGG); From 384f1f3d996615ca0052f8877126dd6e92db25d3 Mon Sep 17 00:00:00 2001 From: Vasileios Vryniotis Date: Mon, 26 Oct 2020 12:57:34 +0000 Subject: [PATCH 4/4] Remove explicit declaration on constructors. --- torchvision/csrc/models/densenet.h | 10 ++++----- torchvision/csrc/models/vgg.h | 34 ++++++++---------------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/torchvision/csrc/models/densenet.h b/torchvision/csrc/models/densenet.h index 731d0c7879f..7ec6e867698 100644 --- a/torchvision/csrc/models/densenet.h +++ b/torchvision/csrc/models/densenet.h @@ -23,7 +23,7 @@ struct VISION_API DenseNetImpl : torch::nn::Module { torch::nn::Sequential features{nullptr}; torch::nn::Linear classifier{nullptr}; - explicit DenseNetImpl( + DenseNetImpl( int64_t num_classes = 1000, int64_t growth_rate = 32, const std::vector& block_config = {6, 12, 24, 16}, @@ -35,7 +35,7 @@ struct VISION_API DenseNetImpl : torch::nn::Module { }; struct VISION_API DenseNet121Impl : DenseNetImpl { - explicit DenseNet121Impl( + DenseNet121Impl( int64_t num_classes = 1000, int64_t growth_rate = 32, const std::vector& block_config = {6, 12, 24, 16}, @@ -45,7 +45,7 @@ struct VISION_API DenseNet121Impl : DenseNetImpl { }; struct VISION_API DenseNet169Impl : DenseNetImpl { - explicit DenseNet169Impl( + DenseNet169Impl( int64_t num_classes = 1000, int64_t growth_rate = 32, const std::vector& block_config = {6, 12, 32, 32}, @@ -55,7 +55,7 @@ struct VISION_API DenseNet169Impl : DenseNetImpl { }; struct VISION_API DenseNet201Impl : DenseNetImpl { - explicit DenseNet201Impl( + DenseNet201Impl( int64_t num_classes = 1000, int64_t growth_rate = 32, const std::vector& block_config = {6, 12, 48, 32}, @@ -65,7 +65,7 @@ struct VISION_API DenseNet201Impl : DenseNetImpl { }; struct VISION_API DenseNet161Impl : DenseNetImpl { - explicit DenseNet161Impl( + DenseNet161Impl( int64_t num_classes = 1000, int64_t growth_rate = 48, const std::vector& block_config = {6, 12, 36, 24}, diff --git a/torchvision/csrc/models/vgg.h b/torchvision/csrc/models/vgg.h index b5c600a68ab..d3cd8917576 100644 --- a/torchvision/csrc/models/vgg.h +++ b/torchvision/csrc/models/vgg.h @@ -11,7 +11,7 @@ struct VISION_API VGGImpl : torch::nn::Module { void _initialize_weights(); - explicit VGGImpl( + VGGImpl( const torch::nn::Sequential& features, int64_t num_classes = 1000, bool initialize_weights = true); @@ -21,58 +21,42 @@ struct VISION_API VGGImpl : torch::nn::Module { // VGG 11-layer model (configuration "A") struct VISION_API VGG11Impl : VGGImpl { - explicit VGG11Impl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG11Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 13-layer model (configuration "B") struct VISION_API VGG13Impl : VGGImpl { - explicit VGG13Impl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG13Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 16-layer model (configuration "D") struct VISION_API VGG16Impl : VGGImpl { - explicit VGG16Impl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG16Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 19-layer model (configuration "E") struct VISION_API VGG19Impl : VGGImpl { - explicit VGG19Impl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG19Impl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 11-layer model (configuration "A") with batch normalization struct VISION_API VGG11BNImpl : VGGImpl { - explicit VGG11BNImpl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG11BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 13-layer model (configuration "B") with batch normalization struct VISION_API VGG13BNImpl : VGGImpl { - explicit VGG13BNImpl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG13BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 16-layer model (configuration "D") with batch normalization struct VISION_API VGG16BNImpl : VGGImpl { - explicit VGG16BNImpl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG16BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; // VGG 19-layer model (configuration 'E') with batch normalization struct VISION_API VGG19BNImpl : VGGImpl { - explicit VGG19BNImpl( - int64_t num_classes = 1000, - bool initialize_weights = true); + VGG19BNImpl(int64_t num_classes = 1000, bool initialize_weights = true); }; TORCH_MODULE(VGG);