diff --git a/torchvision/csrc/models/densenet.cpp b/torchvision/csrc/models/densenet.cpp index 0e3a46e04ff..145748b1449 100644 --- a/torchvision/csrc/models/densenet.cpp +++ b/torchvision/csrc/models/densenet.cpp @@ -76,7 +76,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); })); } @@ -91,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) { @@ -157,7 +157,7 @@ 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) @@ -172,7 +172,7 @@ 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) @@ -187,7 +187,7 @@ 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) @@ -202,7 +202,7 @@ 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) diff --git a/torchvision/csrc/models/densenet.h b/torchvision/csrc/models/densenet.h index 3ed6eba0837..7ec6e867698 100644 --- a/torchvision/csrc/models/densenet.h +++ b/torchvision/csrc/models/densenet.h @@ -26,7 +26,7 @@ struct VISION_API DenseNetImpl : torch::nn::Module { 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); @@ -38,7 +38,7 @@ struct VISION_API DenseNet121Impl : DenseNetImpl { 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); @@ -48,7 +48,7 @@ struct VISION_API DenseNet169Impl : DenseNetImpl { 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); @@ -58,7 +58,7 @@ struct VISION_API DenseNet201Impl : DenseNetImpl { 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); @@ -68,7 +68,7 @@ struct VISION_API DenseNet161Impl : DenseNetImpl { 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/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..73d32d98214 100644 --- a/torchvision/csrc/models/vgg.cpp +++ b/torchvision/csrc/models/vgg.cpp @@ -50,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( diff --git a/torchvision/csrc/models/vgg.h b/torchvision/csrc/models/vgg.h index cc9f98aea77..d3cd8917576 100644 --- a/torchvision/csrc/models/vgg.h +++ b/torchvision/csrc/models/vgg.h @@ -12,7 +12,7 @@ struct VISION_API VGGImpl : torch::nn::Module { void _initialize_weights(); VGGImpl( - torch::nn::Sequential features, + const torch::nn::Sequential& features, int64_t num_classes = 1000, bool initialize_weights = true);