张量张量张量值未分配
我正在使用以下自定义损失函数: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论