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 / pandas_melt.py
Created September 5, 2017 09:22 — forked from rainsunny/pandas_melt.py
Turn certain columns to key-value rows ( and the reverse )
"""
Turn this
location name Jan-2010 Feb-2010 March-2010
A "test" 12 20 30
B "foo" 18 20 25
into this
location name Date Value
@lzhbrian
lzhbrian / ajax_form.js
Last active November 28, 2017 04:28
Send form using javascript
// Post the data
var fd = new FormData();
fd.append("name", "some_filename.jpg");
fd.append("image", dataurl);
fd.append("info", "lah_de_dah");
$.ajax({
url: '/ajax_photo',
data: fd,
cache: false,
contentType: false,
@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];
@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;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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:
@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 / 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 / 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 / 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