张量张量张量值未分配

发布于 2025-01-31 06:37:41 字数 693 浏览 2 评论 0原文

我正在使用以下自定义损失函数:
model.compile(lose = custom_loss,...)
自定义损失函数定义为:

def custom_loss(y_actual,y_pred):
    custom_loss = loss_function(y_actual,y_pred) + penalty * quantizer.model_size()
    return custom_loss

其中Qualtizer是类的对象,model_size()是此类的一种方法。在此model_size()方法中,我正在尝试创建一些具有一些初始值的张量变量。但是似乎没有分配值。我正在使用打印(tf.constant(1.0,dtype = float))) and print(tf.variable(1.0,dtype = float))查看张量输出就像张量(“ custom_loss/const:0”,shape =(),dtype = float32) and code>< tf.variable'custic_loss/varible/variable/varible:0'shape =( )dtype = float32> 。是什么原因导致这个问题?

I'm using a custom loss function as below:
model.compile(loss=custom_loss,...)

And the custom loss function is defined as:

def custom_loss(y_actual,y_pred):
    custom_loss = loss_function(y_actual,y_pred) + penalty * quantizer.model_size()
    return custom_loss

where quantizer is a object of a class and model_size() is a method of this class. In this model_size() method, I'm trying to create some tensors variable with some initial value. But it seems like the value is not assigned. I'm printing using print(tf.constant(1.0, dtype=float)) and print(tf.Variable(1.0, dtype=float)) to see the tensors and the output is like Tensor("custom_loss/Const:0", shape=(), dtype=float32) and <tf.Variable 'custom_loss/Variable:0' shape=() dtype=float32>. What causes this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文