So, I have decided to take the #100DaysOfCode challenge and adapt it to deep learning.
During the next days, I will explore Tensorflow for at least 1 hour per day and post the notebooks, data and models to this repository.
For this first day challenge, I will setup a new clean virtual environment using Anaconda dedicated only to this project.
So, let’s start:
Step 1: Install Anaconda
Go to Anaconda’s site and follow the instructions.
Step 2: Create the environment
I am using Mac, so, I will talk a lot about Terminal.
I will create a new environment called 100daystf running Python 3.7. To do the same, type the following command on Terminal and type “y” when Anaconda requests the confirmation for the install.
(Don’t include the “$” sign).
$ conda create -n 100daystf python=3.7
Then, activate your new environment using
$ conda activate 100daystf
Step 3: Install the packages
When you create a new environment this way, it will be almost clean. It’s important to instal the packages we’ll be using. At least the basics one.
I have prepared a file called requirements.txt. It’s located on the repository and it will be updated every time we need to add a new package.
Get this file (or clone the repository) and place it on your computer. Then, using Terminal, navigate to the place where you saved it and and type:
$ pip install -r requirements.txt
When you are done, type the following command to see if Tensorflow was correctly installed:
$ python -c 'import tensorflow as tf; print(tf.__version__)'
Step 4: Testing a basic network
I am not exactly new to Tensorflow, so I had a few notebooks created before. In order to test if our install is working, I will reuse this project, which is also a very basic introduction to Tensorflow.
⚠️ Since the goal of this project is to develop a strong basis on this framework, I will do a lot of basic stuff in the next days.
I made a few changes to this project. The updated notebook for this project is here:
- I added tf.keras.callbacks.ModelCheckpoint to save the weights of the trained model
- The model is saved on the repository, on the models/day1 directory.
- I am loading the weights before making the predictions to test if the model is being loaded correctly.
Step 5: Export the new enviroment to a yml file
Conda gives you the ability to export an environment to a .yml file. This is useful if you want to redistribute the environment.
To do it, make sure you have activated your recently created environment, navigate to the directory where you want to export the file and type:
$ conda env export > 100daystf.yml
To install and environment using this file, type
$ conda env create -f 100daystf.yml
Conclusion: what we learned today
- How to create a clean environment
- How to install the libraries using requirements.txt
- How to check Tensorflow version
- How to check if the environment is working using a notebook
- How to build a very basic model
- How to save the model weights
- How to load the model weights
- How to export an environment
- How to install an environment from a yml file
Do you want to connect? It will be a pleasure to discuss Machine Learning with you. Drop me a message on LinkedIn.