File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
tensorflow_datasets/core/utils Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 20
20
from __future__ import annotations
21
21
22
22
import csv
23
+ import functools
23
24
import subprocess
24
25
from typing import Any , List , Optional
25
26
34
35
THUMBNAIL_SIZE = 128
35
36
36
37
38
+ @functools .cache
39
+ def _allow_pil_to_load_truncated_images ():
40
+ """Allows truncated images.
41
+
42
+ The function is cached to be called only once. Activating this flag solves
43
+ issues where the image cannot be converted to RGB.
44
+ """
45
+ try :
46
+ from PIL import ImageFile # pylint: disable=g-import-not-at-top
47
+
48
+ ImageFile .LOAD_TRUNCATED_IMAGES = True
49
+ except ImportError :
50
+ pass
51
+
52
+
37
53
@py_utils .memoize ()
38
54
def _get_runner ():
39
55
return tf_utils .TFGraphRunner ()
@@ -148,6 +164,7 @@ def _postprocess_noop(img: PilImage) -> PilImage:
148
164
149
165
150
166
def _postprocess_convert_rgb (img : PilImage ) -> PilImage :
167
+ _allow_pil_to_load_truncated_images ()
151
168
return img .convert ('RGB' )
152
169
153
170
You can’t perform that action at this time.
0 commit comments