Skip to content

Instantly share code, notes, and snippets.

View lzhbrian's full-sized avatar
😎
Interesting

Tzu-Heng Lin lzhbrian

😎
Interesting
View GitHub Profile
@lzhbrian
lzhbrian / infinite_dataloader.py
Created November 13, 2020 04:06 — forked from MFreidank/infinite_dataloader.py
A pytorch DataLoader that generates an unbounded/infinite number of minibatches from the dataset.
from torch.utils.data import DataLoader
class InfiniteDataLoader(DataLoader):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Initialize an iterator over the dataset.
self.dataset_iterator = super().__iter__()
def __iter__(self):
@lzhbrian
lzhbrian / boto3-list-instances.py
Created August 24, 2020 03:16 — forked from ableasdale/boto3-list-instances.py
Using Boto 3 to list out AWS EC2 instance information
import boto3
from termcolor import colored
ec2 = boto3.resource('ec2')
for i in ec2.instances.all():
print("Id: {0}\tState: {1}\tLaunched: {2}\tRoot Device Name: {3}".format(
colored(i.id, 'cyan'),
colored(i.state['Name'], 'green'),
@lzhbrian
lzhbrian / create_user.sh
Created March 6, 2020 14:10
create user account in ubuntu
for i in $@
do
# create user
useradd --gid groupname --home-dir /nvme/$i --create-home --no-user-group --shell /bin/bash $i
echo $i:$i | chpasswd
# make folder a data path
mkdir /data1/$i
chown $i:groupname /data1/$i
done
@lzhbrian
lzhbrian / download.py
Created February 13, 2020 03:25
download vggface2 dataset from commandline
# this is from
# https://github.com/ox-vgg/vgg_face2/issues/2#issuecomment-461684945
import requests
import getpass
import sys
LOGIN_URL = "http://zeus.robots.ox.ac.uk/vgg_face2/login/"
FILE_URL = "http://zeus.robots.ox.ac.uk/vgg_face2/get_file?fname=vggface2_test.tar.gz"
@lzhbrian
lzhbrian / gen_video_interpolation.py
Created January 20, 2020 08:41
generate interpolation video from stylegan2
"""
Author: lzhbrian (https://lzhbrian.me)
Date: 2020.1.20
Note: mainly modified from: https://github.com/tkarras/progressive_growing_of_gans/blob/master/util_scripts.py#L50
"""
import numpy as np
from PIL import Image
import os
import scipy
@lzhbrian
lzhbrian / align_face.py
Last active February 6, 2024 03:20
face alignment with FFHQ method (https://github.com/NVlabs/ffhq-dataset)
"""
brief: face alignment with FFHQ method (https://github.com/NVlabs/ffhq-dataset)
author: lzhbrian (https://lzhbrian.me)
date: 2020.1.5
note: code is heavily borrowed from
https://github.com/NVlabs/ffhq-dataset
http://dlib.net/face_landmark_detection.py.html
requirements:
apt install cmake
@lzhbrian
lzhbrian / trim_detectron_model.py
Created April 26, 2019 07:13 — forked from wangg12/trim_detectron_model.py
trim last layers of detectron model for maskrcnn-benchmark
import os
import torch
import argparse
from maskrcnn_benchmark.config import cfg
from maskrcnn_benchmark.utils.c2_model_loading import load_c2_format
def removekey(d, listofkeys):
r = dict(d)
for key in listofkeys:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lzhbrian
lzhbrian / upload_img.html
Created November 28, 2017 14:06
fix iOS upload image error
<script>
var MAX_WIDTH = 300;
var MAX_HEIGHT = 400;
var dataurl_user = null;
var dataurl_celebrity = null;
function handleFiles(inputid, imageid_to_show, mode)
{
var filesToUpload = document.getElementById(inputid).files;
@lzhbrian
lzhbrian / resize_img_before_upload.html
Created November 28, 2017 04:43
resize img before upload (js)
<img src="" id="image">
<input id="input" type="file" onchange="handleFiles()">
<script>
function handleFiles()
{
var dataurl = null;
var filesToUpload = document.getElementById('input').files;
var file = filesToUpload[0];