This guide walks you through the installation of Keras on Ubuntu, including setting up Python, creating a virtual environment, and installing TensorFlow (which includes Keras). It also covers optional GPU support for faster model training, making it an essential resource for deep learning enthusiasts.
10 min
Edited:12-10-2024
To install Keras on Ubuntu, you'll first need to install Python and then install Keras using pip (Python's package installer). Keras is typically installed with TensorFlow, as it's a high-level API for building and training deep learning models that runs on top of TensorFlow.
Before installing any new software, it's a good practice to update your system.
1. sudo apt update && sudo apt upgrade -y
Ensure that you have Python 3.x installed on your system. You can check this by running:
1. python3 --version
If Python is not installed, you can install it with:
1. sudo apt install python3 python3-pip python3-venv -y
It's a good practice to create a virtual environment to isolate your Python packages.
1. python3 -m venv keras-env
2. source keras-env/bin/activate
Keras is included as part of TensorFlow, so you can install TensorFlow to get both.
Run the following command to install TensorFlow (which includes Keras):
1. pip install tensorflow
You can verify the installation of TensorFlow (and Keras) by running:
1. python -c "import tensorflow as tf; print(tf.keras.__version__)"
You can write a simple script to ensure that Keras is installed correctly.
Create a Python file, for example test_keras.py:
1. import tensorflow as tf
2. from tensorflow.keras.models import Sequential
3. from tensorflow.keras.layers import Dense
4.
5. # Create a simple model
6. model = Sequential([
7. Dense(32, activation='relu', input_shape=(784,)),
8. Dense(10, activation='softmax')
9. ])
10.
11. # Print model summary
12. model.summary()
Run the script to ensure everything is working:
1. python test_keras.py
If you have an NVIDIA GPU and want to use it to accelerate your model training, you’ll need to install TensorFlow with GPU support.
Install the necessary NVIDIA drivers and CUDA toolkit. You can follow the instructions on the NVIDIA website.
After installing the CUDA toolkit, install TensorFlow with GPU support:
1. pip install tensorflow-gpu
After following these steps, you should have Keras installed on Ubuntu, either with or without GPU support, depending on your setup. Now you can start building and training deep learning models
14-10-2024
This article offers a detailed guide on installing and configuring IPTables on an Ubuntu VPS. IPTables is a powerful firewall tool that helps secure your server by controlling inbound and outbound traffic. Learn how to set up rules for traffic filtering, configure basic security policies, and apply custom rules to protect your VPS.
IPtables
security
12 min
This article offers a comprehensive guide on installing and configuring ModSecurity, a powerful web application firewall (WAF), on an Ubuntu VPS. Learn how to secure your server by filtering and monitoring HTTP requests, set up ModSecurity with Nginx or Apache, and apply rules to protect against common web attacks.
Modsecurity
security
10 min
14-10-2024
This article provides a comprehensive guide on installing and configuring PHP-FPM (FastCGI Process Manager) on an Ubuntu VPS. Learn how to optimize PHP performance for your web applications by configuring PHP-FPM with Nginx or Apache, managing pools, and fine-tuning settings for efficient processing of PHP scripts.
PHP-FPM
speed
optimise
12 min