Out of the Box Jupyter with Deep Learning Libraries: Part II

Jupyter Container Application: Scene Classification (with CPU & GPU container versions)

Run a pre-trained model using the CPU container:

We used the “datamachines/jupyter_to” container (described in blog post #1 of this series) to train and deploy a scene classification model. Our goal was to use a machine learning model to be able to remotely identify various landscapes. This was a key component in training an RL agent for autonomous navigation, which would bias certain strategies based on the detected landscape, or scene.

We used MIT CSAIL’s Places365 library of data and model architectures to train, using PyTorch, a neural network to perform scene classification. The Places365 dataset is an image dataset of 365 different scenes, including both indoor and outdoor scenes. We took a subset of the data to include only 49 outdoor scenes, which were relevant to our application.

We’ve put a pre-trained ResNet model, the code to run it on a single image, and the code used to train a new model in a GitHub repository

In the first blog post of this container series, we described how to build the jupyter_to container. To leverage the PyTorch library used in the scene classifier code, you’ll want to run the jupyter_to container in the same directory as the code. 

Once you’ve started the container using the docker run command, it will create a link that will enable you to access Jupyter from your local host. Paste the link in your browser and you’ll be accessing Jupyter from inside the container. From there, you can test the pre-trained model by running the testing script against a single image. 

python run.py <test image> --num_classes 49

Train a model using the GPU container:

We have also extended this project to be able to develop on CPU and port to GPU. We created a GPU version of the container, called datamachines/jupyter_cto, referring to CUDA, TensorFlow, and OpenCV. This container provides GPU compiled versions of TensorFlow, OpenCV, Keras and PyTorch, as well as NumPy and pandas, all from within the Jupyter Notebook. This is extremely useful, because to train your own scene classification model you will benefit from the massive parallelism brought in by the use of CUDA in PyTorch. 

To start this container you will need to check the version of CUDA your GPU driver can run in reference to the container tag. For example, the tag

11.3.1_2.8.0_4.5.5-20220318 

refers to CUDA 11.3.1. If the version of your Nvidia driver supports at least this version of CUDA, you can use the docker pull command to build the container. This can be checked using the nvidia-smi command and checking the “CUDA Version:” field on the first line. For example “NVIDIA-SMI 510.73.05    Driver Version: 510.73.05    CUDA Version: 11.6” indicates that the Linux host is running driver 510.73.05 with support up to CUDA 11.6.

If you have more than one GPU available, you can specify the one to use by  adding

–-gpus device=0 

to the command line, replacing the number by the ID you obtained from nvidia-smi to specify which GPUs you want to run this container on.

For example,

docker run -v `pwd`:/dmc --rm --gpus device=1 -p 8888:8888 --shm-size=2gb datamachines/jupyter_cto:11.3.1_2.8.0_4.5.5-20220318

Before running the container, you will need to add your dataset to the same directory as the code. We’ve added a Makefile to download the outdoor scene classes dataset we used to train the model provided. Run

make get_data 

to download the dataset into your local directory. 

Now, when you run the GPU container inside of the same directory as the image dataset and the scene-classifier repository, all of the code and data will be accessible from inside the container. Using the docker run command to generate a Jupyter URL, you can access Jupyter from your browser. Finally, you can open a Jupyter terminal or notebook and run the training script against the data to generate your own trained model.

We invite you to follow the instructions on the Github page for further instructions on how to set up and use the tool.

To run on a remote host (via FoxyProxy using SOCKS5 over ssh):

Maybe you don’t have a display for your GPU, such as a GPU laptop, but you do have a GPU server remotely accessible. You can still open a Jupyter notebook using the FoxyProxy Firefox extension. Simply install the extension and add a newSOCKS5 proxy on localhost and using an assigned port, here 1337. Title it something that will help you remember it, such as “localhost SOCKS5 over ssh”.

Now, when you go to ssh into the remote GPU, use the port number assigned

(i.e. ssh -D 1337 -q user@host) 

The assigned port will enable you to access your Jupyter container from your Firefox browser on your local host. Simply start up the container as you normally would, and paste the link to access the notebook in your browser. 

We have now successfully built and ran a Jupyter-enabled deep learning container, tested a neural network on a classification task, and learned how to train our own model from scratch leveraging remote GPUs!

Previous
Previous

DMC Attends the 2022 Special Operations Forces Industry Conference

Next
Next

DMC Presents at the UNCW and Defense Alliance Science and Technology Forum