gpt4 book ai didi

python - 未实现错误: Cannot convert a symbolic Tensor (2nd_target:0) to a numpy array

转载 作者:行者123 更新时间:2023-12-02 07:56:40 26 4
gpt4 key购买 nike

我尝试将 2 个损失函数作为 Keras allows that. 传递给模型

loss: String (name of objective function) or objective function orLoss instance. See losses. If the model has multiple outputs, you canuse a different loss on each output by passing a dictionary or a listof losses. The loss value that will be minimized by the model willthen be the sum of all individual losses.

两个损失函数:

def l_2nd(beta):
def loss_2nd(y_true, y_pred):
...
return K.mean(t)

return loss_2nd

def l_1st(alpha):
def loss_1st(y_true, y_pred):
...
return alpha * 2 * tf.linalg.trace(tf.matmul(tf.matmul(Y, L, transpose_a=True), Y)) / batch_size

return loss_1st

然后我构建模型:

l2 = K.eval(l_2nd(self.beta))
l1 = K.eval(l_1st(self.alpha))
self.model.compile(opt, [l2, l1])

当我训练时,它会产生错误:

1.15.0-rc3 WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630:
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.
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call
last) <ipython-input-20-298384dd95ab> in <module>()
47 create_using=nx.DiGraph(), nodetype=None, data=[('weight', int)])
48
---> 49 model = SDNE(G, hidden_size=[256, 128],)
50 model.train(batch_size=100, epochs=40, verbose=2)
51 embeddings = model.get_embeddings()

10 frames <ipython-input-19-df29e9865105> in __init__(self, graph,
hidden_size, alpha, beta, nu1, nu2)
72 self.A, self.L = self._create_A_L(
73 self.graph, self.node2idx) # Adj Matrix,L Matrix
---> 74 self.reset_model()
75 self.inputs = [self.A, self.L]
76 self._embeddings = {}

<ipython-input-19-df29e9865105> in reset_model(self, opt)

---> 84 self.model.compile(opt, loss=[l2, l1])
85 self.get_embeddings()
86

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/training/tracking/base.py
in _method_wrapper(self, *args, **kwargs)
455 self._self_setattr_tracking = False # pylint: disable=protected-access
456 try:
--> 457 result = method(self, *args, **kwargs)
458 finally:
459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access

NotImplementedError: Cannot convert a symbolic Tensor (2nd_target:0)
to a numpy array.

请帮忙,谢谢!

最佳答案

对我来说,从 numpy 1.19 升级时出现了问题至1.20并使用 ray的 RLlib,它使用 tensorflow 2.2内部。只需降级

pip install numpy==1.19.5

解决了问题;错误不再发生。

更新(@codeananda 评论):您现在还可以更新到更新的 TensorFlow (2.6+) 版本来解决问题 ( pip install -U tensorflow )。

关于python - 未实现错误: Cannot convert a symbolic Tensor (2nd_target:0) to a numpy array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58479556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com