Skip to content

Instantly share code, notes, and snippets.

View yinguobing's full-sized avatar
💓
writing human friendly code...

Yin Guobing yinguobing

💓
writing human friendly code...
View GitHub Profile
@yinguobing
yinguobing / split_files.sh
Last active July 13, 2021 01:00
Split files in one directory into many dirs.
n=0
for i in *
do
if [ $((n+=1)) -gt 50 ]; then
n=1
fi
todir=../my_file$n
[ -d "$todir" ] || mkdir "$todir"
mv "$i" "$todir"
done
@yinguobing
yinguobing / process_video.py
Last active August 26, 2022 01:39
Template module for video frame processing.
"""Template code for video frame processing.
Features:
- video source from files or webcams.
- automatically flip the frame if reading from webcam.
- built in video writer to output the processed result.
- built in FPS metter.
For more: https://github.com/yinguobing
"""
@yinguobing
yinguobing / save_mesh_animation.py
Created July 21, 2020 07:33
Save the face mesh points animation video file.
import tkinter
import cv2
import matplotlib
from matplotlib import animation, pyplot
from mpl_toolkits.mplot3d import Axes3D
# The module mesh_detector could be found here:
# https://github.com/yinguobing/head-pose-estimation/tree/google-face-mesh
from mesh_detector import MeshDetector
@yinguobing
yinguobing / import_savedmodel_to_tensorboard.py
Created August 6, 2019 10:17
Import TensorFlow SavedModel to TensorBoard
"""Imports a SavedModel as a graph in Tensorboard."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import sys
from tensorflow.core.framework import graph_pb2
@yinguobing
yinguobing / load_saved_model.py
Last active April 3, 2019 11:40
Load TensorFlow saved model and run inference.
import tensorflow as tf
MODEL_PATH = '/home/robin/Desktop/arc_inf/1554262166'
IMAGE_PATH = '/data/dataset/public/ms_celeb_1m/arc_face_data/img/0/0.jpg'
with tf.Session(graph=tf.Graph()) as sess:
# Restore model from the saved_modle file, that is exported by TensorFlow estimator.
tf.saved_model.loader.load(sess, ["serve"], MODEL_PATH)
# Get the output node from the graph.
@yinguobing
yinguobing / tfrecord.py
Last active February 21, 2022 03:08
Minimal example writing tfrecord file from a image and it's label.
"""Minimal example showing how to generate TensorFlow TFRecord file."""
import tensorflow as tf
tf.enable_eager_execution()
# All raw values should be converted to a type compatible with tf.Example. Use
# the following functions to do these convertions.
def _bytes_feature(value):
"""Returns a bytes_list from a string / byte."""
import matplotlib.pyplot as plt
import numpy as np
DURATION = 12
FPS = 25
START = 0
STEPS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
if __name__ == "__main__":
@yinguobing
yinguobing / perf_grab_decode.py
Created November 15, 2018 11:35
Performance benchmark for read() and grab() in OpenCV VideoCapture.
"""
read() and grab() in OpenCV VideoCapture takes different time as there is no
decoding for grab() operation. Let's try to find out how much these two methods
differs.
"""
import cv2
def main():
tm = cv2.TickMeter()
@yinguobing
yinguobing / video_threaded.py
Last active May 8, 2022 01:38
OpenCV minimal example showing multithreaded video processing.
# Original code here:
# https://github.com/opencv/opencv/blob/master/samples/python/video_threaded.py
#!/usr/bin/env python3
'''
Multithreaded video processing minimal sample.
Usage:
python3 video_threaded.py
Shows how python threading capabilities can be used
@yinguobing
yinguobing / cluster.py
Created July 20, 2017 02:15
这段代码用来对Cambridge Hand Gesture Data set进行整理,将所有的图像重命名并按照类别放置在预定的文件夹中,以便生成TensorFlow需要的TFRecord文件。
import os
import numpy
from random import randint
from PIL import Image
# Get all the image files' path.
homePath = "./images"
# Define locations for different type of data.
for dir_parent in ["train", "test"]: