template <typename Dtype>
class LayerRegistry {
public:
- typedef Layer<Dtype>* (*Creator)(const LayerParameter&);
+ typedef shared_ptr<Layer<Dtype> > (*Creator)(const LayerParameter&);
typedef std::map<string, Creator> CreatorRegistry;
static CreatorRegistry& Registry() {
}
// Get a layer using a LayerParameter.
- static Layer<Dtype>* CreateLayer(const LayerParameter& param) {
+ static shared_ptr<Layer<Dtype> > CreateLayer(const LayerParameter& param) {
LOG(INFO) << "Creating layer " << param.name();
const string& type = param.type();
CreatorRegistry& registry = Registry();
class LayerRegisterer {
public:
LayerRegisterer(const string& type,
- Layer<Dtype>* (*creator)(const LayerParameter&)) {
+ shared_ptr<Layer<Dtype> > (*creator)(const LayerParameter&)) {
// LOG(INFO) << "Registering layer type: " << type;
LayerRegistry<Dtype>::AddCreator(type, creator);
}
#define REGISTER_LAYER_CLASS(type) \
template <typename Dtype> \
- Layer<Dtype>* Creator_##type##Layer(const LayerParameter& param) { \
- return new type##Layer<Dtype>(param); \
+ shared_ptr<Layer<Dtype> > Creator_##type##Layer(const LayerParameter& param) \
+ { \
+ return shared_ptr<Layer<Dtype> >(new type##Layer<Dtype>(param)); \
} \
REGISTER_LAYER_CREATOR(type, Creator_##type##Layer)
// Get convolution layer according to engine.
template <typename Dtype>
-Layer<Dtype>* GetConvolutionLayer(
+shared_ptr<Layer<Dtype> > GetConvolutionLayer(
const LayerParameter& param) {
ConvolutionParameter_Engine engine = param.convolution_param().engine();
if (engine == ConvolutionParameter_Engine_DEFAULT) {
#endif
}
if (engine == ConvolutionParameter_Engine_CAFFE) {
- return new ConvolutionLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new ConvolutionLayer<Dtype>(param));
#ifdef USE_CUDNN
} else if (engine == ConvolutionParameter_Engine_CUDNN) {
- return new CuDNNConvolutionLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new CuDNNConvolutionLayer<Dtype>(param));
#endif
} else {
LOG(FATAL) << "Layer " << param.name() << " has unknown engine.";
// Get pooling layer according to engine.
template <typename Dtype>
-Layer<Dtype>* GetPoolingLayer(const LayerParameter& param) {
+shared_ptr<Layer<Dtype> > GetPoolingLayer(const LayerParameter& param) {
PoolingParameter_Engine engine = param.pooling_param().engine();
if (engine == PoolingParameter_Engine_DEFAULT) {
engine = PoolingParameter_Engine_CAFFE;
#endif
}
if (engine == PoolingParameter_Engine_CAFFE) {
- return new PoolingLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new PoolingLayer<Dtype>(param));
#ifdef USE_CUDNN
} else if (engine == PoolingParameter_Engine_CUDNN) {
PoolingParameter p_param = param.pooling_param();
param.top_size() > 1) {
LOG(INFO) << "CUDNN does not support padding or multiple tops. "
<< "Using Caffe's own pooling layer.";
- return new PoolingLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new PoolingLayer<Dtype>(param));
}
- return new CuDNNPoolingLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new CuDNNPoolingLayer<Dtype>(param));
#endif
} else {
LOG(FATAL) << "Layer " << param.name() << " has unknown engine.";
// Get relu layer according to engine.
template <typename Dtype>
-Layer<Dtype>* GetReLULayer(const LayerParameter& param) {
+shared_ptr<Layer<Dtype> > GetReLULayer(const LayerParameter& param) {
ReLUParameter_Engine engine = param.relu_param().engine();
if (engine == ReLUParameter_Engine_DEFAULT) {
engine = ReLUParameter_Engine_CAFFE;
#endif
}
if (engine == ReLUParameter_Engine_CAFFE) {
- return new ReLULayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new ReLULayer<Dtype>(param));
#ifdef USE_CUDNN
} else if (engine == ReLUParameter_Engine_CUDNN) {
- return new CuDNNReLULayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new CuDNNReLULayer<Dtype>(param));
#endif
} else {
LOG(FATAL) << "Layer " << param.name() << " has unknown engine.";
// Get sigmoid layer according to engine.
template <typename Dtype>
-Layer<Dtype>* GetSigmoidLayer(const LayerParameter& param) {
+shared_ptr<Layer<Dtype> > GetSigmoidLayer(const LayerParameter& param) {
SigmoidParameter_Engine engine = param.sigmoid_param().engine();
if (engine == SigmoidParameter_Engine_DEFAULT) {
engine = SigmoidParameter_Engine_CAFFE;
#endif
}
if (engine == SigmoidParameter_Engine_CAFFE) {
- return new SigmoidLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new SigmoidLayer<Dtype>(param));
#ifdef USE_CUDNN
} else if (engine == SigmoidParameter_Engine_CUDNN) {
- return new CuDNNSigmoidLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new CuDNNSigmoidLayer<Dtype>(param));
#endif
} else {
LOG(FATAL) << "Layer " << param.name() << " has unknown engine.";
// Get softmax layer according to engine.
template <typename Dtype>
-Layer<Dtype>* GetSoftmaxLayer(const LayerParameter& param) {
+shared_ptr<Layer<Dtype> > GetSoftmaxLayer(const LayerParameter& param) {
SoftmaxParameter_Engine engine = param.softmax_param().engine();
if (engine == SoftmaxParameter_Engine_DEFAULT) {
engine = SoftmaxParameter_Engine_CAFFE;
#endif
}
if (engine == SoftmaxParameter_Engine_CAFFE) {
- return new SoftmaxLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new SoftmaxLayer<Dtype>(param));
#ifdef USE_CUDNN
} else if (engine == SoftmaxParameter_Engine_CUDNN) {
- return new CuDNNSoftmaxLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new CuDNNSoftmaxLayer<Dtype>(param));
#endif
} else {
LOG(FATAL) << "Layer " << param.name() << " has unknown engine.";
// Get tanh layer according to engine.
template <typename Dtype>
-Layer<Dtype>* GetTanHLayer(const LayerParameter& param) {
+shared_ptr<Layer<Dtype> > GetTanHLayer(const LayerParameter& param) {
TanHParameter_Engine engine = param.tanh_param().engine();
if (engine == TanHParameter_Engine_DEFAULT) {
engine = TanHParameter_Engine_CAFFE;
#endif
}
if (engine == TanHParameter_Engine_CAFFE) {
- return new TanHLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new TanHLayer<Dtype>(param));
#ifdef USE_CUDNN
} else if (engine == TanHParameter_Engine_CUDNN) {
- return new CuDNNTanHLayer<Dtype>(param);
+ return shared_ptr<Layer<Dtype> >(new CuDNNTanHLayer<Dtype>(param));
#endif
} else {
LOG(FATAL) << "Layer " << param.name() << " has unknown engine.";