首页 > 解决方案 > python注册表Tensorflow中缺少图形操作

问题描述

我正在尝试使用通用句子编码器多语言模块。我正在使用 tensorflow 1.14 版本。在参考了关于stackoverflow的其他问题后,一个可能的原因是使用了旧版本的tensorflow,这里不是这种情况。

更新:添加了 python 包版本

###  Tensorflow version : 1.14.0
###  sentencepiece: 0.1.82
###  tf-sentencepiece: 0.1.82.1

use_large_module_url = "https://tfhub.dev/google/universal-sentence-encoder-large/3" #@param ["https://tfhub.dev/google/universal-sentence-encoder/2", "https://tfhub.dev/google/universal-sentence-encoder-large/3"]
use_lite_module_url = "https://tfhub.dev/google/universal-sentence-encoder-lite/2"
use_multilingual_url = 'https://tfhub.dev/google/universal-sentence-encoder-multilingual/1'  #@param ['https://tfhub.dev/google/universal-sentence-encoder-multilingual/1', 'https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/1', 'https://tfhub.dev/google/universal-sentence-encoder-xling-many/1']

# embed = hub.Module(use_lite_module_url)
# embed = hub.Module(use_large_module_url)
embed = hub.Module(use_multilingual_url)

错误

---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
<ipython-input-11-22dba73760e9> in <module>()
      5 # embed = hub.Module(use_lite_module_url)
      6 # embed = hub.Module(use_large_module_url)
----> 7 embed = hub.Module(use_multilingual_url)

3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_hub/module.py in __init__(self, spec, trainable, name, tags)
    168           name=self._name,
    169           trainable=self._trainable,
--> 170           tags=self._tags)
    171       # pylint: enable=protected-access
    172 

/usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py in _create_impl(self, name, trainable, tags)
    338         trainable=trainable,
    339         checkpoint_path=self._checkpoint_variables_path,
--> 340         name=name)
    341 
    342   def _export(self, path, variables_saver):

/usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py in __init__(self, spec, meta_graph, trainable, checkpoint_path, name)
    380 
    381     register_ops_if_needed({
--> 382         op.name for op in self._meta_graph.meta_info_def.stripped_op_list.op})
    383 
    384     if _is_tpu_graph_function():

/usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py in register_ops_if_needed(graph_ops)
    820         "Graph ops missing from the python registry (%s) are also absent from "
    821         "the c++ registry."
--> 822         % missing_ops.difference(set(cpp_registry_ops.keys())))
    823 
    824 

NotFoundError: Graph ops missing from the python registry ({'SentencepieceEncodeSparse'}) are also absent from the c++ registry.

标签: pythontensorflow

解决方案


这里同样的问题。这是我修复它的方法:

pip install tf_sentencepiece

然后你必须在代码中加载它:

import tensorflow as tf
import tensorflow_hub as hub
import tf_sentencepiece # <- ADD THIS

embed = hub.Module(...)

推荐阅读