Skip to content

Instantly share code, notes, and snippets.

View charliememory's full-sized avatar

Liqian Ma charliememory

View GitHub Profile
@charliememory
charliememory / build-gcc.sh
Created November 9, 2020 19:25 — forked from jeetsukumaran/build-gcc.sh
Build and Install GCC Suite from Scratch
#! /bin/bash
GCC_VERSION="5.2.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"
## NOTE: XCode must be installed (through App Store) and the following run to install command-line tools.
## THIS IS IMPORTANT! Among other things, it creates '/usr/include' and installs the system header files.
# xcode-select --install
@charliememory
charliememory / pdm.py
Last active December 19, 2020 14:20
Tensorflow implement of Point Distribution Model && coord2channel function in CVPR 2018 paper "Natural and effective obfuscation by head inpainting"
#################### Point Distribution Model #####################
## ref to OpenFace PDM model https://github.com/TadasBaltrusaitis/OpenFace/tree/79d7116dae7f6b5335016dcb0e9ea64e1f931287/model_training/pdm_generation
def tf_Euler2Rot(euler):
batch_size = euler.get_shape().as_list()[0]
rx, ry, rz = tf.split(euler, 3, axis=1)
Rx_0 = tf.cast(tf.tile(tf.expand_dims([1.0, 0.0, 0.0],0), [batch_size,1]), tf.float64)
Rx_1 = tf.concat([tf.zeros_like(rx, tf.float64), tf.cos(rx), -tf.sin(rx)], axis=1)
Rx_2 = tf.concat([tf.zeros_like(rx, tf.float64), tf.sin(rx), tf.cos(rx)], axis=1)
Rx = tf.concat([tf.expand_dims(Rx_0,1), tf.expand_dims(Rx_1,1), tf.expand_dims(Rx_2,1)], axis=1)
@charliememory
charliememory / tf_bernoulliSample.py
Created August 28, 2018 16:27
tensorflow implement of bernoulli sampling
#################### Bernoulli Sample #####################
## ref code: https://r2rt.com/binary-stochastic-neurons-in-tensorflow.html
def bernoulliSample(x):
"""
Uses a tensor whose values are in [0,1] to sample a tensor with values in {0, 1},
using the straight through estimator for the gradient.
E.g.,:
if x is 0.6, bernoulliSample(x) will be 1 with probability 0.6, and 0 otherwise,
and the gradient will be pass-through (identity).
@charliememory
charliememory / tf_ms_ssim.py
Created August 28, 2018 16:24
tensorflow implement of Multiscale SSIM
#################### MS_SSIM Loss #####################
## ref code: https://stackoverflow.com/questions/39051451/ssim-ms-ssim-for-tensorflow
def _tf_fspecial_gauss(size, sigma):
"""Function to mimic the 'fspecial' gaussian MATLAB function
"""
x_data, y_data = np.mgrid[-size//2 + 1:size//2 + 1, -size//2 + 1:size//2 + 1]
x_data = np.expand_dims(x_data, axis=-1)
x_data = np.expand_dims(x_data, axis=-1)
@charliememory
charliememory / tf_bbox2mask.py
Last active June 1, 2020 03:56
tensorflow implement of bounding box to mask transform
## ref: https://stackoverflow.com/questions/34128104/tensorflow-creating-mask-of-varied-lengths
def tf_bbox2mask(y1, x1, y2, x2, img_H, img_W):
## Repeat for each row or column
y1_transposed = tf.expand_dims(tf.tile(y1,[img_W]), 0)
x1_transposed = tf.expand_dims(tf.tile(x1,[img_H]), 1)
y2_transposed = tf.expand_dims(tf.tile(y2,[img_W]), 0)
x2_transposed = tf.expand_dims(tf.tile(x2,[img_H]), 1)
## Get the range grid
range_row = tf.cast(tf.expand_dims(tf.range(0, img_H, 1), 1), tf.int32)
range_col = tf.cast(tf.expand_dims(tf.range(0, img_W, 1), 0), tf.int32)
@charliememory
charliememory / git-feature-workflow.md
Created May 21, 2018 23:23 — forked from blackfalcon/git-feature-workflow.md
Git basics - a general workflow

There are many Git workflows out there, I heavily suggest also reading the atlassian.com [Git Workflow][article] article as there is more detail then presented here.

The two prevailing workflows are [Gitflow][gitflow] and [feature branches][feature]. IMHO, being more of a subscriber to continuous integration, I feel that the feature branch workflow is better suited.

When using Bash in the command line, it leaves a bit to be desired when it comes to awareness of state. I would suggest following these instructions on [setting up GIT Bash autocompletion][git-auto].

Basic branching

When working with a centralized workflow the concepts are simple, master represented the official history and is always deployable. With each now scope of work, aka feature, the developer is to create a new branch. For clarity, make sure to use descriptive names like transaction-fail-message or github-oauth for your branches.