layers介紹

Flatten和Dense介紹

優化器

損失函數

compile用法

第二個是onehot編碼

模型訓練 model.fit

兩種創建模型的方法
from tensorflow.python.keras.preprocessing.image import load_img,img_to_array
from tensorflow.python.keras.models import Sequential,Model
from tensorflow.python.keras.layers import Dense,Flatten,Input
import tensorflow as tf
from tensorflow.python.keras.losses import sparse_categorical_crossentropy
def main():
#通過Sequential創建網絡
model = Sequential(
[
Flatten(input_shape=(28,28)),
Dense(64,activation=tf.nn.relu),
Dense(128,activation=tf.nn.relu),
Dense(10,activation=tf.nn.softmax)
]
)
print(model)
#通過Model創建模型
data = Input(shape=(784,))
out = Dense(64)(data)
model_sec = Model(inputs=data,outputs=out)
print(model_sec)
print(model.layers,model_sec.layers)
print(model.input,model.output)
print(model.summary())
print(model_sec.summary())
if __name__ == '__main__':
main()
