TensorFlow估算器以web格式保存(tfjs)

问题描述 投票:0回答:1

我在TF 2.2中有一个linar估算器,目前保存方式如下。

linear_est = tf.estimator.LinearClassifier(feature_columns=feature_columns)
...
serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
tf.feature_column.make_parse_example_spec(feature_columns))
export_path = linear_est.export_saved_model(
              "./model/", serving_input_fn)

我得到了一个.pb文件和一个变量文件夹,但我需要在tfjs中运行预测,因为python tf 2.2对AWS Lambda来说太大。

有没有可能将它直接从python保存为web格式?https:/www.tensorflow.orgjstutorialsconversionimport_saved_model但它没有工作。我也不知道--output_node_names是什么。

我用Python 3.8创建了模型,现在我在venv中使用3.6.8的转换器,因为转换器不能用3.8运行。

(venv) PS C:\predict\web> tensorflowjs_converter --input_format=tf_saved_model --saved_model_tags=serve sold/model/1588619275 sold_web
2020-05-06 22:17:35.434178: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From c:\predict\web\venv\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py:1786: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
WARNING:tensorflow:Issue encountered when serializing global_step.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
to_proto not supported in EAGER mode.
WARNING:tensorflow:Issue encountered when serializing variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
to_proto not supported in EAGER mode.
WARNING:tensorflow:Issue encountered when serializing trainable_variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
to_proto not supported in EAGER mode.
2020-05-06 22:17:36.264215: I tensorflow/core/grappler/devices.cc:60] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA support)
2020-05-06 22:17:36.283583: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2020-05-06 22:17:36.296771: E tensorflow/core/grappler/grappler_item_builder.cc:656] Init node linear/linear_model/linear/linear_model/linear/linear_model/category_id/category_id_lookup/hash_table/table_init/LookupTableImportV2 doesn't exist in graph
WARNING:tensorflow:From c:\predict\web\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py:313: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
WARNING:tensorflow:From c:\predict\web\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py:315: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.convert_variables_to_constants`
WARNING:tensorflow:From c:\predict\web\venv\lib\site-packages\tensorflow_core\python\framework\graph_util_impl.py:277: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.extract_sub_graph`
Traceback (most recent call last):
  File "c:\users\nibur\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\nibur\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\predict\web\venv\Scripts\tensorflowjs_converter.exe\__main__.py", line 7, in <module>
  File "c:\predict\web\venv\lib\site-packages\tensorflowjs\converters\converter.py", line 671, in pip_main
    main([' '.join(sys.argv[1:])])
  File "c:\predict\web\venv\lib\site-packages\tensorflowjs\converters\converter.py", line 675, in main
    convert(argv[0].split(' '))
  File "c:\predict\web\venv\lib\site-packages\tensorflowjs\converters\converter.py", line 618, in convert
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "c:\predict\web\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 462, in convert_tf_saved_model
    weight_shard_size_bytes=weight_shard_size_bytes)
  File "c:\predict\web\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 142, in optimize_graph
    ', '.join(unsupported))
ValueError: Unsupported Ops in the model before optimization
SparseFillEmptyRows, Unique, LookupTableFindV2, ParseExampleV2, HashTableV2, SparseSegmentSum, AsString, SparseReshape

谅谅

python-3.x tensorflow machine-learning tensorflow.js
1个回答
0
投票

因此,你似乎使用了TensorFlow.js的浏览器实现中不支持的操作(这不适用于Node.js,它可以在不转换的情况下执行保存的Models)。

TensorFlow.js支持基于浏览器实现的原TensorFlow实现中的几百个左右的ops,所以现在在浏览器中运行的唯一方法是。

  1. 在JS中实现这些操作--将缺少的操作贡献给Github上的开源代码。
  2. 改变你正在使用的OPS,使用支持的OPS。

你可以在这里看到支持的操作。https:/github.comtensorflowtfjs-converterblobmastertfjs-converterdocssupported_ops.md。

© www.soinside.com 2019 - 2024. All rights reserved.