美文网首页
训练和评估(03)

训练和评估(03)

作者: YX_Andrew | 来源:发表于2019-02-09 12:03 被阅读0次

    设置训练流程

    构建好模型后,通过调用 compile 方法配置该模型的学习流程:

    model = tf.keras.Sequential([
    # Adds a densely-connected layer with 64 units to the model:
    layers.Dense(64, activation='relu'),
    # Add another:
    layers.Dense(64, activation='relu'),
    # Add a softmax layer with 10 output units:
    layers.Dense(10, activation='softmax')])
    
    model.compile(optimizer=tf.train.AdamOptimizer(0.001),
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])
    

    tf.keras.Model.compile 采用三个重要参数:

    以下代码展示了配置模型以进行训练的几个示例:

    # Configure a model for mean-squared error regression.
    model.compile(optimizer=tf.train.AdamOptimizer(0.01),
                  loss='mse',       # mean squared error
                  metrics=['mae'])  # mean absolute error
    
    # Configure a model for categorical classification.
    model.compile(optimizer=tf.train.RMSPropOptimizer(0.01),
                  loss=tf.keras.losses.categorical_crossentropy,
                  metrics=[tf.keras.metrics.categorical_accuracy])
    

    相关文章

      网友评论

          本文标题:训练和评估(03)

          本文链接:https://www.haomeiwen.com/subject/vbiasqtx.html