!7538 Add empty string tensor support for Album

Merge pull request !7538 from EricZ/album_empty_string
This commit is contained in:
mindspore-ci-bot 2020-10-21 08:41:29 +08:00 committed by Gitee
commit 643366ea70
5 changed files with 19 additions and 4 deletions

View File

@ -301,7 +301,7 @@ class Tensor {
const TensorShape &shape() const { return shape_; }
/// Check if tensor has data
/// \return bool - true if tensor is empty
/// \return bool - true if tensor is not empty
bool HasData() const { return data_ != nullptr; }
/// Reshape the tensor. The given shape should have the same number of elements in the Tensor

View File

@ -380,7 +380,7 @@ Status AlbumOp::LoadIDTensor(const std::string &file, uint32_t col_num, TensorRo
Status AlbumOp::LoadEmptyTensor(uint32_t col_num, TensorRow *row) {
// hack to get the file name without extension, the 1 is to get rid of the backslash character
TensorPtr empty_tensor;
RETURN_IF_NOT_OK(Tensor::CreateEmpty(TensorShape({}), data_schema_->column(col_num).type(), &empty_tensor));
RETURN_IF_NOT_OK(Tensor::CreateEmpty(TensorShape({0}), data_schema_->column(col_num).type(), &empty_tensor));
row->push_back(std::move(empty_tensor));
return Status::OK();
}

View File

@ -62,7 +62,7 @@ TEST_F(MindDataTestSchema, TestAlbumSchema) {
} else {
int32_t num_cols = schema->NumColumns();
MS_LOG(INFO) << "num_cols: " << num_cols << ".";
EXPECT_TRUE(num_cols == 7);
EXPECT_TRUE(num_cols == 8);
}
}

View File

@ -117,6 +117,17 @@ TEST_F(MindDataTestStringTensorDE, Empty) {
}
}
TEST_F(MindDataTestStringTensorDE, EmptyData) {
std::shared_ptr<Tensor> t;
Tensor::CreateScalar<std::string>("", &t);
// empty string has 1 element
ASSERT_TRUE(t->HasData());
std::shared_ptr<Tensor> t1;
Tensor::CreateEmpty(TensorShape({0}), DataType(DataType::DE_STRING), &t1);
ASSERT_TRUE(!t1->HasData());
}
TEST_F(MindDataTestStringTensorDE, SetItem) {
std::vector<std::string> strings{"abc", "defg", "hi", "klmno", "123", "789"};
std::shared_ptr<Tensor> t3;

View File

@ -8,6 +8,10 @@
"type": "string",
"rank": 1
},
"optional" : {
"type": "string",
"rank": 1
},
"id" : {
"type": "int64",
"rank": 0