pytorch-inference
pytorch::Conv2d Class Reference

#include <Convolution.hpp>

Inheritance diagram for pytorch::Conv2d:
pytorch::Layer

Public Member Functions

 Conv2d (const conv_params_t &params, const tensor &filters, const tensor &bias)
 Constructs a Conv2d object given parameters, filters, and bias tensors. More...
 
 Conv2d (const conv_params_t &params, const std::string &filters_filename="", const std::vector< int > &filt_dims={}, const std::string &bias_filename="", const std::vector< int > &bias_dims={}, const std::string &python_home="../scripts")
 Constructs a Conv2d object given the filenames and sizes of the requisite tensors. Also requires convolution parameters like the other constructor. More...
 
 Conv2d (const Conv2d &other)
 Copy constructor, constructs a Conv2d object that is exactly a copy of the argument. More...
 
virtual ~Conv2d ()=default
 Destructor - for now trivial, may need to take on some functionality. More...
 
void add_filters (const std::string &filters_filename, const std::vector< int > &filt_dims)
 Read in filters from a file given here if it wasn't passed to the constructor. Overwrites current contents of this->filters. More...
 
void add_bias (const std::string &bias_filename, const std::vector< int > &bias_dims)
 Read in bias from a file given here if it wasn't passed to the constructor. Overwrites current contents of this->bias. More...
 
std::vector< tensor > forward (const std::vector< tensor > &input)
 Forward function, takes data and performs the Conv2d operation using the already-initialized filters and bias tensors. More...
 
std::vector< tensor > operator() (const std::vector< tensor > &input)
 Forward function, takes data and performs the Conv2d operation using the already-initialized filters and bias tensors. More...
 

Private Attributes

tensor filters
 
tensor bias
 
conv_params_t params
 
pycpp::py_object utils
 
bool has_bias = false
 

Constructor & Destructor Documentation

◆ Conv2d() [1/3]

pytorch::Conv2d::Conv2d ( const conv_params_t &  params,
const tensor &  filters,
const tensor &  bias 
)
inlineexplicit

Constructs a Conv2d object given parameters, filters, and bias tensors.

Parameters
paramsThe convolution parameters like filter size, stride, and padding.
filtersThe trained filter tensors. For those comfortable with Py_Cpp.
biasThe trained bias tensors. For those comfortable with Py_Cpp.

◆ Conv2d() [2/3]

pytorch::Conv2d::Conv2d ( const conv_params_t &  params,
const std::string &  filters_filename = "",
const std::vector< int > &  filt_dims = {},
const std::string &  bias_filename = "",
const std::vector< int > &  bias_dims = {},
const std::string &  python_home = "../scripts" 
)
inlineexplicit

Constructs a Conv2d object given the filenames and sizes of the requisite tensors. Also requires convolution parameters like the other constructor.

Parameters
paramsThe convolution parameters like filter size, stride, and padding.
filters_filenameThe file where the filters tensor is saved. Will be loaded with numpy.load(filename).
filt_dimsThe dimensions of the filter tensor in pytorch convention - (batch, channels, h, w)
bias_filenameThe file where the bias tensor is saved. Will be loaded with numpy.load(filename).
bias_dimsThe dimensions of the bias tensor in pytorch convention - (batch, channels, h, w)
python_homeWhere the utility scripts are - holds the loading script necessary to load up the tensors.

◆ Conv2d() [3/3]

pytorch::Conv2d::Conv2d ( const Conv2d other)
inline

Copy constructor, constructs a Conv2d object that is exactly a copy of the argument.

Parameters
otherAnother Conv2d object.

◆ ~Conv2d()

virtual pytorch::Conv2d::~Conv2d ( )
virtualdefault

Destructor - for now trivial, may need to take on some functionality.

Member Function Documentation

◆ add_bias()

void pytorch::Conv2d::add_bias ( const std::string &  bias_filename,
const std::vector< int > &  bias_dims 
)
inline

Read in bias from a file given here if it wasn't passed to the constructor. Overwrites current contents of this->bias.

Parameters
bias_filenameThe file where the bias tensor is saved. Will be loaded with numpy.load(filename).
bias_dimsThe dimensions of the bias tensor in pytorch convention - (batch, channels, h, w)

◆ add_filters()

void pytorch::Conv2d::add_filters ( const std::string &  filters_filename,
const std::vector< int > &  filt_dims 
)
inline

Read in filters from a file given here if it wasn't passed to the constructor. Overwrites current contents of this->filters.

Parameters
filters_filenameThe file where the filters tensor is saved. Will be loaded with numpy.load(filename).
filt_dimsThe dimensions of the filter tensor in pytorch convention - (batch, channels, h, w)

◆ forward()

std::vector<tensor> pytorch::Conv2d::forward ( const std::vector< tensor > &  input)
inlinevirtual

Forward function, takes data and performs the Conv2d operation using the already-initialized filters and bias tensors.

Parameters
inputInput data size (h_in, w_in, Cin, batch)
Returns
Convolved data size (h_out, w_out, Cout, batch)

Implements pytorch::Layer.

◆ operator()()

std::vector<tensor> pytorch::Conv2d::operator() ( const std::vector< tensor > &  input)
inlinevirtual

Forward function, takes data and performs the Conv2d operation using the already-initialized filters and bias tensors.

Parameters
inputInput data size (h_in, w_in, Cin, batch)
Returns
Convolved data size (h_out, w_out, Cout, batch)

Implements pytorch::Layer.

Member Data Documentation

◆ bias

tensor pytorch::Conv2d::bias
private

◆ filters

tensor pytorch::Conv2d::filters
private

◆ has_bias

bool pytorch::Conv2d::has_bias = false
private

◆ params

conv_params_t pytorch::Conv2d::params
private

◆ utils

pycpp::py_object pytorch::Conv2d::utils
private

The documentation for this class was generated from the following file: