Skip to content

Commit

Permalink
feat(#61): support train
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Sep 23, 2019
1 parent 79a2c85 commit af05c72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions stagesepx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ def cut(
return res, data_home


def train(
data_home: str,
save_to: str,
compress_rate: float = 0.2,
target_size: typing.Tuple[int, int] = None,
):
"""
build a trained model with a dataset
:param data_home: output path (dir)
:param save_to: model will be saved to this path
:param compress_rate: before_pic * compress_rate = after_pic. default to 0.2
:param target_size: (100, 200)
"""
assert os.path.isdir(data_home), f"dir {data_home} not existed"
assert not os.path.isfile(save_to), f"file {save_to} already existed"
cl = SVMClassifier(compress_rate=compress_rate, target_size=target_size)
cl.load(data_home)
cl.train()
cl.save_model(save_to)


def classify(
video_path: str,
data_home: str = None,
Expand Down
1 change: 1 addition & 0 deletions stagesepx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TerminalCli(object):
one_step = staticmethod(api.one_step)
cut = staticmethod(api.cut)
classify = staticmethod(api.classify)
train = staticmethod(api.train)


def main():
Expand Down

0 comments on commit af05c72

Please sign in to comment.