Convolutional Neural Networks for Visual Recognition
Stanford - Spring 2023
These are my solutions for the CS231n course assignments offered by Stanford University (Spring 2023). Inline questions are explained, the code is brief and commented (see examples below).
- Course page
- Assignments
- Lecture notes
- Lecture videos
English (2017) Korean (DSBA)
- Q1: k-Nearest Neighbor classifier
- Q2: Training a Support Vector Machine
- Q3: Implement a Softmax classifier
- Q4: Two-Layer Neural Network
- Q5: Higher Level Representations: Image Features
- Q1: Fully-connected Neural Network
- Q2: Batch Normalization
- Q3: Dropout
- Q4: Convolutional Networks
- Q5 option 1: PyTorch on CIFAR-10
- Q5 option 2: TensorFlow on CIFAR-10
- Q1: Image Captioning with Vanilla RNNs
- Q2: Image Captioning with Transformers
- Q3: Network Visualization: Saliency Maps, Class Visualization, and Fooling Images
- Q4: Generative Adversarial Networks
- Q5: Self-Supervised Learning for Image Classification
- Q6: Image Captioning with LSTMs
It is advised to run in Colab, however, you can also run locally. To do so, first, set up your environment - either through conda or venv. It is advised to install PyTorch in advance with GPU acceleration. Then, follow the steps:
- Install the required packages:
pip install -r requirements.txt
- Change every first code cell in
.ipynb
files to:%cd cs231n/datasets/ !bash get_datasets.sh %cd ../../
- Change the first code cell in section Fast Layers in ConvolutionalNetworks.ipynb to:
%cd cs231n !python setup.py build_ext --inplace %cd ..
I've gathered all the requirements for all 3 assignments into one file requirements.txt so there is no need to additionally install the requirements specified under each assignment folder. If you plan to complete TensorFlow.ipynb, then you also need to additionally install Tensorflow.
Note: to use MPS acceleration via Apple M1, see the comment in #4.
In basic, assignments work in colab. But I worked in local environment.
Original code (colab)
# This mounts your Google Drive to the Colab VM.
from google.colab import drive
drive.mount('/content/drive')
# TODO: Enter the foldername in your Drive where you have saved the unzipped
# assignment folder, e.g. 'cs231n/assignments/assignment2/'
FOLDERNAME = None
assert FOLDERNAME is not None, "[!] Enter the foldername."
# Now that we've mounted your Drive, this ensures that
# the Python interpreter of the Colab VM can load
# python files from within it.
import sys
sys.path.append('/content/drive/My Drive/{}'.format(FOLDERNAME))
# This downloads the CIFAR-10 dataset to your Drive
# if it doesn't already exist.
%cd /content/drive/My\ Drive/$FOLDERNAME/cs231n/datasets/
!bash get_datasets.sh
%cd /content/drive/My\ Drive/$FOLDERNAME
My code (local)
# This mounts your Google Drive to the Colab VM.
# from google.colab import drive
# drive.mount('/content/drive')
# TODO: Enter the foldername in your Drive where you have saved the unzipped
# assignment folder, e.g. 'cs231n/assignments/assignment1/'
FOLDERNAME = '/cs231n/assignment1_colab/assignment1'
assert FOLDERNAME is not None, "[!] Enter the foldername."
# Now that we've mounted your Drive, this ensures that
# the Python interpreter of the Colab VM can load
# python files from within it.
import sys
sys.path.append('/home/USER/PATH{}'.format(FOLDERNAME))
# This downloads the CIFAR-10 dataset to your Drive
# if it doesn't already exist.
%cd /home/USER/PATH$FOLDERNAME/cs231n/datasets/
!bash get_datasets.sh
%cd /home/USER/PATH$FOLDERNAME