Skip to content

Instantly share code, notes, and snippets.

View YefanZhou's full-sized avatar
🎯
Focusing

Yefan YefanZhou

🎯
Focusing
View GitHub Profile
@YefanZhou
YefanZhou / pad_packed_demo.py
Created September 19, 2024 20:47 — forked from HarshTrivedi/pad_packed_demo.py
Minimal tutorial on packing (pack_padded_sequence) and unpacking (pad_packed_sequence) sequences in pytorch.
import torch
from torch import LongTensor
from torch.nn import Embedding, LSTM
from torch.autograd import Variable
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
## We want to run LSTM on a batch of 3 character sequences ['long_str', 'tiny', 'medium']
#
# Step 1: Construct Vocabulary
# Step 2: Load indexed data (list of instances, where each instance is list of character indices)
@YefanZhou
YefanZhou / README.md
Created February 6, 2024 23:41 — forked from antoinebrl/README.md
Prepare ImageNet

Preparation of ImageNet (ILSVRC2012)

The dataset can be found on the official website if you are affiliated with a research organization. It is also available on Academic torrents.

This script extracts all the images and group them so that folders contain images that belong to the same class.

  1. Download the ILSVRC2012_img_train.tar and ILSVRC2012_img_val.tar
  2. Download the script wget https://gist.github.com/antoinebrl/7d00d5cb6c95ef194c737392ef7e476a/raw/dc53ad5fcb69dcde2b3e0b9d6f8f99d000ead696/prepare.sh
  3. Run it ./prepare.sh
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@YefanZhou
YefanZhou / hook_activations.py
Created February 17, 2023 18:19 — forked from Tushar-N/hook_activations.py
Pytorch code to save activations for specific layers over an entire dataset
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as tmodels
from functools import partial
import collections
# dummy data: 10 batches of images with batch size 16
dataset = [torch.rand(16,3,224,224).cuda() for _ in range(10)]
@YefanZhou
YefanZhou / cmd.sh
Created July 6, 2021 13:12
Cloud Machine Setup scripts
apt-get update
apt install vim
apt install git
apt install gpustat
apt install wget
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
@YefanZhou
YefanZhou / explanation
Created April 13, 2021 02:44
Python multiprocessing Pool vs Process
link: https://www.ellicium.com/python-multiprocessing-pool-process/
Summary: To summarize this, pool class works better when there are more processes and small IO wait.
Process class works better when processes are small in number and IO operations are long.
@YefanZhou
YefanZhou / cmd.md
Created March 25, 2021 07:12
Ubuntu Clash setup virtual environment
@YefanZhou
YefanZhou / iterm2.html
Created March 23, 2021 02:02
Iterm2 in git slow
https://www.dazhuanlan.com/2019/09/26/5d8cd9b067a23/
@YefanZhou
YefanZhou / cmd.sh
Created March 22, 2021 05:00
Download file from Google drive with command line
# https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive
pip install gdown
gdown https://drive.google.com/uc?id={}
@YefanZhou
YefanZhou / delete_git_submodule.md
Created March 19, 2021 01:38 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule