Welcome to the TensorFlow introduction! 🚀
TensorFlow is an open-source library for machine learning and deep learning developed by Google. It allows you to create complex neural networks and train models efficiently. Let's dive into the basics!
Getting Started 📦
Install TensorFlow
- Use pip:
pip install tensorflow
- Or download from TensorFlow official website 🌐
- Use pip:
Verify Installation
Run a simple script to check if TensorFlow is working correctly:import tensorflow as tf print(tf.__version__)
Core Concepts 🧠
- Tensors: The fundamental data structure in TensorFlow, similar to arrays or matrices.
- Graphs: Represent computations as a series of operations (nodes) and data (edges).
- Sessions: Execute the graph and manage resources.
Example Code 📜
Here's a basic example using TensorFlow to train a model on the MNIST dataset:
import tensorflow as tf
from tensorflow.keras import layers, models
# Load and preprocess data
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train = x_train.reshape(-1, 28*28).astype('float32')/255
x_test = x_test.reshape(-1, 28*28).astype('float32')/255
# Build model
model = models.Sequential([
layers.Dense(512, activation='relu', input_shape=(28*28,)),
layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Train model
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)
Expand Your Knowledge 📘
For deeper insights, check out our TensorFlow Advanced Tutorial or explore Keras documentation.