!4289 Fix pad op validate issue

Merge pull request !4289 from xiefangqi/fix_pad_validate
This commit is contained in:
mindspore-ci-bot 2020-08-11 20:20:35 +08:00 committed by Gitee
commit c2997845c2
2 changed files with 0 additions and 14 deletions

View File

@ -848,8 +848,6 @@ Status Pad(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output
std::shared_ptr<CVTensor> output_cv;
RETURN_IF_NOT_OK(CVTensor::CreateFromMat(out_image, &output_cv));
// pad the dimension if shape information is only 2 dimensional, this is grayscale
CHECK_FAIL_RETURN_UNEXPECTED(input_cv->Rank() == 3,
"Pad error: invalid image shape, only support 3 channels image.");
int num_channels = input_cv->shape()[2];
if (input_cv->Rank() == 3 && num_channels == 1 && output_cv->Rank() == 2) output_cv->ExpandDim(2);
*output = std::static_pointer_cast<Tensor>(output_cv);

View File

@ -148,20 +148,8 @@ def test_pad_md5():
filename2 = "pad_01_py_result.npz"
save_and_check_md5(data2, filename2, generate_golden=GENERATE_GOLDEN)
def test_pad_exception():
try:
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
pad_op = c_vision.Pad(150)
data1 = data1.map(input_columns=["image"], operations=pad_op)
for _ in data1.create_dict_iterator():
pass
assert False
except RuntimeError as e:
assert "Pad error: invalid image shape, only support 3 channels image" in str(e)
if __name__ == "__main__":
test_pad_op()
test_pad_grayscale()
test_pad_md5()
test_pad_exception()