MCPcopy Create free account
hub / github.com/BVLC/caffe / TestReshape

Method TestReshape

src/caffe/test/test_data_layer.cpp:134–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132 }
133
134 void TestReshape(DataParameter_DB backend) {
135 const int num_inputs = 5;
136 // Save data of varying shapes.
137 LOG(INFO) << "Using temporary dataset " << *filename_;
138 scoped_ptr<db::DB> db(db::GetDB(backend));
139 db->Open(*filename_, db::NEW);
140 scoped_ptr<db::Transaction> txn(db->NewTransaction());
141 for (int i = 0; i < num_inputs; ++i) {
142 Datum datum;
143 datum.set_label(i);
144 datum.set_channels(2);
145 datum.set_height(i % 2 + 1);
146 datum.set_width(i % 4 + 1);
147 std::string* data = datum.mutable_data();
148 const int data_size = datum.channels() * datum.height() * datum.width();
149 for (int j = 0; j < data_size; ++j) {
150 data->push_back(static_cast<uint8_t>(j));
151 }
152 stringstream ss;
153 ss << i;
154 string out;
155 CHECK(datum.SerializeToString(&out));
156 txn->Put(ss.str(), out);
157 }
158 txn->Commit();
159 db->Close();
160
161 // Load and check data of various shapes.
162 LayerParameter param;
163 param.set_phase(TEST);
164 DataParameter* data_param = param.mutable_data_param();
165 data_param->set_batch_size(1);
166 data_param->set_source(filename_->c_str());
167 data_param->set_backend(backend);
168
169 DataLayer<Dtype> layer(param);
170 layer.SetUp(blob_bottom_vec_, blob_top_vec_);
171 EXPECT_EQ(blob_top_data_->num(), 1);
172 EXPECT_EQ(blob_top_data_->channels(), 2);
173 EXPECT_EQ(blob_top_label_->num(), 1);
174 EXPECT_EQ(blob_top_label_->channels(), 1);
175 EXPECT_EQ(blob_top_label_->height(), 1);
176 EXPECT_EQ(blob_top_label_->width(), 1);
177
178 for (int iter = 0; iter < num_inputs; ++iter) {
179 layer.Forward(blob_bottom_vec_, blob_top_vec_);
180 EXPECT_EQ(blob_top_data_->height(), iter % 2 + 1);
181 EXPECT_EQ(blob_top_data_->width(), iter % 4 + 1);
182 EXPECT_EQ(iter, blob_top_label_->cpu_data()[0]);
183 const int channels = blob_top_data_->channels();
184 const int height = blob_top_data_->height();
185 const int width = blob_top_data_->width();
186 for (int c = 0; c < channels; ++c) {
187 for (int h = 0; h < height; ++h) {
188 for (int w = 0; w < width; ++w) {
189 const int idx = (c * height + h) * width + w;
190 EXPECT_EQ(idx, static_cast<int>(blob_top_data_->cpu_data()[idx]))
191 << "debug: iter " << iter << " c " << c

Callers 1

TYPED_TESTFunction · 0.80

Calls 14

GetDBFunction · 0.85
set_batch_sizeMethod · 0.80
numMethod · 0.80
ForwardMethod · 0.80
OpenMethod · 0.45
NewTransactionMethod · 0.45
channelsMethod · 0.45
heightMethod · 0.45
widthMethod · 0.45
PutMethod · 0.45
CommitMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected