TensorFlow 是一个开源的机器学习框架,由 Google Brain 团队开发。它广泛应用于各种机器学习任务,包括深度学习。以下是 TensorFlow 的基本教程。

安装 TensorFlow

首先,您需要安装 TensorFlow。根据您的操作系统,请访问 TensorFlow 官方安装指南 了解如何进行安装。

快速开始

  1. 导入 TensorFlow 库

    import tensorflow as tf
    
  2. 创建一个简单的模型

    model = tf.keras.Sequential([
        tf.keras.layers.Dense(10, activation='relu', input_shape=(32,)),
        tf.keras.layers.Dense(1, activation='sigmoid')
    ])
    
  3. 编译模型

    model.compile(optimizer='adam',
                  loss='binary_crossentropy',
                  metrics=['accuracy'])
    
  4. 训练模型

    model.fit(x_train, y_train, epochs=5)
    
  5. 评估模型

    model.evaluate(x_test, y_test)
    
  6. 使用模型进行预测

    predictions = model.predict(x_test)
    

更多资源

TensorFlow Logo