const string& source = this->layer_param_.image_data_param().source();
LOG(INFO) << "Opening file " << source;
std::ifstream infile(source.c_str());
- string filename;
+ string line;
+ size_t pos;
int label;
- while (infile >> filename >> label) {
- lines_.push_back(std::make_pair(filename, label));
+ while (std::getline(infile, line)) {
+ pos = line.find_last_of(' ');
+ label = atoi(line.substr(pos + 1).c_str());
+ lines_.push_back(std::make_pair(line.substr(0, pos), label));
}
if (this->layer_param_.image_data_param().shuffle()) {
std::ofstream outfile(filename_.c_str(), std::ofstream::out);
LOG(INFO) << "Using temporary file " << filename_;
for (int i = 0; i < 5; ++i) {
- outfile << EXAMPLES_SOURCE_DIR "images/cat.jpg " << i;
+ outfile << EXAMPLES_SOURCE_DIR "images/cat.jpg " << i << std::endl;
}
outfile.close();
// Create test input file for images of distinct sizes.
MakeTempFilename(&filename_reshape_);
std::ofstream reshapefile(filename_reshape_.c_str(), std::ofstream::out);
LOG(INFO) << "Using temporary file " << filename_reshape_;
- reshapefile << EXAMPLES_SOURCE_DIR "images/cat.jpg " << 0;
- reshapefile << EXAMPLES_SOURCE_DIR "images/fish-bike.jpg " << 1;
+ reshapefile << EXAMPLES_SOURCE_DIR "images/cat.jpg " << 0 << std::endl;
+ reshapefile << EXAMPLES_SOURCE_DIR "images/fish-bike.jpg " << 1
+ << std::endl;
reshapefile.close();
+ // Create test input file for images with space in names
+ MakeTempFilename(&filename_space_);
+ std::ofstream spacefile(filename_space_.c_str(), std::ofstream::out);
+ LOG(INFO) << "Using temporary file " << filename_space_;
+ spacefile << EXAMPLES_SOURCE_DIR "images/cat.jpg " << 0 << std::endl;
+ spacefile << EXAMPLES_SOURCE_DIR "images/cat gray.jpg " << 1 << std::endl;
+ spacefile.close();
}
virtual ~ImageDataLayerTest() {
int seed_;
string filename_;
string filename_reshape_;
+ string filename_space_;
Blob<Dtype>* const blob_top_data_;
Blob<Dtype>* const blob_top_label_;
vector<Blob<Dtype>*> blob_bottom_vec_;
}
}
+TYPED_TEST(ImageDataLayerTest, TestSpace) {
+ typedef typename TypeParam::Dtype Dtype;
+ LayerParameter param;
+ ImageDataParameter* image_data_param = param.mutable_image_data_param();
+ image_data_param->set_batch_size(1);
+ image_data_param->set_source(this->filename_space_.c_str());
+ image_data_param->set_shuffle(false);
+ ImageDataLayer<Dtype> layer(param);
+ layer.SetUp(this->blob_bottom_vec_, this->blob_top_vec_);
+ EXPECT_EQ(this->blob_top_label_->num(), 1);
+ EXPECT_EQ(this->blob_top_label_->channels(), 1);
+ EXPECT_EQ(this->blob_top_label_->height(), 1);
+ EXPECT_EQ(this->blob_top_label_->width(), 1);
+ // cat.jpg
+ layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
+ EXPECT_EQ(this->blob_top_data_->num(), 1);
+ EXPECT_EQ(this->blob_top_data_->channels(), 3);
+ EXPECT_EQ(this->blob_top_data_->height(), 360);
+ EXPECT_EQ(this->blob_top_data_->width(), 480);
+ EXPECT_EQ(this->blob_top_label_->cpu_data()[0], 0);
+ // cat gray.jpg
+ layer.Forward(this->blob_bottom_vec_, this->blob_top_vec_);
+ EXPECT_EQ(this->blob_top_data_->num(), 1);
+ EXPECT_EQ(this->blob_top_data_->channels(), 3);
+ EXPECT_EQ(this->blob_top_data_->height(), 360);
+ EXPECT_EQ(this->blob_top_data_->width(), 480);
+ EXPECT_EQ(this->blob_top_label_->cpu_data()[0], 1);
+}
+
} // namespace caffe
#endif // USE_OPENCV