如何将我的 TensorFlow saved_model.pb 转换为 Javascript?
How do I convert my TensorFlow saved_model.pb to Javascript?
我已经能够 运行 我的终端中的 tensorflow 转换器,但我不确定如何更改 TensorFlow 提供的以下示例以在计算机上找到我的 saved_model.pb 路径,并且将其保存为 Javascript 文件:
tensorflowjs_converter \
--input_format=tf_saved_model \
--output_format=tfjs_graph_model \
--signature_name=serving_default \
--saved_model_tags=serve \
/mobilenet/saved_model \
/mobilenet/web_model
这是我在导致错误的终端上的输入:
tensorflowjs_converter \
--input_format=tf_saved_model \
--output_format=tfjs_graph_model \
--signature_name=serving_default \
--saved_model_tags=serve \
/Users/name/Desktop/name\ name\ TensorFlow/saved_model \
/Users/name/Desktop/name\ name\ TensorFlow/web_model
usage: TensorFlow.js model converters. [-h]
[--input_format {tf_frozen_model,keras_saved_model,tfjs_layers_model,tf_hub,tf_saved_model,keras}]
[--output_format {tfjs_layers_model,keras_saved_model,tfjs_graph_model,keras}]
[--signature_name SIGNATURE_NAME]
[--saved_model_tags SAVED_MODEL_TAGS]
[--quantize_float16 [QUANTIZE_FLOAT16]]
[--quantize_uint8 [QUANTIZE_UINT8]]
[--quantize_uint16 [QUANTIZE_UINT16]]
[--quantization_bytes {1,2}]
[--split_weights_by_layer] [--version]
[--skip_op_check]
[--strip_debug_ops STRIP_DEBUG_OPS]
[--weight_shard_size_bytes WEIGHT_SHARD_SIZE_BYTES]
[--output_node_names OUTPUT_NODE_NAMES]
[--control_flow_v2 CONTROL_FLOW_V2]
[--experiments EXPERIMENTS]
[input_path] [output_path]
TensorFlow.js model converters.: error: unrecognized arguments: TensorFlow/saved_model /Users/ned/Desktop/name name TensorFlow/web_model
当我尝试使用 Tensorflow 转换器时,它说原始路径是错误的:
Welcome to TensorFlow.js Converter.
? Please provide the path of model file or the directory that contains model fil
If you are converting TFHub module please provide the URL. /Users/name/Desktop/name\ name\ TensorFlow/saved_model.pb
? What is your input model format? (model format cannot be detected.) Tensorfl
? The original path seems to be wrong, what is the directory that contains the m
odel?
它只允许访问 home 下的文件夹,所以它只是:
/Users/ned/Tensorflow
尝试使用 Tensorflow 转换器查找路径时。
我发现自己在 Python 中编写转换器更容易,将脚本移动到与目录相同的文件夹,然后 运行 在那里。像这样:
from tensorflow import keras
import tensorflowjs as tfjs
def importModel(modelPath):
model = keras.models.load_model(modelPath)
tfjs.converters.save_keras_model(model, "tfjsmodel")
importModel("modelDirectory")
这样你只需要在相对路径名中写模型的目录名。
我已经能够 运行 我的终端中的 tensorflow 转换器,但我不确定如何更改 TensorFlow 提供的以下示例以在计算机上找到我的 saved_model.pb 路径,并且将其保存为 Javascript 文件:
tensorflowjs_converter \
--input_format=tf_saved_model \
--output_format=tfjs_graph_model \
--signature_name=serving_default \
--saved_model_tags=serve \
/mobilenet/saved_model \
/mobilenet/web_model
这是我在导致错误的终端上的输入:
tensorflowjs_converter \
--input_format=tf_saved_model \
--output_format=tfjs_graph_model \
--signature_name=serving_default \
--saved_model_tags=serve \
/Users/name/Desktop/name\ name\ TensorFlow/saved_model \
/Users/name/Desktop/name\ name\ TensorFlow/web_model
usage: TensorFlow.js model converters. [-h]
[--input_format {tf_frozen_model,keras_saved_model,tfjs_layers_model,tf_hub,tf_saved_model,keras}]
[--output_format {tfjs_layers_model,keras_saved_model,tfjs_graph_model,keras}]
[--signature_name SIGNATURE_NAME]
[--saved_model_tags SAVED_MODEL_TAGS]
[--quantize_float16 [QUANTIZE_FLOAT16]]
[--quantize_uint8 [QUANTIZE_UINT8]]
[--quantize_uint16 [QUANTIZE_UINT16]]
[--quantization_bytes {1,2}]
[--split_weights_by_layer] [--version]
[--skip_op_check]
[--strip_debug_ops STRIP_DEBUG_OPS]
[--weight_shard_size_bytes WEIGHT_SHARD_SIZE_BYTES]
[--output_node_names OUTPUT_NODE_NAMES]
[--control_flow_v2 CONTROL_FLOW_V2]
[--experiments EXPERIMENTS]
[input_path] [output_path]
TensorFlow.js model converters.: error: unrecognized arguments: TensorFlow/saved_model /Users/ned/Desktop/name name TensorFlow/web_model
当我尝试使用 Tensorflow 转换器时,它说原始路径是错误的:
Welcome to TensorFlow.js Converter.
? Please provide the path of model file or the directory that contains model fil
If you are converting TFHub module please provide the URL. /Users/name/Desktop/name\ name\ TensorFlow/saved_model.pb
? What is your input model format? (model format cannot be detected.) Tensorfl
? The original path seems to be wrong, what is the directory that contains the m
odel?
它只允许访问 home 下的文件夹,所以它只是:
/Users/ned/Tensorflow
尝试使用 Tensorflow 转换器查找路径时。
我发现自己在 Python 中编写转换器更容易,将脚本移动到与目录相同的文件夹,然后 运行 在那里。像这样:
from tensorflow import keras
import tensorflowjs as tfjs
def importModel(modelPath):
model = keras.models.load_model(modelPath)
tfjs.converters.save_keras_model(model, "tfjsmodel")
importModel("modelDirectory")
这样你只需要在相对路径名中写模型的目录名。