Skip to content

Instantly share code, notes, and snippets.

View hlzz's full-sized avatar
🎯
Focusing

Tianwei Shen hlzz

🎯
Focusing
  • Meta
  • United States
View GitHub Profile
import sys
import cv2
for img_path in all_image_path:
one_img = cv2.imread(img_path, -1 | 128)
if one_img == None:
print(img_path, 'has problem, exit...')
exit(-1)
else:
print(img_path, 'exists')
@hlzz
hlzz / gist:f0604e4bd2ce9cc6511048b1ba665788
Created May 10, 2018 06:11
tensorflow restore model
def recover_from_pretrained(sess, net, ckpt_path=None, ckpt_step=-1, np_model_path=None):
"""
recover from pretrained ckpt graph or numpy net parameters
:param sess: the current session
:param net: the feature tower
:param ckpt_path: the ckpt root path (if there is any)
:param ckpt_step: the ckpt step number (if there is any)
:param np_model_path: the numpy model path (if there is any)
:return: the correct step index for the current
"""
@hlzz
hlzz / list_from_folder.py
Last active March 28, 2018 09:32
List many many files from a folder
#!/usr/bin/env python
# Copyright 2016, Tianwei Shen, HKUST.
"""
A handy script to execute a command recursively in a folder,
such as 'ls' or 'rm' files.
"""
import os
@hlzz
hlzz / gist:db68fb6f401fe8a60586b19222d4f2b9
Last active June 27, 2018 09:14
Some useful bash commands
# some bash tricks (Ubuntu 16.04)
## show the smallest 500 files
ll | awk '{print $5" "$NF}' | sort | head -500
## if find some empty files, you can output them to a file named empty_files.txt
## then rm them using this pipe
cat empty_files.txt | awk '{print "index/"$2}' | xargs rm
## rank file size from largest to smallest and show top 100
@hlzz
hlzz / gist:ba6da6e692beceb4da8b4d5387a8eacc
Created February 28, 2018 09:03
Generate sprite images for tensorboard
#!/usr/bin/python
from PIL import Image
import math
test_image_list = '/home/tianwei/Data/sfm_data/test_image_list' # path to the image list
with open(test_image_list, 'r') as f:
test_images = f.readlines()
test_images = map(str.strip, test_images)