-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scripts): define script for loading cases
The new script is best suited for loading boiling cases, and came from working implementations on Google Colab.
- Loading branch information
1 parent
d676e1e
commit 969ec2d
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Iterable, Tuple | ||
|
||
from dataclassy import dataclass | ||
|
||
from boiling_learning.preprocessing import Case | ||
from boiling_learning.utils import print_header, print_verbose | ||
from boiling_learning.utils.pathutils import PathLike | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Options: | ||
convert_videos: bool = False | ||
extract_audios: bool = False | ||
pre_load_videos: bool = False | ||
extract_frames: bool = False | ||
|
||
|
||
def main( | ||
casepaths: Iterable[PathLike], | ||
video_suffix: str, | ||
options: Options, | ||
verbose: bool = True, | ||
) -> Tuple[Case, ...]: | ||
cases = tuple( | ||
Case(casepath, video_suffix=video_suffix) for casepath in casepaths | ||
) | ||
|
||
for case in cases: | ||
if verbose: | ||
print_header(case.name) | ||
|
||
if options.convert_videos: | ||
print_verbose(verbose, 'Converting videos') | ||
case.convert_videos( | ||
'.mp4', 'converted', verbose=True, overwrite=False | ||
) | ||
if options.extract_audios: | ||
print_verbose(verbose, 'Extracting audios') | ||
case.extract_audios(verbose=True) | ||
if options.pre_load_videos: | ||
print_verbose(verbose, 'Opening videos') | ||
case.open_videos() | ||
if options.extract_frames: | ||
print_verbose(verbose, 'Extracting videos') | ||
case.extract_frames( | ||
overwrite=False, | ||
verbose=2, | ||
chunk_sizes=(100, 100), | ||
iterate=True, | ||
) | ||
|
||
return cases | ||
|
||
|
||
if __name__ == '__main__': | ||
raise RuntimeError( | ||
'*interact_frames* cannot be executed as a standalone script yet.' | ||
) |