From 20524f37e4eb4324f0e8de4322e67fda56f90b06 Mon Sep 17 00:00:00 2001 From: yanghaitao Date: Fri, 12 Jun 2020 14:56:51 +0800 Subject: [PATCH] add check for num_rows --- .../dataset/engine/datasetops/source/image_folder_op.cc | 5 +++++ mindspore/ccsrc/dataset/engine/datasetops/source/mnist_op.cc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/image_folder_op.cc b/mindspore/ccsrc/dataset/engine/datasetops/source/image_folder_op.cc index 7ffb63a6ba9..a8332736b7f 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/image_folder_op.cc +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/image_folder_op.cc @@ -116,6 +116,11 @@ Status ImageFolderOp::PrescanMasterEntry(const std::string &filedir) { } image_label_pairs_.shrink_to_fit(); num_rows_ = image_label_pairs_.size(); + if (num_rows_ == 0) { + RETURN_STATUS_UNEXPECTED( + "There is no valid data matching the dataset API ImageFolderDatasetV2.Please check file path or dataset " + "API validation first."); + } // free memory of two queues used for pre-scan folder_name_queue_->Reset(); image_name_queue_->Reset(); diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/mnist_op.cc b/mindspore/ccsrc/dataset/engine/datasetops/source/mnist_op.cc index 07726f5033e..54fb39215b6 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/mnist_op.cc +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/mnist_op.cc @@ -350,6 +350,11 @@ Status MnistOp::ParseMnistData() { } image_label_pairs_.shrink_to_fit(); num_rows_ = image_label_pairs_.size(); + if (num_rows_ == 0) { + RETURN_STATUS_UNEXPECTED( + "There is no valid data matching the dataset API MnistDataset.Please check file path or dataset API " + "validation first."); + } return Status::OK(); }