Keras 是一个高级神经网络 API,专为用户友好性和模块化设计,可无缝运行在 TensorFlow 上。以下是快速上手的核心要点:

🚀 快速入门

  1. 安装依赖
    pip install tensorflow
    
  2. 基础结构
    import tensorflow as tf
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import Dense
    
    model = Sequential([
        Dense(64, activation='relu', input_shape=(32,)),
        Dense(64, activation='relu'),
        Dense(10, activation='softmax')
    ])
    model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
    
  3. 数据训练
    使用内置数据集或自定义数据进行训练,例如:
    mnist = tf.keras.datasets.mnist.load_data()
    (x_train, y_train), (x_test, y_test) = mnist
    

📚 扩展学习

Keras_Introduction
TensorFlow_Logo