import tensorflow as tf
from numpy.random import RandomState
batch_size=8
#定义神经网络的相关参数,无隐藏层
x=tf.placeholder(tf.float32,shape=[None,2],name='x-input')
y_=tf.placeholder(tf.float32,shape=[None,1],name='y-input')
w1=tf.Variable(tf.random_normal([2,1],stddev=1,seed=1))
y=tf.matmul(x,w1)
#设置损失函数
loss_less=10
loss_more=1
loss=tf.reduce_sum(tf.where(tf.greater(y,y_),(y-y_)*loss_more,(y_-y)*loss_less))
train_step=tf
神经网络 Python TensorFlow 自定义损失函数(学习笔记)
最新推荐文章于 2023-08-28 15:53:27 发布