Adding useful script and modifying instructions

This commit is contained in:
2026-03-10 20:20:24 -04:00
parent 417295dd05
commit 1fbb16df15
2 changed files with 77 additions and 3 deletions

View File

@@ -9,9 +9,16 @@ import matplotlib.pyplot as plt
# This is the new 2026 version
# This model was trained with 13,185 images
# See CNNImageProcessor solution for create the test images for training this model
# See CNNImageProcessor solution for creating the test images for training this model
# **************************************** I M P O R T A N T ********************************************************
# Train the model on EUPORIE laptop using the GPU card with WSL2. (Windows Subsystem For Linux). I am running Ubuntu1 22.04.2
# To launch WSL open up a command prompt, run powershell and type "wsl".
# The folder structure will be /home/pi/CNN.
# You can access the folder structure through windows explorer. type "\\wsl$" in explorer and navigate to the folder.
# drop in the Data and Model and run the model
# There is a shell script in the Scripts folder. setup_tf_gpu.sh Copy teh script to the CNN folder and run it. It will
# create the venv enviroment and install python 3.10 and tensorflow (gpu)
# ********************************************************************************************************************
# Figure out if we are training in CPU or GPU
print("GPUs:", tf.config.list_physical_devices('GPU'))

67
Scripts/setup_tf_gpu.sh Normal file
View File

@@ -0,0 +1,67 @@
#!/bin/bash
set -e
echo "====================================="
echo "TensorFlow GPU WSL Setup Script"
echo "====================================="
PROJECT_DIR="$HOME/CNN"
VENV_NAME="tf_gpu"
echo "Updating system packages..."
sudo apt update
sudo apt install -y python3.10 python3.10-venv python3-pip
echo ""
echo "Creating project directory if needed..."
mkdir -p $PROJECT_DIR
cd $PROJECT_DIR
echo ""
echo "Creating Python virtual environment..."
python3.10 -m venv $VENV_NAME
echo ""
echo "Activating virtual environment..."
source $VENV_NAME/bin/activate
echo ""
echo "Upgrading pip..."
pip install --upgrade pip
echo ""
echo "Installing TensorFlow GPU build..."
pip install tensorflow[and-cuda]==2.19
echo ""
echo "Adding recommended TensorFlow environment variables..."
BASHRC="$HOME/.bashrc"
if ! grep -q TF_FORCE_GPU_ALLOW_GROWTH $BASHRC; then
echo "" >> $BASHRC
echo "# TensorFlow GPU settings" >> $BASHRC
echo "export TF_FORCE_GPU_ALLOW_GROWTH=true" >> $BASHRC
echo "export TF_CPP_MIN_LOG_LEVEL=2" >> $BASHRC
fi
echo ""
echo "Testing TensorFlow GPU detection..."
python <<EOF
import tensorflow as tf
print("TensorFlow version:", tf.__version__)
print("GPUs detected:", tf.config.list_physical_devices('GPU'))
EOF
echo ""
echo "====================================="
echo "Setup complete"
echo "====================================="
echo ""
echo "To activate the environment later:"
echo ""
echo "cd ~/CNN"
echo "source venv/bin/activate"