Skip to content

Instantly share code, notes, and snippets.

@elijahc
elijahc / keras_clear_gpu_mem.py
Last active September 4, 2018 15:43
Clearing gpu memory once a computation is complete when using keras
# Inspired by
# http://forums.fast.ai/t/tip-clear-tensorflow-gpu-memory/1979
# https://github.com/tensorflow/tensorflow/issues/1578#issuecomment-200544189
import keras.backend as K
def limit_mem():
K.get_session().close()
cfg = K.tf.ConfigProto()
cfg.gpu_options.allow_growth = True
K.set_session(K.tf.Session(config=cfg))
@elijahc
elijahc / timelapse.md
Created August 31, 2018 05:59 — forked from alexellis/timelapse.md
ffmpeg time-lapse

Convert sequence of JPEG images to MP4 video

ffmpeg -r 24 -pattern_type glob -i '*.JPG' -i DSC_%04d.JPG -s hd1080 -vcodec libx264 timelapse.mp4

  • -r 24 - output frame rate
  • -pattern_type glob -i '*.JPG' - all JPG files in the current directory
  • -i DSC_%04d.JPG - e.g. DSC_0397.JPG
  • -s hd1080 - 1920x1080 resolution

Slower, better quality

ACTION=="add"
KERNEL=="sd?1", \
ATTRS{busnum}=="3", \
ATTRS{devpath}=="2", \
ENV{mount_point}=df "$env{DEVNAME}" | tail -1 | awk '{ print $6}'
SYMLINK+="bak_src", \
RUN+="/bin/rm /media/bak_src", RUN+="/bin/ln -s $env{mount_point} /media/bak_src"
ACTION=="remove"
KERNEL=="sd?1", \
@elijahc
elijahc / keras_reset_weights.py
Created April 13, 2018 18:27
Reset weights in a Keras layer
import keras.backend as K
def reset_weights(model):
session = K.get_session()
for layer in model.layers:
if hasattr(layer, 'kernel_initializer'):
layer.kernel.initializer.run(session=session)
@elijahc
elijahc / loadaerdat.py
Last active April 7, 2018 19:03
Example script for loading aerdat files from neuromorphic DVS camera
# Source:
# https://sourceforge.net/p/jaer/code/HEAD/tree/scripts/python/jAER_utils/loadaerdat.py
import struct
import os
V3 = "aedat3"
V2 = "aedat" # current 32bit file format
V1 = "dat" # old format
EVT_DVS = 0 # DVS event type
@elijahc
elijahc / autonrn.sh
Created February 6, 2018 01:02
Script for installing NEURON and python 2.7 on ec2
# Install the relevant system requirements
sudo apt-get update
# Install Python 2.7 w/ development headers
sudo apt-get install -y python
sudo apt-get install -y python-dev
# Install NEURON deps
sudo apt-get install -y libx11-dev
sudo apt-get install -y libxext-dev
@elijahc
elijahc / jupyter-hub-setup.md
Created November 8, 2017 02:56
Setting up Jupyterhub with multiple virtualenv kernels managed with pyenv
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@elijahc
elijahc / hw1.ipynb
Last active September 19, 2017 17:09
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.