fix minddata directory path problem

This commit is contained in:
xiefangqi 2021-05-10 22:16:37 +08:00
parent ff0103f5ff
commit e0148f7181
2 changed files with 13 additions and 0 deletions

View File

@ -260,6 +260,10 @@ Status Tensor::CreateFromByteList(const dataengine::BytesList &bytes_list, const
#endif
Status Tensor::CreateFromFile(const std::string &path, std::shared_ptr<Tensor> *out) {
Path file(path);
if (file.IsDirectory()) {
RETURN_STATUS_UNEXPECTED("Invalid file found: " + path + ", should be file, but got directory.");
}
std::ifstream fs;
fs.open(path, std::ios::binary | std::ios::in);
CHECK_FAIL_RETURN_UNEXPECTED(!fs.fail(), "Fail to open file: " + path);

View File

@ -759,6 +759,15 @@ def test_imagefolder_exception():
except RuntimeError as e:
assert "map operation: [PyFunc] failed. The corresponding data files" in str(e)
data_dir_invalid = "../data/dataset/testPK"
try:
data = ds.ImageFolderDataset(data_dir_invalid)
for _ in data.__iter__():
pass
assert False
except RuntimeError as e:
assert "should be file, but got directory" in str(e)
if __name__ == '__main__':
test_imagefolder_basic()