@@ -422,77 +422,6 @@ def test_encode_jpeg_errors():
422
422
encode_jpeg (torch .empty ((100 , 100 ), dtype = torch .uint8 ))
423
423
424
424
425
- def _collect_if (cond ):
426
- # TODO: remove this once test_encode_jpeg_reference and test_write_jpeg_reference
427
- # are removed
428
- def _inner (test_func ):
429
- if cond :
430
- return test_func
431
- else :
432
- return pytest .mark .dont_collect (test_func )
433
-
434
- return _inner
435
-
436
-
437
- @_collect_if (cond = False )
438
- @pytest .mark .parametrize (
439
- "img_path" ,
440
- [pytest .param (jpeg_path , id = _get_safe_image_name (jpeg_path )) for jpeg_path in get_images (ENCODE_JPEG , ".jpg" )],
441
- )
442
- def test_encode_jpeg_reference (img_path ):
443
- # This test is *wrong*.
444
- # It compares a torchvision-encoded jpeg with a PIL-encoded jpeg (the reference), but it
445
- # starts encoding the torchvision version from an image that comes from
446
- # decode_jpeg, which can yield different results from pil.decode (see
447
- # test_decode... which uses a high tolerance).
448
- # Instead, we should start encoding from the exact same decoded image, for a
449
- # valid comparison. This is done in test_encode_jpeg, but unfortunately
450
- # these more correct tests fail on windows (probably because of a difference
451
- # in libjpeg) between torchvision and PIL.
452
- # FIXME: make the correct tests pass on windows and remove this.
453
- dirname = os .path .dirname (img_path )
454
- filename , _ = os .path .splitext (os .path .basename (img_path ))
455
- write_folder = os .path .join (dirname , "jpeg_write" )
456
- expected_file = os .path .join (write_folder , f"{ filename } _pil.jpg" )
457
- img = decode_jpeg (read_file (img_path ))
458
-
459
- with open (expected_file , "rb" ) as f :
460
- pil_bytes = f .read ()
461
- pil_bytes = torch .as_tensor (list (pil_bytes ), dtype = torch .uint8 )
462
- for src_img in [img , img .contiguous ()]:
463
- # PIL sets jpeg quality to 75 by default
464
- jpeg_bytes = encode_jpeg (src_img , quality = 75 )
465
- assert_equal (jpeg_bytes , pil_bytes )
466
-
467
-
468
- @_collect_if (cond = False )
469
- @pytest .mark .parametrize (
470
- "img_path" ,
471
- [pytest .param (jpeg_path , id = _get_safe_image_name (jpeg_path )) for jpeg_path in get_images (ENCODE_JPEG , ".jpg" )],
472
- )
473
- def test_write_jpeg_reference (img_path , tmpdir ):
474
- # FIXME: Remove this eventually, see test_encode_jpeg_reference
475
- data = read_file (img_path )
476
- img = decode_jpeg (data )
477
-
478
- basedir = os .path .dirname (img_path )
479
- filename , _ = os .path .splitext (os .path .basename (img_path ))
480
- torch_jpeg = os .path .join (tmpdir , f"{ filename } _torch.jpg" )
481
- pil_jpeg = os .path .join (basedir , "jpeg_write" , f"{ filename } _pil.jpg" )
482
-
483
- write_jpeg (img , torch_jpeg , quality = 75 )
484
-
485
- with open (torch_jpeg , "rb" ) as f :
486
- torch_bytes = f .read ()
487
-
488
- with open (pil_jpeg , "rb" ) as f :
489
- pil_bytes = f .read ()
490
-
491
- assert_equal (torch_bytes , pil_bytes )
492
-
493
-
494
- # TODO: Remove the skip. See https://github.com/pytorch/vision/issues/5162.
495
- @pytest .mark .skip ("this test fails because PIL uses libjpeg-turbo" )
496
425
@pytest .mark .parametrize (
497
426
"img_path" ,
498
427
[pytest .param (jpeg_path , id = _get_safe_image_name (jpeg_path )) for jpeg_path in get_images (ENCODE_JPEG , ".jpg" )],
@@ -511,8 +440,6 @@ def test_encode_jpeg(img_path):
511
440
assert_equal (encoded_jpeg_torch , encoded_jpeg_pil )
512
441
513
442
514
- # TODO: Remove the skip. See https://github.com/pytorch/vision/issues/5162.
515
- @pytest .mark .skip ("this test fails because PIL uses libjpeg-turbo" )
516
443
@pytest .mark .parametrize (
517
444
"img_path" ,
518
445
[pytest .param (jpeg_path , id = _get_safe_image_name (jpeg_path )) for jpeg_path in get_images (ENCODE_JPEG , ".jpg" )],
0 commit comments