ultralytics 8.1.21 Add YOLOv8-World-v2 models (#8580)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
parent
906b8d31dc
commit
946e18f79c
12 changed files with 98 additions and 48 deletions
|
|
@ -60,27 +60,29 @@ def imshow(winname: str, mat: np.ndarray):
|
|||
_torch_save = torch.save # copy to avoid recursion errors
|
||||
|
||||
|
||||
def torch_save(*args, **kwargs):
|
||||
def torch_save(*args, use_dill=True, **kwargs):
|
||||
"""
|
||||
Use dill (if exists) to serialize the lambda functions where pickle does not do this. Also adds 3 retries with
|
||||
exponential standoff in case of save failure to improve robustness to transient issues.
|
||||
Optionally use dill to serialize lambda functions where pickle does not, adding robustness with 3 retries and
|
||||
exponential standoff in case of save failure.
|
||||
|
||||
Args:
|
||||
*args (tuple): Positional arguments to pass to torch.save.
|
||||
use_dill (bool): Whether to try using dill for serialization if available. Defaults to True.
|
||||
**kwargs (dict): Keyword arguments to pass to torch.save.
|
||||
"""
|
||||
try:
|
||||
import dill as pickle # noqa
|
||||
except ImportError:
|
||||
assert use_dill
|
||||
import dill as pickle
|
||||
except (AssertionError, ImportError):
|
||||
import pickle
|
||||
|
||||
if "pickle_module" not in kwargs:
|
||||
kwargs["pickle_module"] = pickle # noqa
|
||||
kwargs["pickle_module"] = pickle
|
||||
|
||||
for i in range(4): # 3 retries
|
||||
try:
|
||||
return _torch_save(*args, **kwargs)
|
||||
except RuntimeError: # unable to save, possibly waiting for device to flush or anti-virus to finish scanning
|
||||
except RuntimeError as e: # unable to save, possibly waiting for device to flush or antivirus scan
|
||||
if i == 3:
|
||||
raise
|
||||
time.sleep((2**i) / 2) # exponential standoff 0.5s, 1.0s, 2.0s
|
||||
raise e
|
||||
time.sleep((2**i) / 2) # exponential standoff: 0.5s, 1.0s, 2.0s
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue