From e7b2b4eab67390885b8cb360750cfc1553fbb70e Mon Sep 17 00:00:00 2001 From: philkr Date: Tue, 4 Aug 2015 10:27:34 -0700 Subject: [PATCH] ImageData layer default batch size of 1, and check for zero batch size --- src/caffe/layers/image_data_layer.cpp | 3 +++ src/caffe/proto/caffe.proto | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/caffe/layers/image_data_layer.cpp b/src/caffe/layers/image_data_layer.cpp index 18c035cba9d..dcc53348304 100644 --- a/src/caffe/layers/image_data_layer.cpp +++ b/src/caffe/layers/image_data_layer.cpp @@ -62,11 +62,13 @@ void ImageDataLayer::DataLayerSetUp(const vector*>& bottom, // Read an image, and use it to initialize the top blob. cv::Mat cv_img = ReadImageToCVMat(root_folder + lines_[lines_id_].first, new_height, new_width, is_color); + CHECK(cv_img.data) << "Could not load " << lines_[lines_id_].first; // Use data_transformer to infer the expected blob shape from a cv_image. vector top_shape = this->data_transformer_->InferBlobShape(cv_img); this->transformed_data_.Reshape(top_shape); // Reshape prefetch_data and top[0] according to the batch_size. const int batch_size = this->layer_param_.image_data_param().batch_size(); + CHECK_GT(batch_size, 0) << "Positive batch size required"; top_shape[0] = batch_size; this->prefetch_data_.Reshape(top_shape); top[0]->ReshapeLike(this->prefetch_data_); @@ -108,6 +110,7 @@ void ImageDataLayer::InternalThreadEntry() { // on single input batches allows for inputs of varying dimension. cv::Mat cv_img = ReadImageToCVMat(root_folder + lines_[lines_id_].first, new_height, new_width, is_color); + CHECK(cv_img.data) << "Could not load " << lines_[lines_id_].first; // Use data_transformer to infer the expected blob shape from a cv_img. vector top_shape = this->data_transformer_->InferBlobShape(cv_img); this->transformed_data_.Reshape(top_shape); diff --git a/src/caffe/proto/caffe.proto b/src/caffe/proto/caffe.proto index 81a8c69d88e..8c3f0723600 100644 --- a/src/caffe/proto/caffe.proto +++ b/src/caffe/proto/caffe.proto @@ -290,7 +290,7 @@ message LayerParameter { // The blobs containing the numeric parameters of the layer. repeated BlobProto blobs = 7; - + // Specifies on which bottoms the backpropagation should be skipped. // The size must be either 0 or equal to the number of bottoms. repeated bool propagate_down = 11; @@ -431,7 +431,7 @@ message ContrastiveLossParameter { // Hadsell paper. New models should probably use this version. // legacy_version = true uses (margin - d^2). This is kept to support / // reproduce existing models and results - optional bool legacy_version = 2 [default = false]; + optional bool legacy_version = 2 [default = false]; } message ConvolutionParameter { @@ -579,7 +579,7 @@ message ImageDataParameter { // Specify the data source. optional string source = 1; // Specify the batch size. - optional uint32 batch_size = 4; + optional uint32 batch_size = 4 [default = 1]; // The rand_skip variable is for the data layer to skip a few data points // to avoid all asynchronous sgd clients to start at the same point. The skip // point would be set as rand_skip * rand(0,1). Note that rand_skip should not