DAY 22
0

## [第22天] Tensorflow 練習５

``````def add_layer(inputs, in_size, out_size, activation_function=None):
Weights = tf.Variable(tf.random_normal([in_size, out_size]))
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1)
Wx_plus_b = tf.matmul(inputs, Weights) + biases
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs

``````

y_out = x_in * W + b

``````hidden_layer = add_layer(input, input_tensors = 4, output_tensors = 6, activation_function = None)
``````

biases最好不要用0就設0.1，因為y_out維度是(1,6)因此in_size=1,out_size=6然後再把整個０向量+0.1，幾本上把它想成線性代數的就可以把結構定義出來。因此我們有

``````biases = tf.Variable(tf.zeros([1, out_size]) + 0.1)
``````

``````Wx_plus_b = tf.matmul(inputs, Weights) + biases  # tf.matmul是矩陣乘法
``````

``````output_layer = add_layer(hidden_layer, input_tensors = 6, output_tensors = 3, activation_function = None)
``````

``````if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
return outputs
``````