代码:
#author@chengxiaona
import tensorflow as tf
import numpy as np
#输入训练数据,这里是python的list, 也可以定义为numpy的ndarray
x_data = [[1., 0.], [0., 1.], [0., 0.], [1., 1.]]
#定义占位符,占位符在运行图的时候必须feed数据
x = tf.placeholder(tf.float32, shape = [None, 2])
#训练数据的标签,注意维度
y_data = [[1], [1], [0], [0]]
y = tf.placeholder(tf.float32, shape = [None, 1])
#定义variables,在运行图的过程中会被按照优化目标改变和保存
weights = {
'w1': tf.Variable(tf.random_normal([2, 16])), 'w2': tf.Variable(tf.random_normal([16, 1]))}
bias = {
'b1': tf.Variable(tf.zeros([1])), 'b2': tf.Variable(tf.zeros([1]))}
#定义对于节点的操作函数