Giter Club home page Giter Club logo

cs231n's Introduction

CS231n: Assignment Solutions

Convolutional Neural Networks for Visual Recognition

Stanford - Spring 2023

About

Overview

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).

Main sources (official)


Solutions

Assignment 1

  • 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

Assignment 2

  • 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

Assignment 3

  • 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

Running Locally

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:

  1. Install the required packages:
    pip install -r requirements.txt
  2. Change every first code cell in .ipynb files to:
    %cd cs231n/datasets/
    !bash get_datasets.sh
    %cd ../../
  3. 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.

Difference in assignments code (.ipynb)

In basic, assignments work in colab. But I worked in local environment.

Example (assignemt1)

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

cs231n's People

Contributors

ro-ko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.