MCPcopy Create free account
hub / github.com/MeiGen-AI/MultiTalk / cache_image

Function cache_image

wan/utils/utils.py:64–91  ·  view source on GitHub ↗
(tensor,
                save_file,
                nrow=8,
                normalize=True,
                value_range=(-1, 1),
                retry=5)

Source from the content-addressed store, hash-verified

62
63
64def cache_image(tensor,
65 save_file,
66 nrow=8,
67 normalize=True,
68 value_range=(-1, 1),
69 retry=5):
70 # cache file
71 suffix = osp.splitext(save_file)[1]
72 if suffix.lower() not in [
73 '.jpg', '.jpeg', '.png', '.tiff', '.gif', '.webp'
74 ]:
75 suffix = '.png'
76
77 # save to cache
78 error = None
79 for _ in range(retry):
80 try:
81 tensor = tensor.clamp(min(value_range), max(value_range))
82 torchvision.utils.save_image(
83 tensor,
84 save_file,
85 nrow=nrow,
86 normalize=normalize,
87 value_range=value_range)
88 return save_file
89 except Exception as e:
90 error = e
91 continue
92
93
94def str2bool(v):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected