Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / build_celeba_lmdb.py
Created December 12, 2016 06:52
Script to convert CelebA dataset to LMDB format
#!/usr/bin/env python
'''
Example:
python data/celeba/scripts/build_dataset.py \
--output_dir data/celeba/
./build/tools/compute_image_mean \
data/celeba/train-images.lmdb \
data/celeba/mean.binaryproto
@kyamagu
kyamagu / ubuntu-setup.md
Last active August 3, 2021 14:18
Ubuntu in ActiveDirectory environment

Ubuntu setup

Setup instructions for the Ubuntu 16.04 workstations and servers in the laboratory environment. Replace systemctl with Upstart start|stop for Ubuntu 14.04.

Passwordless sudo

sudo tee /etc/sudoers.d/administrator <<EOF
administrator ALL=(ALL) NOPASSWD: ALL
EOF
@kyamagu
kyamagu / binary_classification_utils.py
Created June 15, 2017 13:12
Helper for binary classification training in PyTorch
"""
Use in PyTorch.
"""
def accuracy(output, target):
"""Computes the accuracy for multiple binary predictions"""
pred = output >= 0.5
truth = target >= 0.5
acc = pred.eq(truth).sum() / target.numel()
return acc

SMBNetFS

Install and setup

sudo apt-get install smbnetfs
mkdir ~/.smb
cp /etc/smbnetfs/smbnetfs.conf ~/.smb
cp /etc/samba/smb.conf ~/.smb