|
@@ -3,21 +3,11 @@ import numpy as np
|
|
|
from os.path import isfile
|
|
|
from PIL import Image
|
|
|
|
|
|
-def read_image(im_path, n_retries=5):
|
|
|
- _read = lambda: Image.open(im_path, mode="r")
|
|
|
- if n_retries <= 0:
|
|
|
- assert isfile(im_path), "Image \"{}\" does not exist!".format(im_path)
|
|
|
- return _read()
|
|
|
-
|
|
|
- else:
|
|
|
- error = None
|
|
|
- for i in range(n_retries):
|
|
|
- try:
|
|
|
- return _read()
|
|
|
- except Exception as e:
|
|
|
- error = e
|
|
|
+from cvdatasets.utils import retry_operation
|
|
|
|
|
|
- raise RuntimeError("Reading image \"{}\" failed after {} n_retries! ({})".format(im_path, n_retries, error))
|
|
|
+def read_image(im_path, n_retries=5):
|
|
|
+ assert isfile(im_path), "Image \"{}\" does not exist!".format(im_path)
|
|
|
+ return retry_operation(n_retries, Image.open, im_path, mode="r")
|
|
|
|
|
|
|
|
|
def asarray(im, dtype=np.uint8):
|