In this project, I sought to use and explore the Python libraries TensorFlow, Numpy, and Matplotlib, and to learn more about training machine learning models.
It's a model trained on the MNIST database of handwritten digits to be able to classify images with their respective number.
Example of training data:
It defines and then uses the functions create_dataset_from_img and create_dataset_from_path to parse the png files to TensorFlow datasets for training and validation.
The code then flattens the (28,28,3) matrixes to (28,28,1) since having multiple color channels is irrelevant in greyscale images.\
We then define the model archictecture
Following that we train it to the data then test it on data that it wasn't trained on.
Plot of validation accuracy and validation loss per epoch
Tested on windows 10 and nvidia GPU.
Install anaconda https://www.anaconda.com/products/distribution
Check tenserflow for latest gpu version https://www.tensorflow.org/install/source#gpu
Download Microsoft Visual Studio (no need for any workflows). Might be a good idea to install the older version so its compatible or check https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html for suported versions.
Install the correct version of the cuda toolkit according to the TensorFlow version. https://developer.nvidia.com/cuda-toolkit-archive
Download the correct CuDNN according to the TensorFlow version. https://developer.nvidia.com/cudnn
Extract the CuDNN zip, go to the path C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0
and paste the zip's content in there.
Add these to the path variable.
On the anaconda prompt (admin)
conda create --name tf_2.7 python==3.9
Replace the versions accordingly.
pip install --upgrade pip
pip install TensorFlow
In the Jupyter shortcut go to properties and change target to this
C:\Users\USERNAME\anaconda3\python.exe C:\Users\Gustavo\anaconda3\cwp.py C:\Users\USERNAME\anaconda3 C:\Users\USERNAME\anaconda3\python.exe C:\Users\USERNAME\anaconda3\Scripts\jupyter-notebook-script.py "D:\AI_Projects"
, aka replace %USERPROFILE% with the intended startup path.
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
Should return 1 gpu available.
To change theme do this and restart the notebook.
pip install jupyterthemes
jt -l
jt -t gruvboxd
On PyCharm create a project using the anaconda interpreter on the desired dir.
Set the server to the url given in the Jupyter terminal.
If it warns that the kernel of the newly configured server doesn't match your current Python interpreter just "register project interpreter as kernel".
If it gives error like ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.
copy sqlite3.dll from C:\Users\USERNAME\anaconda3\Library\bin
to C:\Users\USERNAME\anaconda3\DLLs
.