Skip to content

Instantly share code, notes, and snippets.

@kyamagu
kyamagu / resnet.py
Last active May 28, 2021 12:35
Caffe NetSpec for ResNet architecture
#!/usr/bin/env python
'''Caffe ResNet NetSpec example.
Compatible with Kaiming He's pre-trained models.
https://github.com/KaimingHe/deep-residual-networks
'''
import sys
@kyamagu
kyamagu / plot_iteration.py
Last active November 1, 2016 03:32
Caffe solver log analyzer
'''
Plot iteration information from the log file.
Usage
python examples/message_passing/plot_iteration.py solver.log
'''
import argparse
@kyamagu
kyamagu / celeba_alexnet_independent.prototxt
Last active November 10, 2016 23:53
Caffe baseline model with AlexNet for CelebA dataset
name: "celeba_alexnet_independent"
layer {
name: "data"
type: "Data"
top: "data"
include {
phase: TRAIN
}
transform_param {
mirror: true
@kyamagu
kyamagu / qlogin.sh
Last active August 29, 2015 14:17
Shell .profile to retrieve SGE environment within login
# set SGE environment if exists
ACTIVE_JOBS_DIR=/var/spool/gridengine/execd/$(hostname)/active_jobs/
if [ -d $ACTIVE_JOBS_DIR ]; then
PARENT_PID=$(ps -p $(ps -p $$ -o ppid --no-header) -o ppid --no-header)
for job_dir in $(ls -1 $ACTIVE_JOBS_DIR); do
JOB_PID=$(cat $ACTIVE_JOBS_DIR$job_dir/job_pid)
if [ $JOB_PID -eq $PARENT_PID ]; then
echo . $ACTIVE_JOBS_DIR$job_dir/environment
. $ACTIVE_JOBS_DIR$job_dir/environment
break
@kyamagu
kyamagu / caffe_proto_.cc
Last active December 6, 2016 17:26
Caffe Datum proto converter
// Caffe proto converter.
//
// Build.
//
// mex -I/path/to/matlab-lmdb/include ...
// -I/path/to/caffe/build/src/caffe/proto ...
// caffe_proto_.cc ...
// /path/to/caffe/build/src/caffe/proto/caffe.pb.o ...
// -lprotobuf CXXFLAGS="$CXXFLAGS -std=c++11"
//
@kyamagu
kyamagu / lmdb_reader.py
Last active May 28, 2021 12:37
Python iterator for kv-store
import lmdb
import leveldb
def lmdb_reader(filename, **kwargs):
with lmdb.open(filename, readonly=True, create=False, **kwargs) as env:
with env.begin() as txn:
with txn.cursor() as cursor:
for key, value in cursor:
yield key, value
@kyamagu
kyamagu / java_home.sh
Created August 12, 2014 15:06
Command to find JAVA_HOME in OS X. Needed to use older Matlab that is not compatible with Java 1.7.
#!/bin/sh
/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home -v "1.6"
@kyamagu
kyamagu / find-opencv-conflict.sh
Last active August 29, 2015 14:02
UNIX command to detect conflicting opencv objects.
#!/bin/sh
pkg-config --libs opencv | grep -E -o "/.*\.(so|dylib)" | sed "s/ /:/g"
@kyamagu
kyamagu / mex-dispatch.h
Created March 13, 2014 21:59
MEX-disptach: Macro library to build a dispatchable MEX file in ANSI C.
/** MEX-disptach: Macro library to build a dispatchable MEX file.
*
* Example:
*
* // mylibrary.c
* #include "mex-dispatch.h"
* void myFunction(int nlhs, mxArray** plhs,
* int nrhs, const mxArray** prhs) {
* mexPrintf("myFunction called.");
* }
@kyamagu
kyamagu / mexopts.sh
Last active January 2, 2016 21:29
Matlab MEX configurations to be compatible with OS X Mavericks. 1) Change target to 10.9, 2) Change from libstdc++ to libc++, 3) Use c++11, 4) Add CHAR16_T macro
CC='clang'
CXX='clang++'
SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/'
MACOSX_DEPLOYMENT_TARGET='10.9'
CFLAGS="$CFLAGS -Dchar16_t=uint16_t"
CXXFLAGS="$CXXFLAGS -std=c++11 -stdlib=libc++ -DCHAR16_T"
CXXLIBS="$MLIBS -lc++"