Сохранение оценщика TensorFlow в веб-формате (tf js) - PullRequest
0 голосов
/ 06 мая 2020

У меня есть линейный оценщик в TF 2.2, и в настоящее время я сохраняю его следующим образом 1015 *, потому что python tf 2.2 слишком велик для AWS Lambda.

Есть ли возможность сохранить его прямо из python в веб-формат? Я уже пытался преобразовать его с помощью этого урока https://www.tensorflow.org/js/tutorials/conversion/import_saved_model, но он не работает. Я также не уверен, что такое --output_node_names

Я создал модель с Python 3.8, и теперь я использую 3.6.8 в venv для конвертера, потому что конвертер не работает с 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

Спасибо

1 Ответ

0 голосов
/ 08 мая 2020

Итак, похоже, вы используете операции, которые не поддерживаются в реализации TensorFlow в браузере. js (это не относится к Node.js, который может выполнять сохраненные модели без преобразования).

TensorFlow. js поддерживает несколько сотен или около того операций из исходной реализации TensorFlow для реализации на основе браузера, поэтому единственный способ запустить это в браузере прямо сейчас - это:

  1. Реализовать операции в JS - внести вклад в открытый исходный код на Github для отсутствующих операций.
  2. Измените используемые операции, чтобы использовать поддерживаемые операции.

Вы можете увидеть поддерживаемые операции здесь: https://github.com/tensorflow/tfjs-converter/blob/master/tfjs-converter/docs/supported_ops.md

...