Spaces:
Running
Running
File size: 1,543 Bytes
966ae59 |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# -*- coding: utf-8 -*-
# Author: ximing
# Description: misc
# Copyright (c) 2023, XiMing Xing.
# License: MPL-2.0 License
from datetime import datetime
import random
import pathlib
from typing import Any, List, Dict, Union
import omegaconf
"""Add Type"""
AnyPath = Union[str, pathlib.Path, 'os.PathLike']
AnyList = Union[omegaconf.ListConfig, List]
AnyDict = Union[omegaconf.DictConfig, Dict]
def render_batch_wrap(cfg: omegaconf.DictConfig,
seed_range: List,
pipeline: Any,
**pipe_args):
start_time = datetime.now()
for idx, seed in enumerate(seed_range):
cfg.seed = seed # update seed
print(f"\n-> [{idx}/{len(seed_range)}], "
f"current seed: {seed}, "
f"current time: {datetime.now() - start_time}\n")
pipe = pipeline(cfg)
pipe.painterly_rendering(**pipe_args)
def get_seed_range(srange: AnyList):
# random sampling without specifying a range
start_, end_ = 1, 1000000
if srange is not None: # specify range sequential sampling
seed_range_ = list(srange)
assert len(seed_range_) == 2 and int(seed_range_[1]) > int(seed_range_[0])
start_, end_ = int(seed_range_[0]), int(seed_range_[1])
seed_range = [i for i in range(start_, end_)]
else:
# a list of lengths 1000 sampled from the range start_ to end_ (e.g.: [1, 1000000])
numbers = list(range(start_, end_))
seed_range = random.sample(numbers, k=1000)
return seed_range
|