Skip to content
This repository has been archived by the owner on Sep 5, 2021. It is now read-only.

Latest commit

 

History

History
58 lines (47 loc) · 1.31 KB

18-Day7.md

File metadata and controls

58 lines (47 loc) · 1.31 KB

BDMI --第七周学习小结

赵子瑜

本周课程的主要内容有:

  1. 即刻执行

    C,Java,Python都用了即刻求值.

    tensorflow2 默认使用了eager execution

  2. 模型的训练与评估

    训练数据的加载:

    (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
    x_train = x_train.reshape(60000, 784).astype('float32') / 255
    x_test = x_test.reshape(10000, 784).astype('float32') / 255
    

    模型的构造:

    inputs = keras.Input(shape=(784,), name="digits")
    x = layers.Dense(512, activation="relu", name="dense_1")(inputs)
    x = layers.Dense(128, activation="relu", name="dense_2")(x)
    outputs = layers.Dense(10, activation="softmax", name="predictions")(x)
    model = keras.Model(inputs=inputs, outputs=outputs)
    

    编译:

    model.compile(
        optimizer="adam",
        loss="sparse_categorical_crossentropy",
        metrics=["sparse_categorical_accuracy"],
    )
    

    训练模型:

    history = model.fit(
       x_train,
        y_train,
        batch_size=1024,
        epochs=10,
        validation_data=(x_val, y_val),
    )