'AutoTrackable' object is not callable in Python

不羁的心 提交于 2021-02-07 05:42:25

问题


My tensorflow version is 2.0

tensorflow_hub version is 0.7

python version is 3.7

I have these code

import tensorflow as tf
import tensorflow_hub as hub
import summarizer_data_utils

specials = ["<EOS>", "<SOS>","<PAD>","<UNK>"]
word2ind, ind2word,  missing_words = summarizer_data_utils.create_word_inds_dicts(words_counted,
                                                                       specials = specials)

#embed = hub.Module("https://tfhub.dev/google/nnlm-en-dim128/1")
embed = hub.load("https://tfhub.dev/google/Wiki-words-250/1")
emb = embed([key for key in word2ind.keys()])

and i get this error

Processing Time:  32.69666647911072
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-aefe0bf334ec> in <module>
     84 #embed = hub.Module("https://tfhub.dev/google/nnlm-en-dim128/1")
     85 embed = hub.load("https://tfhub.dev/google/Wiki-words-250/1")
---> 86 emb = embed([key for key in word2ind.keys()])
     87 
     88 with tf.Session() as sess:

TypeError: 'AutoTrackable' object is not callable

How should i solve it?

Edited: I have found my solution. I just need to change

https://tfhub.dev/google/Wiki-words-250/1

to

https://tfhub.dev/google/Wiki-words-250/2

回答1:


This is part of the common issues in TensorFlow: https://www.tensorflow.org/hub/common_issues

Solution is to extract the signature that you need, for example:

embed = hub.load('https://tfhub.dev/google/nnlm-en-dim128/1')
embed.signatures['default'](['my text', 'batch'])


来源:https://stackoverflow.com/questions/59471873/autotrackable-object-is-not-callable-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!