- Basics of Deep Learning in Computer Vision
-
Install VSCode
-
Install VSCode extensions from PowerShell
code --install-extension ms-python.python code --install-extension ms-python.vscode-pylance code --install-extension ms-toolsai.jupyter code --install-extension ms-toolsai.jupyter-renderers code --install-extension ms-vscode-remote.vscode-remote-extensionpack
-
Install WSL(Ubuntu) from an adminstrator PowerShell
wsl --install
You need to reboot your computer during the installation, and then set a username and password for WSL.
-
Install packages in Ubuntu
Right click mouse to paste contents in WSL.
sudo apt-get update sudo apt-get install wget ca-certificates curl
You would be asked for a passowrd.
-
Install pyenv in Ubuntu
curl https://pyenv.run | bash -
Add environment variables
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init -)"' >> ~/.bashrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc exec $SHELL
-
Lauch Terminal
-
Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -
Install packages
brew install wget git pyenv pyenv-virtualenv
-
Add environment variables
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile echo 'eval "$(pyenv init -)"' >> ~/.zprofile echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zprofile exec $SHELL
If your MacOS < 10.15, replace
.zprofilewith.bash_profile. -
Install VSCode and extensions
brew install --cask visual-studio-code code --install-extension ms-python.python code --install-extension ms-python.vscode-pylance code --install-extension ms-toolsai.jupyter code --install-extension ms-toolsai.jupyter-renderers code --install-extension ms-vscode-remote.vscode-remote-extensionpack
-
Create the project folder
mkdir -p ~/Projects cd ~/Projects
-
Clone the lecture project
git clone https://github.com/hinson/DLCVLecture cd DLCVLecture -
Create the python environment
pyenv install mambaforge pyenv local mambaforge mamba env create -f env-cpu.yml -
Activate the python environment (named
dlcvl)conda activate dlcvl
If you want to deactivate, use
conda deactivate
-
Open the project with VSCode
code DLCVLecture.code-workspace
Please trust the author 😊.
-
Create your RSA key pair from an adminstrator PowerShell in Windows or Terminal in MacOS
ssh-keygen
Press
enterif you are prompted. -
Copy your public key
cat ~/.ssh/id_rsa.pub # copy the entire output
-
Login to a remote GPU server
ssh {username}@{server IP} # replace the placeholdersInput your password. Input
yesif the machine ask for your confirmation.If you want to change the password, use
passwd
-
Paste the public key to the remote server
mkdir -p ~/.ssh && vim ~/.ssh/authorized_keys
Paste the copied content to the end of the file and save (press
shift+g, presso, paste, pressesc, input:wq). -
Login the remote server without password
exit ssh {username}@{server IP} #
If the server does not ask for a password, then all is well.
-
Set up the project
curl https://pyenv.run | bash echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init -)"' >> ~/.bashrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc exec $SHELL
mkdir -p ~/Projects cd ~/Projects #
git clone https://github.com/hinson/DLCVLecture cd DLCVLecture #
-
Setup
pyenv install mambaforge pyenv local mambaforge mamba env create -f env-gpu.yml conda activate dlcvl #
-
Launch a Jupyter server
jupyter notebook --no-browser --ip={server IP} --port={your port} #The output will be like this:
... http://{server IP}:{your port}/?token={your token} ...Open this url in your browser.
{your token}will change every time you lanch jupyter.
The above commands with # are required every time you re-login to the remote server. Summarize as
ssh {username}@{server IP}
cd ~/Projects/DLCVLecture
conda activate dlcvl- From menu,
File->Open Workspace from File, select{your home}/Projects/DLCVLecture/DLCVLecture.code-workspace - Check if the project files are shown in
VSCode Exploreron the left.
- From
VSCode Explorer, openDLCVLecture/python/test.py - click
Python {version}in the lower left corner - Select
Select at workspace level - Select the version with
(dlcvl) - Prest
ctrl+F5to runtest.py.
- Launch VSCode
- Press
F1, inputjusplr, selectJupyter: Specify local or remote Jupyter server for connections - Select
Existing - Paste the above jupyter url and press
enter
See Jupyter Notebooks in VS Code for more details.
- From
VSCode Explorer, openDLCVLecture/notebooks/test.ipynb - Click
Select Kernelin the upper right corner - Select the one with
/home/{username}/...(Remote)... - Click the right Play button or use
shift+enterto execute the code in the first cell.
If you want to close remote Jupyter, press ctrl + c in the remote session.
In both your local and remote project folders, run the following command to update the materials.
cd ~/Projects/DLCVLecture
git fetch && git reset --hard origin/masterIf you want to overwrite a specific file:
cd ~/Projects/DLCVLecture
git fetch && git checkout origin/master {relative path} # eg. git checkout origin/master Readme.mdFollow 2.2 to login to the remote server, then
cd python/example
mlflow ui --backend-store-uri sqlite:///mlflow.db --host 0.0.0.0 --port {your port} There will be a new sqlite db file mlflow.db to store experimental data in ~/Projects/DLCVLecture/python/example. If you want to use other databases, see MLflow Tracking.
Then visit {server IP}:{your port} in a browser.
Open a new terminal and repeat 2.2, then
export MLFLOW_TRACKING_URI=http://{server IP}:{your port}If you do not export the above evironment variable, the following mlflow commands will use the default tracking URI http://localhost:5000.
cd python/example- To run the default entry point
main:
mlflow run . --no-conda --experiment-name MNIST The --no-conda flag is to avoid creating dlcvl environment repeatedly.
According to the MLproject file, we can set max_epochs and batch_size like:
mlflow run . --no-conda --experiment-name MNIST -P max_epochs=5 -P batch_size=128 - To run the
grid searchentry point:
mlflow run . --no-conda --experiment-name MNIST_gs -e gridtensorboard --host 0.0.0.0 --port {your port} --logdir {lightning log path}Then visit {server IP}:{your port} in a browser.
model = MNISTClassifier.load_from_checkpoint({some pl. checkpoint path})See Saveing and Loading Weights (Lightning) for details.
Because pl.LightningModule is a subclass of torch.nn.Module, you can also load a state dict saved by pl.LightningModule to a torch.nn.Module model when they have the same layer definitions.
For example, you can use the CNN class defined in notebook/process 3.1:
model = CNN()
ckpt = torch.load({some pl. checkpoint path})
model.load_state_dict(ckpt["state_dict"])More about state dict, see Saving and Loading Models (PyTorch).