Repository navigation
Expand file tree
/
Copy pathcos_data_layer.cpp
More file actions
66 lines (56 loc) · 2 KB
/
Copy pathcos_data_layer.cpp
File metadata and controls
66 lines (56 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <vector>
#include "extra_layers.hpp"
namespace caffe {
template <typename Dtype>
CoSDataLayer<Dtype>::~CoSDataLayer<Dtype>() { }
template <typename Dtype>
void CoSDataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const CoSDataParameter& cos_data_param = this->layer_param_.cos_data_param();
batch_size_ = cos_data_param.batch_size();
top_size_ = this->layer_param_.top_size();
CHECK(top_size_ == cos_data_param.top_size()) <<
"number of tops in this layer should be equal to number" <<
" of tops in CoSDataParameter";
channels_.resize(top_size_);
height_.resize(top_size_);
width_.resize(top_size_);
data_.resize(top_size_);
for (int i = 0; i < top_size_; i++) {
channels_[i] = cos_data_param.top(i).channels();
height_[i] = cos_data_param.top(i).height();
width_[i] = cos_data_param.top(i).width();
top[i]->Reshape(batch_size_, channels_[i], height_[i], width_[i]);
}
}
template <typename Dtype>
void CoSDataLayer<Dtype>::Reset(const vector<Dtype*>& data) {
CHECK_EQ(data.size(), top_size_);
for (int i = 0; i < data_.size(); i++) {
CHECK(data[i]);
data_[i] = data[i];
}
}
template <typename Dtype>
void CoSDataLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
for (int i = 0; i < top_size_; i++) {
CHECK(data_[i]) <<
"CoSDataLayer needs to be initialized by calling Reset";
top[i]->Reshape(batch_size_, channels_[i], height_[i], width_[i]);
top[i]->set_cpu_data(data_[i]);
}
}
template <typename Dtype>
void CoSDataLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
for (int i = 0; i < top_size_; i++) {
CHECK(data_[i]) <<
"CoSDataLayer needs to be initialized by calling Reset";
top[i]->Reshape(batch_size_, channels_[i], height_[i], width_[i]);
top[i]->set_gpu_data(data_[i]);
}
}
INSTANTIATE_CLASS(CoSDataLayer);
REGISTER_LAYER_CLASS(CoSData);
} // namespace caffe