-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.py
30 lines (25 loc) · 866 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import imageio
import logging
from pathlib import Path
import sys
import matplotlib.pyplot as plt
from tqdm import tqdm
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(pathname)s:%(lineno)d | %(levelname)s: %(message)s",
datefmt="%H:%M:%S",
stream=sys.stdout,
)
def save_fig(fig, path, dpi=100, tight_layout_kwargs={}):
Path(path).parent.mkdir(parents=True, exist_ok=True)
fig.tight_layout(**tight_layout_kwargs)
fig.savefig(path, bbox_inches="tight", dpi=dpi)
logging.info(f"Saved to {path}")
plt.close(fig)
def make_gif(img_paths, gif_path, fps):
Path(gif_path).parent.mkdir(parents=True, exist_ok=True)
images = []
for img_path in tqdm(img_paths):
images.append(imageio.imread(img_path))
imageio.mimsave(gif_path, images, duration=1 / fps)
logging.info(f"Saved to {gif_path}")