!49719 fix pillow pad

Merge pull request !49719 from luoyang/fix-pillow-pad
This commit is contained in:
i-robot 2023-03-06 01:41:34 +00:00 committed by Gitee
commit 19735e8afd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 20 additions and 1 deletions

View File

@ -964,6 +964,8 @@ def pad(img, padding, fill_value, padding_mode):
image = ImageOps.expand(img, border=(left, top, right, bottom), fill=fill_value)
image.putpalette(palette)
return image
if isinstance(fill_value, tuple) and (img.mode == 'L' or img.mode == '1'):
fill_value = (fill_value[0],)
return ImageOps.expand(img, border=(left, top, right, bottom), fill=fill_value)
if img.mode == 'P':

View File

@ -17,6 +17,7 @@ Testing RandomCrop op in DE
"""
import numpy as np
import pytest
from PIL import Image
import mindspore.dataset.transforms as ops
import mindspore.dataset.vision as vision
@ -550,6 +551,18 @@ def test_random_crop_09():
assert error_msg in str(error_info.value)
def test_random_crop_10():
"""
Feature: RandomCrop
Description: Test Py RandomCrop with grayscale/binary image
Expectation: The dataset is processed as expected
"""
path = "../data/dataset/apple.jpg"
image_list = [Image.open(path), Image.open(path).convert('1'), Image.open(path).convert('L')]
for image in image_list:
_ = vision.RandomCrop((28))(image)
def test_random_crop_comp(plot=False):
"""
Feature: RandomCrop op
@ -667,6 +680,7 @@ if __name__ == "__main__":
test_random_crop_07_py()
test_random_crop_08_py()
test_random_crop_09()
test_random_crop_10()
test_random_crop_op_c(True)
test_random_crop_op_py(True)
test_random_crop_comp(True)

View File

@ -67,7 +67,10 @@ def test_imagenet_to_mindrecord(fixture_file):
for i in range(PARTITION_NUMBER):
assert os.path.exists(file_name + str(i))
assert os.path.exists(file_name + str(i) + ".db")
read(file_name + "0")
read([file_name + "0",
file_name + "1",
file_name + "2",
file_name + "3"])
def test_imagenet_to_mindrecord_default_partition_number(fixture_file):
"""