[英]Custom cost function for tensorflow
Is there any way I can have this custom cost for my op in Tensorflow? 有什么办法可以在Tensorflow中为我的操作收取定制费用?
n_step =5
for i in range(0,int(train_size/n_step)):
W=[0]
I=[0]
for j in range(n_step):
W.append(max(W[j]+train_y[i*n_step+j]-yhat[i*n_step+j],0))
I.append(max(-W[j]-train_y[i*n_step+j]+yhat[i*n_step+j],0))
loss += 2*np.sum(W)+1*np.sum(I)
where yhat
is the output of a fully connected network and W
, I
are auxiliaries. 其中
yhat
是完全连接的网络和输出W
, I
是助剂。
Yes, you just have to add your loss
to the collection of losses with tf.losses.add_loss . 是的,您只需使用tf.losses.add_loss将您的
loss
添加到损失集合中。
In order for you to be able to do that, you have to express your loss function in terms of tensors and tensor operations, however. 为了使您能够做到这一点,您必须用张量和张量运算来表达损失函数。 Numpy operations as in your code will not do.
如代码中的Numpy操作将无法执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.