您的位置:首页 > 其它

AttributeError: module 'tensorflow' has no attribute 'select'

2017-12-22 16:57 661 查看
# p79自定义损失函数import tensorflow as tffrom numpy.random import RandomStatebatch_size = 8x = 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 = 10loss_more = 1loss = tf.reduce_sum(tf.select(tf.greater(y_,y), (y-y_) * loss_more, (y_-y) * loss_less))train_step = tf.train_AdamOptimizer(0.001).minimize(loss)rdm = RandomState(1)dataset_size = 128X = rdm.rand(dataset_size,2)Y = [[x1+x2+rdm.rand()/10.0-0.05] for (x1,x2) in X]with tf.Session() as sess:    init_op = tf.initialize_all_variables()    sess.run(init_op)    STEP = 5000    for i in range(STEP):        start = (i * batch_size) % dataset_size        end = min(start+batch_size, dataset_size)        sess.run(train_step, feed_dict = {x:X[start:end], y:Y[start:end]})        print(sess.run(w1))AttributeError: module 'tensorflow' has no attribute 'select'tf.select ——>tf.where

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: