Skip to content

Instantly share code, notes, and snippets.

View CookieLau's full-sized avatar
👁️
Looking for next step.

cookielau CookieLau

👁️
Looking for next step.
  • Beijing, China
View GitHub Profile
@CookieLau
CookieLau / pdf_merger.py
Last active November 13, 2023 10:10
A CLI PDF Merger tool
from PyPDF2 import PdfMerger
import os
from tqdm import tqdm
directory = input("Please input the directory containing all pdfs: ")
#Create an instance of PdfFileMerger() class
merger = PdfMerger()
#Create a list with the file paths
@CookieLau
CookieLau / ADMM_fore_background_segmentation.py
Created April 13, 2023 16:34
Foreground/Background Segmentation using ADMM algorithm.
import time
import math
import numpy as np
import pandas as pd
import pickle
import wandb
wandb.init(project="dsa5103-assignment3")
# helper functions
@CookieLau
CookieLau / plot_intersection.py
Created April 11, 2023 03:52
Find and plot the intersection of side and down image of DICOM
def get_orientation(IOP):
orientations = [float(x) for x in IOP]
row = orientations[:3]
col = orientations[3:]
return np.array(row), np.array(col)
def get_position(IPP):
position = [float(x) for x in IPP]
return np.array(position)
def get_Spacing(PS):
return [float(x) for x in PS]
@CookieLau
CookieLau / transfer_learning_on_cifar10.py
Last active April 7, 2023 11:33
Transfer Learning by tuning the head of ImageNet-1K pre-trained model
# Original Code here:
# https://github.com/pytorch/examples/blob/master/mnist/main.py
import os
import gc
import time
import random
from filelock import FileLock
import torch
from torch import optim
@CookieLau
CookieLau / tiny_ImageNet_download.py
Last active April 5, 2023 13:03
download tiny-ImageNet using `datasets` and save as ImageNet train/test split with individual categorical sub-directory
from datasets import load_dataset
import os
from PIL import Image
from tqdm import tqdm
os.makedirs("train", exist_ok=True)
os.chdir("train")
tiny_imagenet = load_dataset('Maysee/tiny-imagenet', split='train')
size = 100000
@CookieLau
CookieLau / cifar_pre_process.py
Created April 5, 2023 03:07
If you would like to process CIFAR dataset like the ImageNet-1K, i.e. split the train and test dataset and every category as an individual subdirectory, try this gist!
import cv2
import numpy as np
import pickle
import os
import shutil
from torchvision import datasets
# %%
def unpickle(file):