Skip to content

Instantly share code, notes, and snippets.

@zhanghang1989
zhanghang1989 / camera_demo.py
Created May 27, 2017 02:55
Python Opencv Camera Show
import cv2
def run_demo(mirror=False):
cam = cv2.VideoCapture(0)
cam.set(3, 640)
cam.set(4, 480)
key = 0
while True:
# read frame
ret_val, img = cam.read()
@zhanghang1989
zhanghang1989 / camera_demo.lua
Created May 27, 2017 02:55
Torch Lua Camera Demo
require 'torch'
require 'image'
require 'camera'
require 'qt'
local function main()
local camera_opt = {
idx = 0,
fps = 30,
# export PATH=$PATH:/usr/local/cuda/bin
# export LD_LIBRARY_PATH=/usr/local/cuda/lib
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
alias l='ls -GFh'
alias count='ls -F |grep -v / | wc -l'
" Vim color file
" Maintainer: Gerald S. Williams
" Last Change: 2003 Apr 17
" A nice light background (you guessed it, PapayaWhip) that's relatively easy
" on the eyes yet very usable. Not nearly as "puffy" as peachpuff.
"
" Only values that differ from defaults are specified.
set background=light
colorscheme papaya
syntax on
set nu
set hlsearch
set autoindent
set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
set cursorline
autocmd BufRead,BufNewFile *.cu set filetype=cpp
autocmd Filetype cpp setlocal expandtab tabstop=2 shiftwidth=2
autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4
@zhanghang1989
zhanghang1989 / TwoLayerExample.m
Created March 9, 2018 01:36
Training Two Layer NN
N = 64;
D_in = 1000;
H = 100;
D_out = 10;
% init input and output
x = rand(N, D_in)-0.5;
y = rand(N, D_out)-0.5;
% init weights
@zhanghang1989
zhanghang1989 / eval_ade.py
Created June 5, 2018 18:04
Evaluating Script for ADE20K Dataset
import os
import sys
from tqdm import tqdm
from PIL import Image
import numpy as np
# adapt from https://github.com/CSAILVision/placeschallenge/blob/master/sceneparsing/evaluationCode/utils_eval.py
def intersectionAndUnion(imPred, imLab, numClass):
imPred = np.asarray(imPred)
imLab = np.asarray(imLab)
name: "SENet"
# mean_value: 104, 117, 123
layer {
name: "data"
type: "Input"
top: "data"
input_param: {
shape: {
dim: 1
dim: 3

PyTorch to MXNet

This cheatsheet serves as a quick reference for PyTorch users who are interested in trying MXNet, and vice versa.

Pytorch is a deep learning framework provides imperative tensor manipulation and neural network training. MXNet provides similar imperative tensor manipulation through the ndarray package and neural network training through gluon. This cheatsheet maps functions one-by-one between these two frameworks.

Note that MXNet has a symbolic interface similar to Keras and Tensorflow that may provide better performance and portability. This cheatsheet mainly focus on MXNet's imperative interface.

Installation

@zhanghang1989
zhanghang1989 / auto_compress.py
Last active April 4, 2020 03:53
automatically create zip file for model_zoo upload
import os
from os import listdir
from os.path import isfile, join
import hashlib
import shutil
import zipfile
mypath = './'
newpath = './zip'