tensor_flow官网上的教程链接:
https://tensorflow.google.cn/guide/keras/sequential_model
这里教了最基本的全链接Dense,其中tensor的shape需要弄清楚,可以使用tensor.get_shape()来获取形状。
layer1 = layers.Dense(2)
x = tf.ones((1, 4))
y = layer1(x)
layer1.weights # Now it has weights, of shape (4, 3) and (3,)
[<tf.Variable 'dense_9/kernel:0' shape=(4, 2) dtype=float32, numpy=
array([[ 0.16653562, 0.9739351 ],
[ 0.54127383, 0.7828257 ],
[-0.5645373 , -0.555321 ],
[ 0.17373228, 0.43521905]], dtype=float32)>,
<tf.Variable 'dense_9/bias:0' shape=(2,) dtype=float32, numpy=array([0., 0.], dtype=float32)>]
print(x)
print(y)
tf.