Skip to content

Instantly share code, notes, and snippets.

@liangfu
liangfu / ffmpeg.md
Created May 24, 2017 04:46 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma

You can get the list of supported formats with:
ffmpeg -formats

Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:

@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
#
@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

/*
* 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 / 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 / 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 / bosonnlp_to_bio2.py
Last active January 27, 2021 07:13
Convert origindata.txt in bosonnlp to CoNLL format for named entity recognition (NER).
import random
random.seed(111)
def bosonnlp_to_bio2(origfile, trainfile, valfile):
val_ratio = 0.2
traindata = []
valdata = []
with open(origfile, 'rt') as fp:
@liangfu
liangfu / s3_controller.py
Created January 28, 2021 09:15
Enable batch operations for recursively copying s3 objects
import boto3
def recursive_copy(src_bucket, src_prefix, dst_bucket, dst_prefix):
def get_partition():
if boto3.session.Session().region_name in ["cn-northwest-1", "cn-north-1"]:
return "aws-cn"
else:
return "aws"
partition = get_partition()
region_name = boto3.session.Session().region_name
# Inspired by https://keon.io/deep-q-learning/
# python3 -m pip install keras==2.3.1 tensorflow-gpu==1.15 gym==0.18.3
# python3 -m pip install 'h5py==2.10.0' --force-reinstall
import random
import gym
import math
import numpy as np
import keras
@liangfu
liangfu / bfloat16.cc
Last active January 4, 2022 23:00
An implementation of IEEE 16-bit floating point data type
#include <stdio.h>
#include <inttypes.h>
static const uint32_t kSingleSignMask = 0x80000000;
static const uint32_t kSingleExpMask = 0x7f800000;
static const uint32_t kSingleMantMask = 0x007fffff;
static const uint32_t kHalfSignMask = 0x8000;
static const uint32_t kHalfExpMask = 0x7c00;
static const uint32_t kHalfMantMask = 0x03ff;