#ifndef CAFFE_UTIL_IO_H_
#define CAFFE_UTIL_IO_H_
+#include <unistd.h>
#include <string>
#include "google/protobuf/message.h"
using ::google::protobuf::Message;
+inline void MakeTempFilename(string* temp_filename) {
+ temp_filename->clear();
+ *temp_filename = "/tmp/caffe_test.XXXXXX";
+ char* temp_filename_cstr = new char[temp_filename->size()];
+ // NOLINT_NEXT_LINE(runtime/printf)
+ strcpy(temp_filename_cstr, temp_filename->c_str());
+ int fd = mkstemp(temp_filename_cstr);
+ CHECK_GE(fd, 0) << "Failed to open a temporary file at: " << *temp_filename;
+ close(fd);
+ *temp_filename = temp_filename_cstr;
+ delete temp_filename_cstr;
+}
+
+inline void MakeTempDir(string* temp_dirname) {
+ temp_dirname->clear();
+ *temp_dirname = "/tmp/caffe_test.XXXXXX";
+ char* temp_dirname_cstr = new char[temp_dirname->size()];
+ // NOLINT_NEXT_LINE(runtime/printf)
+ strcpy(temp_dirname_cstr, temp_dirname->c_str());
+ char* mkdtemp_result = mkdtemp(temp_dirname_cstr);
+ CHECK(mkdtemp_result != NULL)
+ << "Failed to create a temporary directory at: " << *temp_dirname;
+ *temp_dirname = temp_dirname_cstr;
+ delete temp_dirname_cstr;
+}
+
bool ReadProtoFromTextFile(const char* filename, Message* proto);
inline bool ReadProtoFromTextFile(const string& filename, Message* proto) {
#include "caffe/common.hpp"
#include "caffe/filler.hpp"
#include "caffe/proto/caffe.pb.h"
+#include "caffe/util/io.hpp"
#include "caffe/vision_layers.hpp"
#include "caffe/test/test_caffe_main.hpp"
protected:
DataLayerTest()
: backend_(DataParameter_DB_LEVELDB),
- filename_(new string(tmpnam(NULL))),
blob_top_data_(new Blob<Dtype>()),
blob_top_label_(new Blob<Dtype>()),
seed_(1701) {}
virtual void SetUp() {
+ filename_.reset(new string());
+ MakeTempDir(filename_.get());
+ *filename_ += "/db";
blob_top_vec_.push_back(blob_top_data_);
blob_top_vec_.push_back(blob_top_label_);
}
protected:
HDF5OutputLayerTest()
- : output_file_name_(tmpnam(NULL)),
- input_file_name_(
+ : input_file_name_(
CMAKE_SOURCE_DIR "caffe/test/test_data/sample_data.h5"),
blob_data_(new Blob<Dtype>()),
blob_label_(new Blob<Dtype>()),
channels_(8),
height_(5),
width_(5) {
+ MakeTempFilename(&output_file_name_);
}
virtual ~HDF5OutputLayerTest() {
#include "caffe/common.hpp"
#include "caffe/filler.hpp"
#include "caffe/proto/caffe.pb.h"
+#include "caffe/util/io.hpp"
#include "caffe/vision_layers.hpp"
#include "caffe/test/test_caffe_main.hpp"
protected:
ImageDataLayerTest()
: seed_(1701),
- filename_(new string(tmpnam(NULL))),
blob_top_data_(new Blob<Dtype>()),
blob_top_label_(new Blob<Dtype>()) {}
virtual void SetUp() {
+ MakeTempFilename(&filename_);
blob_top_vec_.push_back(blob_top_data_);
blob_top_vec_.push_back(blob_top_label_);
Caffe::set_random_seed(seed_);
// Create a Vector of files with labels
- std::ofstream outfile(filename_->c_str(), std::ofstream::out);
- LOG(INFO) << "Using temporary file " << *filename_;
+ 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;
}
}
int seed_;
- shared_ptr<string> filename_;
+ string filename_;
Blob<Dtype>* const blob_top_data_;
Blob<Dtype>* const blob_top_label_;
vector<Blob<Dtype>*> blob_bottom_vec_;
LayerParameter param;
ImageDataParameter* image_data_param = param.mutable_image_data_param();
image_data_param->set_batch_size(5);
- image_data_param->set_source(this->filename_->c_str());
+ image_data_param->set_source(this->filename_.c_str());
image_data_param->set_shuffle(false);
ImageDataLayer<Dtype> layer(param);
layer.SetUp(this->blob_bottom_vec_, &this->blob_top_vec_);
LayerParameter param;
ImageDataParameter* image_data_param = param.mutable_image_data_param();
image_data_param->set_batch_size(5);
- image_data_param->set_source(this->filename_->c_str());
+ image_data_param->set_source(this->filename_.c_str());
image_data_param->set_new_height(256);
image_data_param->set_new_width(256);
image_data_param->set_shuffle(false);
LayerParameter param;
ImageDataParameter* image_data_param = param.mutable_image_data_param();
image_data_param->set_batch_size(5);
- image_data_param->set_source(this->filename_->c_str());
+ image_data_param->set_source(this->filename_.c_str());
image_data_param->set_shuffle(true);
ImageDataLayer<Dtype> layer(param);
layer.SetUp(this->blob_bottom_vec_, &this->blob_top_vec_);
+++ /dev/null
-#include <string>
-#include <vector>
-
-#include "gtest/gtest.h"
-
-#include "caffe/blob.hpp"
-#include "caffe/common.hpp"
-#include "caffe/data_layers.hpp"
-#include "caffe/proto/caffe.pb.h"
-
-#include "caffe/test/test_caffe_main.hpp"
-
-namespace caffe {
-
-template <typename TypeParam>
-class WindowDataLayerTest : public MultiDeviceTest<TypeParam> {
- typedef typename TypeParam::Dtype Dtype;
-
- protected:
- WindowDataLayerTest()
- : seed_(1701),
- filename_(new string(tmpnam(NULL))),
- blob_top_data_(new Blob<Dtype>()),
- blob_top_label_(new Blob<Dtype>()) {}
- virtual void SetUp() {
- blob_top_vec_.push_back(blob_top_data_);
- blob_top_vec_.push_back(blob_top_label_);
- Caffe::set_random_seed(seed_);
- }
-
- virtual ~WindowDataLayerTest() {
- delete blob_top_data_;
- delete blob_top_label_;
- }
-
- int seed_;
- shared_ptr<string> filename_;
- Blob<Dtype>* const blob_top_data_;
- Blob<Dtype>* const blob_top_label_;
- vector<Blob<Dtype>*> blob_bottom_vec_;
- vector<Blob<Dtype>*> blob_top_vec_;
-};
-
-TYPED_TEST_CASE(WindowDataLayerTest, TestDtypesAndDevices);
-
-TYPED_TEST(WindowDataLayerTest, TestNothing) {
-}
-
-} // namespace caffe