public:
explicit NeuronLayer(const LayerParameter& param)
: Layer<Dtype>(param) {}
- virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
+ virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
virtual inline LayerParameter_LayerType type() const {
: NeuronLayer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
+ virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top);
virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_DROPOUT;
: ReLULayer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
+ virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top);
virtual ~CuDNNReLULayer();
protected:
: SigmoidLayer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
+ virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top);
virtual ~CuDNNSigmoidLayer();
protected:
: TanHLayer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top);
+ virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top);
virtual ~CuDNNTanHLayer();
protected:
ReLULayer<Dtype>::LayerSetUp(bottom, top);
// initialize cuDNN
CUDNN_CHECK(cudnnCreate(&handle_));
+ cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);
+ cudnn::createTensor4dDesc<Dtype>(&top_desc_);
+}
+
+template <typename Dtype>
+void CuDNNReLULayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top) {
+ ReLULayer<Dtype>::Reshape(bottom, top);
const int N = bottom[0]->num();
const int K = bottom[0]->channels();
const int H = bottom[0]->height();
const int W = bottom[0]->width();
- cudnn::createTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);
- cudnn::createTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);
+ cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);
+ cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);
}
template <typename Dtype>
SigmoidLayer<Dtype>::LayerSetUp(bottom, top);
// initialize cuDNN
CUDNN_CHECK(cudnnCreate(&handle_));
+ cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);
+ cudnn::createTensor4dDesc<Dtype>(&top_desc_);
+}
+
+template <typename Dtype>
+void CuDNNSigmoidLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top) {
+ SigmoidLayer<Dtype>::Reshape(bottom, top);
const int N = bottom[0]->num();
const int K = bottom[0]->channels();
const int H = bottom[0]->height();
const int W = bottom[0]->width();
- cudnn::createTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);
- cudnn::createTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);
+ cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);
+ cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);
}
template <typename Dtype>
TanHLayer<Dtype>::LayerSetUp(bottom, top);
// initialize cuDNN
CUDNN_CHECK(cudnnCreate(&handle_));
+ cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);
+ cudnn::createTensor4dDesc<Dtype>(&top_desc_);
+}
+
+template <typename Dtype>
+void CuDNNTanHLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top) {
+ TanHLayer<Dtype>::Reshape(bottom, top);
const int N = bottom[0]->num();
const int K = bottom[0]->channels();
const int H = bottom[0]->height();
const int W = bottom[0]->width();
- cudnn::createTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);
- cudnn::createTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);
+ cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);
+ cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);
}
template <typename Dtype>
void DropoutLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top) {
NeuronLayer<Dtype>::LayerSetUp(bottom, top);
- // Set up the cache for random number generation
- rand_vec_.Reshape(bottom[0]->num(), bottom[0]->channels(),
- bottom[0]->height(), bottom[0]->width());
threshold_ = this->layer_param_.dropout_param().dropout_ratio();
DCHECK(threshold_ > 0.);
DCHECK(threshold_ < 1.);
}
template <typename Dtype>
+void DropoutLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
+ vector<Blob<Dtype>*>* top) {
+ NeuronLayer<Dtype>::Reshape(bottom, top);
+ // Set up the cache for random number generation
+ rand_vec_.Reshape(bottom[0]->num(), bottom[0]->channels(),
+ bottom[0]->height(), bottom[0]->width());
+}
+
+template <typename Dtype>
void DropoutLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top) {
const Dtype* bottom_data = bottom[0]->cpu_data();
namespace caffe {
template <typename Dtype>
-void NeuronLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
+void NeuronLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
vector<Blob<Dtype>*>* top) {
- // NeuronLayer allows in-place computations. If the computation is not
- // in-place, we will need to initialize the top blob.
- if ((*top)[0] != bottom[0]) {
- (*top)[0]->ReshapeLike(*bottom[0]);
- }
+ (*top)[0]->ReshapeLike(*bottom[0]);
}
INSTANTIATE_CLASS(NeuronLayer);