Skip to content

Instantly share code, notes, and snippets.

@liangfu
liangfu / mobilenet.md
Created December 29, 2017 10:42
mobilenet model zoo

MobileNet_v1

MobileNets are small, low-latency, low-power models parameterized to meet the resource constraints of a variety of use cases. They can be built upon for classification, detection, embeddings and segmentation similar to how other popular large scale models, such as Inception, are used. MobileNets can be run efficiently on mobile devices with TensorFlow Mobile.

MobileNets trade off between latency, size and accuracy while comparing favorably with popular models from the literature.

alt text

Pre-trained Models

@liangfu
liangfu / vta_datapath.json
Created November 8, 2019 07:20
VTA Datapath in Yosys JSON Format; (Generate Block Diagram from https://nturley.github.io/netlistsvg )
{
creator: "Yosys 0.5+220 (git sha1 94fbaff, emcc -Os)",
modules: {
VTAShell: {
ports: {
io_host_r: {
direction: "output",
bits: [
0
]
@liangfu
liangfu / strip_comment.py
Created September 22, 2019 04:02
Strip Comment Sections in Chisel Generated Verilog files
#!/usr/bin/env python3
import os, sys
out = ""
with open(sys.argv[1], 'r') as fp:
lines = fp.readlines()
for idx, line in enumerate(lines):
end = line.find(" // @[")
line = line[:end] + '\n'
out += line
@liangfu
liangfu / winograd.py
Created November 19, 2017 06:19
winograd convolution in numpy
#!/usr/bin/python
# Copyright 2015-2016 Nervana Systems Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
/*
* one.c -- Lua core, libraries, and interpreter in a single file (Lua 5.3)
*/
/* default is to build the full interpreter */
#ifndef MAKE_LIB
#ifndef MAKE_LUAC
#ifndef MAKE_LUA
#define MAKE_LUA
#endif
@liangfu
liangfu / utility.h
Created August 25, 2016 01:45
Get current time in formatted string with cross-platform C/C++, while avoid using c++11 classes.
#include <string>
#include <ctime>
#if defined WIN32
#include <windows.h>
#include <stdint.h>
static int gettimeofday(struct timeval * tp, struct timezone * tzp)
{
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
SYSTEMTIME system_time;
@liangfu
liangfu / pg-pong.py
Created June 1, 2016 02:20 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@liangfu
liangfu / hash.c
Created May 24, 2016 16:05
simple hash string code in c
char num2char(size_t num){
char res = 0; int val = num%62;
if (val<10){ res = val+48;
}else if (val>=10&&val<36){ res = val+65-10;
}else if (val>=36&&val<62){ res = val+97-36;
}return res;
}
void swap(char & a, char & b){char t=b;b=a;a=t;}
void hash(char * src, char * dst, int sz){
memcpy(dst,src,32);
@liangfu
liangfu / MLPdemo.m
Last active April 29, 2016 07:02
demonstration of multi-layer perceptron with gradient checkings enabled
function MLPdemo()
net.alpha=0.002;
net.maxiter=200;
% hyperbolic - input layer
net.layer{1}.forward = @tanh_forward;
net.layer{1}.backward = @tanh_backward;
net.layer{1}.alpha=net.alpha;
@liangfu
liangfu / cvquantile.cpp
Last active April 27, 2016 09:19
Compute quantile of input matrix for given value range from 0.0 to 1.0
/**
* compute quantile of input matrix for given value range from 0.0 to 1.0
*/
float cvQuantile(CvMat * src, float p)
{
p=MIN(1,MAX(0,p)); // eliminate overflow
int nr = src->rows, nc = src->cols;
CvMat * converted = cvCreateMat(nr,nc,CV_32F);
CvMat * reshaped = cvCreateMat(1,nr*nc,CV_32F);
CvMat * sorted = cvCreateMat(1,nr*nc,CV_32F);