Skip to content

Commit

Permalink
Merge pull request #1093 from CellScope/io-cant-load-error-msg
Browse files Browse the repository at this point in the history
[fix] Move file reading error checking closer to actual file read command
  • Loading branch information
shelhamer committed Sep 16, 2014
2 parents 0fb2faf + aecab61 commit a77ca76
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/caffe/util/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ bool ReadImageToDatum(const string& filename, const int label,
cv::Mat cv_img;
int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
CV_LOAD_IMAGE_GRAYSCALE);
if (height > 0 && width > 0) {
cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
cv::resize(cv_img_origin, cv_img, cv::Size(width, height));
} else {
cv_img = cv::imread(filename, cv_read_flag);
}
if (!cv_img.data) {

cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
if (!cv_img_origin.data) {
LOG(ERROR) << "Could not open or find file " << filename;
return false;
}
if (height > 0 && width > 0) {
cv::resize(cv_img_origin, cv_img, cv::Size(height, width));
} else {
cv_img = cv_img_origin;
}

int num_channels = (is_color ? 3 : 1);
datum->set_channels(num_channels);
datum->set_height(cv_img.rows);
Expand Down

0 comments on commit a77ca76

Please sign in to comment.