0% found this document useful (0 votes)
22 views4 pages

Week 2

The document provides a comprehensive guide for setting up TensorFlow, including installation instructions for both CPU and GPU versions, as well as Keras integration. It details the necessary components and steps for installation, including creating a virtual environment and verifying GPU setup. Additionally, it briefly mentions other deep learning libraries like Caffe and Theano for awareness, noting their historical significance and installation commands.

Uploaded by

dipanwita.d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Week 2

The document provides a comprehensive guide for setting up TensorFlow, including installation instructions for both CPU and GPU versions, as well as Keras integration. It details the necessary components and steps for installation, including creating a virtual environment and verifying GPU setup. Additionally, it briefly mentions other deep learning libraries like Caffe and Theano for awareness, noting their historical significance and installation commands.

Uploaded by

dipanwita.d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Week 2:

i Setup of TensorFlow, TensorFlow with GPU support.

TensorFlow is an open-source deep learning framework developed by


Google. It allows building and training machine learning and deep learning
models in a flexible and scalable way.

Installation of TensorFlow (CPU Version)


Step-by-Step Guide:
➤ Step 1: Install Python

Recommended: Python 3.8 to 3.11

Download from: https://www.python.org/downloads/

➤ Step 2: Create a Virtual Environment

python -m venv tf_env

➤ Step 3: Activate the Environment

Windows:

.\tf_env\Scripts\activate

Linux/macOS:

source tf_env/bin/activate

➤ Step 4: Install TensorFlow (CPU version)

pip install tensorflow

Installation of TensorFlow with GPU Support

Component Version Requirement


Python 3.8–3.11
TensorFlow 2.12.0 or later
CUDA Toolkit 11.8 (for TF 2.12), or 12.2+ for TF 2.15+
cuDNN 8.6 or 8.9
NVIDIA GPU With compute capability ≥ 3.5 (e.g., GTX 10xx, RTX)
NVIDIA Driver Compatible with your CUDA version

Step-by-Step GPU Setup (Windows/Linux)


➤ Step 1: Install Python and Virtual Environment
(Same as above)
➤ Step 2: Install GPU-compatible TensorFlow

pip install tensorflow

Since TensorFlow 2.11+, GPU support is included in tensorflow package (no need for tensorflow-
gpu separately).

➤ Step 3: Install CUDA Toolkit and cuDNN


🟢 Option A: Use NVIDIA CUDA Installer

Install CUDA 11.8:


https://developer.nvidia.com/cuda-11-8-0-download-archive

Install cuDNN 8.6:


https://developer.nvidia.com/rdp/cudnn-archive

✅ Add these to Environment Variables:

CUDA_HOME

Add to PATH:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin

...\CUDA\v11.8\libnvvp

🟢 Option B: Use conda for Simpler Setup

conda create -n tf_gpu python=3.10


conda activate tf_gpu
conda install -c nvidia cuda-toolkit=11.8 cudnn=8.6
pip install tensorflow

✅ 4. Verify GPU Setup


Run the following script:

import tensorflow as tf
print("TensorFlow version:", tf.__version__)
print("Num GPUs Available:", len(tf.config.list_physical_devices('GPU')))

You should see:

TensorFlow version: 2.12.0


Num GPUs Available: 1

ii Setup to Keras.
Keras is a high-level API for building and training deep learning models.
Originally developed as an independent library, Keras is now tightly
integrated into TensorFlow as tf.keras.
Keras Installation
🔹 Step-by-Step:

Keras is included with TensorFlow (since TF 2.0+), so you don't need to


install it separately.
✅ To install:

pip install tensorflow

This will install tensorflow along with tf.keras.

✅ 2. Importing and Using Keras

You should always use tf.keras, not the old standalone keras:

from tensorflow import keras


from tensorflow.keras import layers

✅ 3. Basic Keras Workflow


🔷 Step 1: Build the Model

model = keras.Sequential([
layers.Dense(128, activation='relu', input_shape=(784,)),
layers.Dense(10, activation='softmax')
])

🔷 Step 2: Compile the Model

model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

🔷 Step 3: Train the Model

model.fit(x_train, y_train, epochs=5, batch_size=32)

🔷 Step 4: Evaluate

model.evaluate(x_test, y_test)

iii Learning the other deep learning libraries like Caffe,


Theano, etc.
These are not actively maintained for new projects but are useful for understanding legacy
systems and framework design.

🔸 Caffe (Convolutional Architecture for Fast Feature Embedding)

Written in C++

Developed by Berkeley AI Research

Pretrained models available

Installation (Linux):

sudo apt install caffe-cpu

Documentation: https://caffe.berkeleyvision.org/

Theano

Python library for defining, optimizing, and evaluating mathematical expressions

Was foundational to many other libraries (e.g., Keras originally used Theano)

pip install Theano

import theano
print(theano.config.device)

🔸 Other Libraries (for awareness):


Library Notes
PyTorch Widely used in academia and research
MXNet Backed by Apache; used by AWS
CNTK Microsoft Cognitive Toolkit
JAX High-performance computing; by Google

You might also like