[Python API] Improve configuration files (#10960)
* [Python API] Improve configuration files * fix config files * update setup.cfd + change quotes * move all codestyle checks to py_checks job * update requirements_test.txt * fix codestyle according to flake-docstring * fix * fix mypy * apply comments
This commit is contained in:
1 parent
be6db5d69a
commit
4c7050f6a9
22 files changed
+378
-1541
No files matched your search
@@ -14,7 +14,7 @@ from openvino.runtime import AsyncInferQueue, Core, InferRequest, Layout, Type
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
"""Parse and return command line arguments"""
|
||||
"""Parse and return command line arguments."""
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
args = parser.add_argument_group('Options')
|
||||
# fmt: off
|
||||
|
||||
@@ -9,7 +9,7 @@ from openvino.runtime import Core
|
||||
|
||||
|
||||
def param_to_string(parameters) -> str:
|
||||
"""Convert a list / tuple of parameters returned from IE to a string"""
|
||||
"""Convert a list / tuple of parameters returned from IE to a string."""
|
||||
if isinstance(parameters, (list, tuple)):
|
||||
return ', '.join([str(x) for x in parameters])
|
||||
else:
|
||||
|
||||
@@ -16,7 +16,7 @@ from data import digits
|
||||
|
||||
|
||||
def create_ngraph_function(model_path: str) -> Model:
|
||||
"""Create a model on the fly from the source code using ngraph"""
|
||||
"""Create a model on the fly from the source code using ngraph."""
|
||||
|
||||
def shape_and_length(shape: list) -> typing.Tuple[list, int]:
|
||||
length = reduce(lambda x, y: x * y, shape)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
[flake8]
|
||||
# ignore:
|
||||
# D100 - Missing docstring in public module
|
||||
# D101 - Missing docstring in public class
|
||||
# D103 - Missing docstring in public function
|
||||
filename = *.py
|
||||
max-line-length = 160
|
||||
ignore = E203
|
||||
ignore = E203,D100,D101,D103
|
||||
max-parameters-amount = 8
|
||||
show_source = True
|
||||
docstring-convention = google
|
||||
|
||||
@@ -5,7 +5,7 @@ import argparse
|
||||
|
||||
|
||||
def build_arg_parser() -> argparse.ArgumentParser:
|
||||
"""Create and return argument parser"""
|
||||
"""Create and return argument parser."""
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
args = parser.add_argument_group('Options')
|
||||
model = parser.add_mutually_exclusive_group(required=True)
|
||||
@@ -73,7 +73,7 @@ def build_arg_parser() -> argparse.ArgumentParser:
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
"""Parse and validate command-line arguments"""
|
||||
"""Parse and validate command-line arguments."""
|
||||
parser = build_arg_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ class FileData(NamedTuple):
|
||||
|
||||
|
||||
def read_ark_file(file_name: str) -> FileData:
|
||||
"""Read utterance matrices from a .ark file"""
|
||||
"""Read utterance matrices from a .ark file."""
|
||||
def read_key(input_file: IO[Any]) -> str:
|
||||
"""Read a identifier of utterance matrix"""
|
||||
"""Read a identifier of utterance matrix."""
|
||||
key = ''
|
||||
char = input_file.read(1).decode()
|
||||
|
||||
@@ -28,7 +28,7 @@ def read_ark_file(file_name: str) -> FileData:
|
||||
return key
|
||||
|
||||
def read_matrix(input_file: IO[Any]) -> np.ndarray:
|
||||
"""Read a utterance matrix"""
|
||||
"""Read a utterance matrix."""
|
||||
header = input_file.read(5).decode()
|
||||
if 'FM' in header:
|
||||
num_of_bytes = 4
|
||||
@@ -61,7 +61,7 @@ def read_ark_file(file_name: str) -> FileData:
|
||||
|
||||
|
||||
def write_ark_file(file_name: str, keys: List[str], utterances: List[np.ndarray]):
|
||||
"""Write utterance matrices to a .ark file"""
|
||||
"""Write utterance matrices to a .ark file."""
|
||||
with open(file_name, 'wb') as output_file:
|
||||
for key, matrix in zip(keys, utterances):
|
||||
# write a utterance key
|
||||
@@ -86,7 +86,7 @@ def write_ark_file(file_name: str, keys: List[str], utterances: List[np.ndarray]
|
||||
|
||||
|
||||
def read_utterance_file(file_name: str) -> FileData:
|
||||
"""Read utterance matrices from a file"""
|
||||
"""Read utterance matrices from a file."""
|
||||
file_extension = file_name.split('.')[-1]
|
||||
|
||||
if file_extension == 'ark':
|
||||
@@ -100,7 +100,7 @@ def read_utterance_file(file_name: str) -> FileData:
|
||||
|
||||
|
||||
def write_utterance_file(file_name: str, keys: List[str], utterances: List[np.ndarray]):
|
||||
"""Write utterance matrices to a file"""
|
||||
"""Write utterance matrices to a file."""
|
||||
file_extension = file_name.split('.')[-1]
|
||||
|
||||
if file_extension == 'ark':
|
||||
|
||||
@@ -22,7 +22,7 @@ from utils import (GNA_ATOM_FREQUENCY, GNA_CORE_FREQUENCY,
|
||||
|
||||
|
||||
def do_inference(data: Dict[str, np.ndarray], infer_request: InferRequest, cw_l: int = 0, cw_r: int = 0) -> np.ndarray:
|
||||
"""Do a synchronous matrix inference"""
|
||||
"""Do a synchronous matrix inference."""
|
||||
frames_to_infer = {}
|
||||
result = {}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ def compare_with_reference(result: np.ndarray, reference: np.ndarray):
|
||||
|
||||
|
||||
def get_scale_factor(matrix: np.ndarray) -> float:
|
||||
"""Get scale factor for quantization using utterance matrix"""
|
||||
"""Get scale factor for quantization using utterance matrix."""
|
||||
# Max to find scale factor
|
||||
target_max = 16384
|
||||
max_val = np.max(matrix)
|
||||
@@ -46,14 +46,14 @@ def get_scale_factor(matrix: np.ndarray) -> float:
|
||||
|
||||
|
||||
def set_scale_factors(plugin_config: dict, scale_factors: list):
|
||||
"""Set a scale factor provided for each input"""
|
||||
"""Set a scale factor provided for each input."""
|
||||
for i, scale_factor in enumerate(scale_factors):
|
||||
log.info(f'For input {i} using scale factor of {scale_factor:.7f}')
|
||||
plugin_config[f'GNA_SCALE_FACTOR_{i}'] = str(scale_factor)
|
||||
|
||||
|
||||
def parse_scale_factors(args: argparse.Namespace) -> list:
|
||||
"""Get a list of scale factors for input files"""
|
||||
"""Get a list of scale factors for input files."""
|
||||
input_files = re.split(', |,', args.input)
|
||||
scale_factors = re.split(', |,', str(args.scale_factor))
|
||||
scale_factors = list(map(float, scale_factors))
|
||||
@@ -72,7 +72,7 @@ def parse_scale_factors(args: argparse.Namespace) -> list:
|
||||
|
||||
|
||||
def parse_outputs_from_args(args: argparse.Namespace) -> Tuple[List[str], List[int]]:
|
||||
"""Get a list of outputs specified in the args"""
|
||||
"""Get a list of outputs specified in the args."""
|
||||
name_and_port = [output.split(':') for output in re.split(', |,', args.output_layers)]
|
||||
try:
|
||||
return [name for name, _ in name_and_port], [int(port) for _, port in name_and_port]
|
||||
|
||||
Reference in new issue
Block a user