Tensor is unhashable if Tensor equality is enabled【解决办法】

今天爱分享给大家带来Tensor is unhashable if Tensor equality is enabled【解决办法】,希望能够帮助到大家。

具体的报错信息如下:Tensor is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.
报错地方的代码如下,使用的tensorflow版本为2.0

self.best_model = tf.keras.models.load_model(self.save_model_path)
batch_logits = self.best_model(tensorized_sents)
batch_tagids = tf.argmax(batch_logits, axis=2)  # [[[ ]]]
# 将id转化为标注
pred_tag_lists = []
id2tag = dict((id_, tag) for tag, id_ in tag2id.items())
for i, ids in enumerate(batch_tagids):
      tag_list = []
      if self.crf:
           for j in range(lengths[i] - 1):  # crf解码过程中,end被舍弃
                    tag_list.append(id2tag[ids[j]])
           else:
               for j in range(lengths[i]):
                   tag_list.append(id2tag[ids[j]])  # 报错的地方在这里
      pred_tag_lists.append(tag_list)

报错的地方在遍历tensor并利用id2tag进行还原标签处;怀疑是因为tensor不可以使用下标去遍历的原因,所以需要将tensor转换为array数组

所以在batch_tagids的地方将其转换为array,代码如下:

batch_tagids = tf.argmax(batch_logits, axis=2).numpy()
原文链接:https://blog.itblood.com/1854.html,转载请注明出处。
0
半老徐娘S2v10.01 官中版[PC+安卓/14.6G/更新]MILFs of Sunville [S2 v10.01] [神作SLG/汉化/沙盒]
半老徐娘S2v10.01 官中版[PC+安卓/14.6G/更新]MILFs of Sunville [S2 v10.01] [神作SLG/汉化/沙盒]
刚刚 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?