未验证 提交 a1b99978 编写于 作者: J jingsongliu 提交者: GitHub

Update imread() read image way error (#47005)

* update test_image.py

* update test_image.py
上级 31a437b1
......@@ -192,7 +192,7 @@ def load_image(file, is_color=True):
# Here, use constant 1 and 0
# 1: COLOR, 0: GRAYSCALE
flag = 1 if is_color else 0
im = cv2.imread(file, flag)
im = cv2.imread(file.encode('utf-8').decode('utf-8'), flag)
return im
......
......@@ -11,35 +11,45 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Fliename:
test_image.py
Description:
This scipt test image resize,flip and chw.
"""
import sys
import unittest
import numpy as np
import paddle.dataset.image as image
from paddle.dataset import image
__all__ = []
class Image(unittest.TestCase):
"""
This function is test image resize,flip and chw.
"""
def test_resize_flip_chw(self):
# resize
im = image.load_image('cat.jpg')
im = image.resize_short(im, 256)
self.assertEqual(256, min(im.shape[:2]))
self.assertEqual(3, im.shape[2])
""" resize """
imgdir = sys.argv[0].replace('test_image.py', 'cat.jpg')
images = image.load_image(imgdir)
images = image.resize_short(images, 256)
self.assertEqual(256, min(images.shape[:2]))
self.assertEqual(3, images.shape[2])
# flip
im = image.left_right_flip(im)
im2 = np.flip(im, 1)
self.assertEqual(im.all(), im2.all())
images = image.left_right_flip(images)
images2 = np.flip(images, 1)
self.assertEqual(images.all(), images2.all())
# to_chw
h, w, c = im.shape
im = image.to_chw(im)
self.assertEqual(c, im.shape[0])
self.assertEqual(h, im.shape[1])
self.assertEqual(w, im.shape[2])
height, width, channel = images.shape
images = image.to_chw(images)
self.assertEqual(channel, images.shape[0])
self.assertEqual(height, images.shape[1])
self.assertEqual(width, images.shape[2])
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册