Skip to content

Instantly share code, notes, and snippets.

View leimao's full-sized avatar
🦉
Hello Underworld.

Lei Mao leimao

🦉
Hello Underworld.
View GitHub Profile
@leimao
leimao / fast_tf_estimator_predict.py
Created August 28, 2019 22:05
TensorFlow Predict Using tf.Estimator without Rebuilding Graphs.
"""
Speeds up estimator.predict by preventing it from reloading the graph on each call to predict.
It does this by creating a python generator to keep the predict call open.
Usage: Just warp your estimator in a FastPredict. i.e.
classifier = FastPredict(learn.Estimator(model_fn=model_params.model_fn, model_dir=model_params.model_dir), my_input_fn)
This version supports tf 1.4 and above and can be used by pre-made Estimators like tf.estimator.DNNClassifier.
Author: Marc Stogaitis
# https://github.com/marcsto/rl/blob/master/src/fast_predict2.py
"""
import tensorflow as tf
@leimao
leimao / csv_splitter.py
Created August 1, 2019 18:16 — forked from jrivero/csv_splitter.py
A Python CSV splitter
import os
def split(filehandler, delimiter=',', row_limit=10000,
output_name_template='output_%s.csv', output_path='.', keep_headers=True):
"""
Splits a CSV file into multiple pieces.
A quick bastardization of the Python CSV library.
Arguments:
@leimao
leimao / template_specialization.cpp
Created May 4, 2019 18:51
Template Specialization Usages
// https://www.geeksforgeeks.org/template-specialization-c/
@leimao
leimao / friend.cpp
Last active May 4, 2019 18:50
Friend Class and Function Usages
#include <iostream>
/*
* Modified from
* https://www.geeksforgeeks.org/friend-class-function-cpp/
*/
class A;
class B;
@leimao
leimao / inheritance.cpp
Last active May 2, 2019 07:25
C++ Class Inheritance Guidance
#include <iostream>
// https://stackoverflow.com/questions/860339/difference-between-private-public-and-protected-inheritance
class A
{
public:
int x = 1;
// Constructor
A() {}
@leimao
leimao / GitHub-Forking.md
Created April 30, 2019 20:30 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

@leimao
leimao / function_pointers_kernel.cu
Last active May 26, 2025 12:39
Alchemy on passing functional pointers to kernel in CUDA programming. https://leimao.github.io/blog/Pass-Function-Pointers-to-Kernels-CUDA/
#include <iostream>
// Since C++ 11
template<typename T>
using func_t = T (*) (T, T);
template <typename T>
__device__ T add_func (T x, T y)
{
return x + y;
@leimao
leimao / reorg_simulation.py
Last active April 8, 2020 07:24
This is a simulation for the reorg layer in YOLO v2 model.
import numpy as np
stride_MACRO = 2
batch_MACRO = 2
C_MACRO = 4
H_MACRO = 6
W_MACRO = 6
"""
@leimao
leimao / typedef.cpp
Created April 8, 2019 22:01
C++ typedef Advanced Usages
#include <iostream>
// more complicated typedef
typedef int int_t, *intp_t, (&fp)(int, float), arr_t[10];
int my_int_func(int x, float y)
{
return x;
}
# Check blog details:
# https://yerevann.github.io/2016/06/26/combining-cnn-and-rnn-for-spoken-language-identification/
# TensorFlow sample code
# http://nicholaspropes.com/entries/general/updated-cnn-rnn-tensorflow-example-code
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import math