Skip to content

Commit

Permalink
[ADD][FEAT](cli) add model cli commands
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenbihi committed Aug 23, 2022
1 parent a14b9ec commit dbb3fc7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import click

from .mpii import mpii
from cli.mpii import mpii
from cli.model import model


@click.group()
Expand All @@ -12,6 +13,7 @@ def cli():

# Register Commands
cli.add_command(mpii)
cli.add_command(model)


if __name__ == "__main__":
Expand Down
60 changes: 60 additions & 0 deletions cli/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import datetime

import click
import tensorflow as tf
from loguru import logger

from hourglass_tensorflow.types.config import HTFConfig
from hourglass_tensorflow.types.config import HTFConfigParser
from hourglass_tensorflow.handlers.model import HTFModelHandler


@click.group()
def model():
"""Operation related to Model"""


@click.command()
@click.option(
"--verbose/--no-verbose",
"-v",
default=False,
help="Activate Logs",
type=bool,
)
@click.argument("input")
@click.argument("output")
def log(verbose, input, output):
"""Create a TensorBoard log to visualize graph"""
if verbose:
logger.debug(f"input:\t {input}")
logger.debug(f"output:\t {output}")
try:
if verbose:
logger.info(f"Reading {input}...")
config = HTFConfig.parse_obj(
HTFConfigParser.parse(filename=input, verbose=verbose)
)
writer = tf.summary.create_file_writer(output)
tf.summary.trace_on(graph=True, profiler=True)
if verbose:
logger.info("Building Graph...")
model_handler = HTFModelHandler(config=config.model, verbose=verbose)
model_handler()
if verbose:
logger.info("Writing Graph...")
with writer.as_default():
tf.summary.trace_export(
name=f"GraphTrace_{datetime.datetime.now()}",
step=0,
profiler_outdir=f"{output}/graph",
)
if verbose:
logger.success("Operation completed!")
except Exception as e:
if verbose:
logger.exception(e)
logger.error("Operation aborted!")


model.add_command(log)

0 comments on commit dbb3fc7

Please sign in to comment.