Skip to content

Enabling exporting symbols on windows #1035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion torchvision/csrc/models/alexnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define ALEXNET_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {
// AlexNet model architecture from the
// "One weird trick..." <https://arxiv.org/abs/1404.5997> paper.
struct AlexNetImpl : torch::nn::Module {
struct VISION_API AlexNetImpl : torch::nn::Module {
torch::nn::Sequential features{nullptr}, classifier{nullptr};

AlexNetImpl(int64_t num_classes = 1000);
Expand Down
11 changes: 6 additions & 5 deletions torchvision/csrc/models/densenet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DENSENET_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {
Expand All @@ -18,7 +19,7 @@ namespace models {
// bn_size (int) - multiplicative factor for number of bottle neck layers
// (i.e. bn_size * k features in the bottleneck layer)
// drop_rate (float) - dropout rate after each dense layer
struct DenseNetImpl : torch::nn::Module {
struct VISION_API DenseNetImpl : torch::nn::Module {
torch::nn::Sequential features{nullptr};
torch::nn::Linear classifier{nullptr};

Expand All @@ -33,7 +34,7 @@ struct DenseNetImpl : torch::nn::Module {
torch::Tensor forward(torch::Tensor x);
};

struct DenseNet121Impl : DenseNetImpl {
struct VISION_API DenseNet121Impl : DenseNetImpl {
DenseNet121Impl(
int64_t num_classes = 1000,
int64_t growth_rate = 32,
Expand All @@ -43,7 +44,7 @@ struct DenseNet121Impl : DenseNetImpl {
double drop_rate = 0);
};

struct DenseNet169Impl : DenseNetImpl {
struct VISION_API DenseNet169Impl : DenseNetImpl {
DenseNet169Impl(
int64_t num_classes = 1000,
int64_t growth_rate = 32,
Expand All @@ -53,7 +54,7 @@ struct DenseNet169Impl : DenseNetImpl {
double drop_rate = 0);
};

struct DenseNet201Impl : DenseNetImpl {
struct VISION_API DenseNet201Impl : DenseNetImpl {
DenseNet201Impl(
int64_t num_classes = 1000,
int64_t growth_rate = 32,
Expand All @@ -63,7 +64,7 @@ struct DenseNet201Impl : DenseNetImpl {
double drop_rate = 0);
};

struct DenseNet161Impl : DenseNetImpl {
struct VISION_API DenseNet161Impl : DenseNetImpl {
DenseNet161Impl(
int64_t num_classes = 1000,
int64_t growth_rate = 48,
Expand Down
14 changes: 14 additions & 0 deletions torchvision/csrc/models/general.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef VISION_GENERAL_H
#define VISION_GENERAL_H

#ifdef _WIN32
#if defined(torchvision_EXPORTS)
#define VISION_API __declspec(dllexport)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about dllimport?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it seemed to work locally - it built and the convertmodels sample ran as expected. I've added the dllimport now, and it also works, although I had to remove a spurious VISION_API call that I had put in a definition in resnet.h

#else
#define VISION_API __declspec(dllimport)
#endif
#else
#define VISION_API
#endif

#endif // VISION_GENERAL_H
11 changes: 6 additions & 5 deletions torchvision/csrc/models/googlenet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define GOOGLENET_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {

namespace _googlenetimpl {
struct BasicConv2dImpl : torch::nn::Module {
struct VISION_API BasicConv2dImpl : torch::nn::Module {
torch::nn::Conv2d conv{nullptr};
torch::nn::BatchNorm bn{nullptr};

Expand All @@ -18,7 +19,7 @@ struct BasicConv2dImpl : torch::nn::Module {

TORCH_MODULE(BasicConv2d);

struct InceptionImpl : torch::nn::Module {
struct VISION_API InceptionImpl : torch::nn::Module {
BasicConv2d branch1{nullptr};
torch::nn::Sequential branch2, branch3, branch4;

Expand All @@ -36,7 +37,7 @@ struct InceptionImpl : torch::nn::Module {

TORCH_MODULE(Inception);

struct InceptionAuxImpl : torch::nn::Module {
struct VISION_API InceptionAuxImpl : torch::nn::Module {
BasicConv2d conv{nullptr};
torch::nn::Linear fc1{nullptr}, fc2{nullptr};

Expand All @@ -49,13 +50,13 @@ TORCH_MODULE(InceptionAux);

} // namespace _googlenetimpl

struct GoogLeNetOutput {
struct VISION_API GoogLeNetOutput {
torch::Tensor output;
torch::Tensor aux1;
torch::Tensor aux2;
};

struct GoogLeNetImpl : torch::nn::Module {
struct VISION_API GoogLeNetImpl : torch::nn::Module {
bool aux_logits, transform_input;

_googlenetimpl::BasicConv2d conv1{nullptr}, conv2{nullptr}, conv3{nullptr};
Expand Down
19 changes: 10 additions & 9 deletions torchvision/csrc/models/inception.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define INCEPTION_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {
namespace _inceptionimpl {
struct BasicConv2dImpl : torch::nn::Module {
struct VISION_API BasicConv2dImpl : torch::nn::Module {
torch::nn::Conv2d conv{nullptr};
torch::nn::BatchNorm bn{nullptr};

Expand All @@ -17,7 +18,7 @@ struct BasicConv2dImpl : torch::nn::Module {

TORCH_MODULE(BasicConv2d);

struct InceptionAImpl : torch::nn::Module {
struct VISION_API InceptionAImpl : torch::nn::Module {
BasicConv2d branch1x1, branch5x5_1, branch5x5_2, branch3x3dbl_1,
branch3x3dbl_2, branch3x3dbl_3, branch_pool;

Expand All @@ -26,15 +27,15 @@ struct InceptionAImpl : torch::nn::Module {
torch::Tensor forward(torch::Tensor x);
};

struct InceptionBImpl : torch::nn::Module {
struct VISION_API InceptionBImpl : torch::nn::Module {
BasicConv2d branch3x3, branch3x3dbl_1, branch3x3dbl_2, branch3x3dbl_3;

InceptionBImpl(int64_t in_channels);

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

struct InceptionCImpl : torch::nn::Module {
struct VISION_API InceptionCImpl : torch::nn::Module {
BasicConv2d branch1x1{nullptr}, branch7x7_1{nullptr}, branch7x7_2{nullptr},
branch7x7_3{nullptr}, branch7x7dbl_1{nullptr}, branch7x7dbl_2{nullptr},
branch7x7dbl_3{nullptr}, branch7x7dbl_4{nullptr}, branch7x7dbl_5{nullptr},
Expand All @@ -45,7 +46,7 @@ struct InceptionCImpl : torch::nn::Module {
torch::Tensor forward(torch::Tensor x);
};

struct InceptionDImpl : torch::nn::Module {
struct VISION_API InceptionDImpl : torch::nn::Module {
BasicConv2d branch3x3_1, branch3x3_2, branch7x7x3_1, branch7x7x3_2,
branch7x7x3_3, branch7x7x3_4;

Expand All @@ -54,7 +55,7 @@ struct InceptionDImpl : torch::nn::Module {
torch::Tensor forward(torch::Tensor x);
};

struct InceptionEImpl : torch::nn::Module {
struct VISION_API InceptionEImpl : torch::nn::Module {
BasicConv2d branch1x1, branch3x3_1, branch3x3_2a, branch3x3_2b,
branch3x3dbl_1, branch3x3dbl_2, branch3x3dbl_3a, branch3x3dbl_3b,
branch_pool;
Expand All @@ -64,7 +65,7 @@ struct InceptionEImpl : torch::nn::Module {
torch::Tensor forward(torch::Tensor x);
};

struct InceptionAuxImpl : torch::nn::Module {
struct VISION_API InceptionAuxImpl : torch::nn::Module {
BasicConv2d conv0;
BasicConv2d conv1;
torch::nn::Linear fc;
Expand All @@ -83,15 +84,15 @@ TORCH_MODULE(InceptionAux);

} // namespace _inceptionimpl

struct InceptionV3Output {
struct VISION_API InceptionV3Output {
torch::Tensor output;
torch::Tensor aux;
};

// Inception v3 model architecture from
//"Rethinking the Inception Architecture for Computer Vision"
//<http://arxiv.org/abs/1512.00567>
struct InceptionV3Impl : torch::nn::Module {
struct VISION_API InceptionV3Impl : torch::nn::Module {
bool aux_logits, transform_input;

_inceptionimpl::BasicConv2d Conv2d_1a_3x3{nullptr}, Conv2d_2a_3x3{nullptr},
Expand Down
3 changes: 2 additions & 1 deletion torchvision/csrc/models/mobilenet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#define MOBILENET_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {
struct MobileNetV2Impl : torch::nn::Module {
struct VISION_API MobileNetV2Impl : torch::nn::Module {
int64_t last_channel;
torch::nn::Sequential features, classifier;

Expand Down
21 changes: 11 additions & 10 deletions torchvision/csrc/models/resnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RESNET_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {
Expand All @@ -19,7 +20,7 @@ torch::nn::Conv2d conv3x3(
// 1x1 convolution
torch::nn::Conv2d conv1x1(int64_t in, int64_t out, int64_t stride = 1);

struct BasicBlock : torch::nn::Module {
struct VISION_API BasicBlock : torch::nn::Module {
template <typename Block>
friend struct vision::models::ResNetImpl;

Expand All @@ -42,7 +43,7 @@ struct BasicBlock : torch::nn::Module {
torch::Tensor forward(torch::Tensor x);
};

struct Bottleneck : torch::nn::Module {
struct VISION_API Bottleneck : torch::nn::Module {
template <typename Block>
friend struct vision::models::ResNetImpl;

Expand Down Expand Up @@ -184,40 +185,40 @@ torch::Tensor ResNetImpl<Block>::forward(torch::Tensor x) {
return x;
}

struct ResNet18Impl : ResNetImpl<_resnetimpl::BasicBlock> {
struct VISION_API ResNet18Impl : ResNetImpl<_resnetimpl::BasicBlock> {
ResNet18Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
};

struct ResNet34Impl : ResNetImpl<_resnetimpl::BasicBlock> {
struct VISION_API ResNet34Impl : ResNetImpl<_resnetimpl::BasicBlock> {
ResNet34Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
};

struct ResNet50Impl : ResNetImpl<_resnetimpl::Bottleneck> {
struct VISION_API ResNet50Impl : ResNetImpl<_resnetimpl::Bottleneck> {
ResNet50Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
};

struct ResNet101Impl : ResNetImpl<_resnetimpl::Bottleneck> {
struct VISION_API ResNet101Impl : ResNetImpl<_resnetimpl::Bottleneck> {
ResNet101Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
};

struct ResNet152Impl : ResNetImpl<_resnetimpl::Bottleneck> {
struct VISION_API ResNet152Impl : ResNetImpl<_resnetimpl::Bottleneck> {
ResNet152Impl(int64_t num_classes = 1000, bool zero_init_residual = false);
};

struct ResNext50_32x4dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
struct VISION_API ResNext50_32x4dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
ResNext50_32x4dImpl(
int64_t num_classes = 1000,
bool zero_init_residual = false);
};

struct ResNext101_32x8dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
struct VISION_API ResNext101_32x8dImpl : ResNetImpl<_resnetimpl::Bottleneck> {
ResNext101_32x8dImpl(
int64_t num_classes = 1000,
bool zero_init_residual = false);
};

template <typename Block>
struct ResNet : torch::nn::ModuleHolder<ResNetImpl<Block>> {
struct VISION_API ResNet : torch::nn::ModuleHolder<ResNetImpl<Block>> {
using torch::nn::ModuleHolder<ResNetImpl<Block>>::ModuleHolder;
};

Expand Down
11 changes: 6 additions & 5 deletions torchvision/csrc/models/shufflenetv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define SHUFFLENETV2_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {

struct ShuffleNetV2Impl : torch::nn::Module {
struct VISION_API ShuffleNetV2Impl : torch::nn::Module {
std::vector<int64_t> _stage_out_channels;
torch::nn::Sequential conv1{nullptr}, stage2, stage3, stage4, conv5{nullptr};
torch::nn::Linear fc{nullptr};
Expand All @@ -19,19 +20,19 @@ struct ShuffleNetV2Impl : torch::nn::Module {
torch::Tensor forward(torch::Tensor x);
};

struct ShuffleNetV2_x0_5Impl : ShuffleNetV2Impl {
struct VISION_API ShuffleNetV2_x0_5Impl : ShuffleNetV2Impl {
ShuffleNetV2_x0_5Impl(int64_t num_classes = 1000);
};

struct ShuffleNetV2_x1_0Impl : ShuffleNetV2Impl {
struct VISION_API ShuffleNetV2_x1_0Impl : ShuffleNetV2Impl {
ShuffleNetV2_x1_0Impl(int64_t num_classes = 1000);
};

struct ShuffleNetV2_x1_5Impl : ShuffleNetV2Impl {
struct VISION_API ShuffleNetV2_x1_5Impl : ShuffleNetV2Impl {
ShuffleNetV2_x1_5Impl(int64_t num_classes = 1000);
};

struct ShuffleNetV2_x2_0Impl : ShuffleNetV2Impl {
struct VISION_API ShuffleNetV2_x2_0Impl : ShuffleNetV2Impl {
ShuffleNetV2_x2_0Impl(int64_t num_classes = 1000);
};

Expand Down
7 changes: 4 additions & 3 deletions torchvision/csrc/models/squeezenet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#define SQUEEZENET_H

#include <torch/torch.h>
#include "general.h"

namespace vision {
namespace models {
struct SqueezeNetImpl : torch::nn::Module {
struct VISION_API SqueezeNetImpl : torch::nn::Module {
int64_t num_classes;
torch::nn::Sequential features{nullptr}, classifier{nullptr};

Expand All @@ -17,15 +18,15 @@ struct SqueezeNetImpl : torch::nn::Module {
// SqueezeNet model architecture from the "SqueezeNet: AlexNet-level
// accuracy with 50x fewer parameters and <0.5MB model size"
// <https://arxiv.org/abs/1602.07360> paper.
struct SqueezeNet1_0Impl : SqueezeNetImpl {
struct VISION_API SqueezeNet1_0Impl : SqueezeNetImpl {
SqueezeNet1_0Impl(int64_t num_classes = 1000);
};

// SqueezeNet 1.1 model from the official SqueezeNet repo
// <https://github.com/DeepScale/SqueezeNet/tree/master/SqueezeNet_v1.1>.
// SqueezeNet 1.1 has 2.4x less computation and slightly fewer parameters
// than SqueezeNet 1.0, without sacrificing accuracy.
struct SqueezeNet1_1Impl : SqueezeNetImpl {
struct VISION_API SqueezeNet1_1Impl : SqueezeNetImpl {
SqueezeNet1_1Impl(int64_t num_classes = 1000);
};

Expand Down
Loading