Use tfjs binary to make inference and store output in file. Args: binary_path: Path to the nodejs binary. The path can be an absolute path (preferred) or a relative path from this python script's current directory. model_path: Directory to TensorFlow.js model's json file.
(binary_path,
model_path,
inputs_dir,
outputs_dir,
backend=None,
tf_output_name_file=None)
| 22 | |
| 23 | |
| 24 | def predict(binary_path, |
| 25 | model_path, |
| 26 | inputs_dir, |
| 27 | outputs_dir, |
| 28 | backend=None, |
| 29 | tf_output_name_file=None): |
| 30 | """Use tfjs binary to make inference and store output in file. |
| 31 | |
| 32 | Args: |
| 33 | binary_path: Path to the nodejs binary. The path can be an absolute path |
| 34 | (preferred) or a relative path from this python script's current |
| 35 | directory. |
| 36 | model_path: Directory to TensorFlow.js model's json file. |
| 37 | inputs_dir: Directory to the inputs files, including data, shape and dtype |
| 38 | files. |
| 39 | outputs_dir: Directory to write the outputs files, including data, shape |
| 40 | and dtype files. |
| 41 | backend: Optional. Choose which TensorFlow.js backend to use. Supported |
| 42 | backends include cpu and wasm. Default: cpu |
| 43 | tf_output_name_file: Optional. File name of the tf_output_name, if file does |
| 44 | not exist, will use the default outputs of the model. |
| 45 | """ |
| 46 | model_path_option = '--model_path=' + model_path |
| 47 | inputs_dir_option = '--inputs_dir=' + inputs_dir |
| 48 | outputs_dir_option = '--outputs_dir=' + outputs_dir |
| 49 | |
| 50 | tfjs_inference_command = [ |
| 51 | binary_path, model_path_option, inputs_dir_option, |
| 52 | outputs_dir_option |
| 53 | ] |
| 54 | |
| 55 | if tf_output_name_file: |
| 56 | tf_output_name_file_option = '--tf_output_name_file=' + tf_output_name_file |
| 57 | tfjs_inference_command.append(tf_output_name_file_option) |
| 58 | |
| 59 | if backend: |
| 60 | backend_option = '--backend=' + backend |
| 61 | tfjs_inference_command.append(backend_option) |
| 62 | |
| 63 | popen = subprocess.Popen( |
| 64 | tfjs_inference_command, |
| 65 | stdin=subprocess.PIPE, |
| 66 | stdout=subprocess.PIPE, |
| 67 | stderr=subprocess.PIPE) |
| 68 | stdout, stderr = popen.communicate() |
| 69 | |
| 70 | if popen.returncode != 0: |
| 71 | raise ValueError('Inference failed with status %d\nstderr:\n%s' % |
| 72 | (popen.returncode, stderr.decode())) |
nothing calls this directly
no test coverage detected
searching dependent graphs…