From 688a07cb1b29c0702417fa336a719ddaeb42deb2 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Sun, 4 Apr 2021 22:02:24 +0100 Subject: [PATCH 1/2] new image --- test/assets/fakedata/draw_boxes_util.png | Bin 547 -> 547 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/assets/fakedata/draw_boxes_util.png b/test/assets/fakedata/draw_boxes_util.png index d64fa2f1f360fc386494b915cef0675fdee705a0..2c361c5fafd52abb6a6b645e92fb4fe972a716ac 100644 GIT binary patch delta 408 zcmV;J0cZZB1fv9yH-9h$%+VD%;W^44aLNkI(L-10BI$vY9@^S@R@8!d->DLUMo+fm zSco*nm<}mgjW1*Kd+*LFB970;wm0Wjx1Dih0d5@tV*!iCx-MItu3yV7@Vzfs;WR{(p#fEs z*ov49WVwoR~@H$lY!0000JpD ze65b&+W$`ZP+aNqi0@{h+bxe~?Nhinb-ksw(j_y?BU<~`ZZ3QHqkdK4O9lyU1F;01 z0}%&S{VR(L4;Omv5qSHa=EbXQ=UmowRMge~d%N~y?wU1e#b36id^Ta}VfC5c_V{r{ zO`xUx`y*PfqWNBTbXd6LB-O|~{@~tTIyXpjEBCdJN!QEH&rmKeGo53d{`AD(*t;tt zH}=iEGkM0m2e~EBE-`}bjErd5$dJrxn^`|K~py{T-P0=w87$Iq$C6 z`0W#Z9uhnKrMKiXe~H+;%ZrM`miL~UCLKBbSZ=yZWP>+5(CLddp1T~j{PXo9;hOit zVHHwJlOHmQPJYTLh=%!f)#kYx|IV(ek>ITr^Zoq2?BrzukW(Ho8$Au!@O7ueL Date: Tue, 6 Apr 2021 08:30:45 +0100 Subject: [PATCH 2/2] avoid check if pil version is < 8.2 as the reference image would be different --- test/test_utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/test_utils.py b/test/test_utils.py index b9893cdd1ac..8c4cc620229 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -7,7 +7,10 @@ import unittest from io import BytesIO import torchvision.transforms.functional as F -from PIL import Image +from PIL import Image, __version__ as PILLOW_VERSION + + +PILLOW_VERSION = tuple(int(x) for x in PILLOW_VERSION.split('.')) boxes = torch.tensor([[0, 0, 20, 20], [0, 0, 0, 0], [10, 15, 30, 35], [23, 35, 93, 95]], dtype=torch.float) @@ -120,8 +123,11 @@ def test_draw_boxes(self): res = Image.fromarray(result.permute(1, 2, 0).contiguous().numpy()) res.save(path) - expected = torch.as_tensor(np.array(Image.open(path))).permute(2, 0, 1) - self.assertTrue(torch.equal(result, expected)) + if PILLOW_VERSION >= (8, 2): + # The reference image is only valid for new PIL versions + expected = torch.as_tensor(np.array(Image.open(path))).permute(2, 0, 1) + self.assertTrue(torch.equal(result, expected)) + # Check if modification is not in place self.assertTrue(torch.all(torch.eq(boxes, boxes_cp)).item()) self.assertTrue(torch.all(torch.eq(img, img_cp)).item())