towhee
/
transform-image
copied
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions
28 lines
886 B
28 lines
886 B
import unittest
|
|
from PIL import Image
|
|
from torchvision import transforms
|
|
from transform_image import TransformImage
|
|
|
|
|
|
class TestTransformImage(unittest.TestCase):
|
|
def test_transform_image(self):
|
|
img_src = './test_data/test.jpg'
|
|
test_img = Image.open(img_src)
|
|
tfms = transforms.Compose(
|
|
[
|
|
transforms.Resize(256),
|
|
transforms.CenterCrop(224),
|
|
transforms.ToTensor(),
|
|
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
|
]
|
|
)
|
|
img1 = tfms(test_img).unsqueeze(0)
|
|
op = TransformImage(256)
|
|
outputs = op(test_img)
|
|
print("The output tyep of operator:", type(outputs.img_transformed))
|
|
c = (img1.numpy() == outputs.img_transformed.numpy())
|
|
self.assertTrue(c.all())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|