Skip to content

Instantly share code, notes, and snippets.

@f0k
f0k / cudnn_codepath.py
Created November 18, 2014 19:53
cuDNN code path benchmark
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Demonstrates that cuDNN does not choose the fastest code path internally.
It first asks cuDNN to compute a particular full convolution as a forward
pass with sufficient zero padding of the input.
It then asks cuDNN to compute the same as a backward pass of a valid convolution
without zero padding of the input.
@f0k
f0k / png_strip_pHYs.py
Created May 3, 2015 10:39
Strip resolution information (pHYs chunk) from PNG file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Strips the pHYs chunk (resolution information) of a .png file.
Handy if pdflatex fails with "dimension too large" due to the
PNG resolution being set to 1.
For usage information, call without any parameters.
@f0k
f0k / wgan_mnist.py
Created February 2, 2017 14:21
Lasagne WGAN example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Example employing Lasagne for digit generation using the MNIST dataset and
Wasserstein Generative Adversarial Networks
(WGANs, see https://arxiv.org/abs/1701.07875 for the paper and
https://github.com/martinarjovsky/WassersteinGAN for the "official" code).
It is based on a DCGAN example:
@f0k
f0k / lsgan_mnist.py
Created March 7, 2017 13:22
Lasagne LSGAN example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Example employing Lasagne for digit generation using the MNIST dataset and
Least Squares Generative Adversarial Networks
(LSGANs, see https://arxiv.org/abs/1611.04076 for the paper).
It is based on a WGAN example:
https://gist.github.com/f0k/f3190ebba6c53887d598d03119ca2066
@f0k
f0k / dcgan_mnist.py
Last active December 7, 2017 12:03
Lasagne DCGAN example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Example employing Lasagne for digit generation using the MNIST dataset and
Deep Convolutional Generative Adversarial Networks
(DCGANs, see http://arxiv.org/abs/1511.06434).
It is based on the MNIST example in Lasagne:
http://lasagne.readthedocs.org/en/latest/user/tutorial.html
@f0k
f0k / pcenlayer.py
Last active June 18, 2018 17:25
PCEN layer for Lasagne
# -*- coding: utf-8 -*-
"""
PCEN Layer for Lasagne.
Author: Jan Schlüter, OFAI
"""
import numpy as np
import theano
@f0k
f0k / merge_ics.py
Created September 5, 2021 07:37
Merge and deduplicate .ics/.ical files
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Merges and deduplicates one or more .ics / ical files.
For usage information, call with --help.
Author: Jan Schlüter
"""
@f0k
f0k / batch_norm.py
Last active September 9, 2022 11:34
Batch Normalization for Lasagne
# -*- coding: utf-8 -*-
"""
Preliminary implementation of batch normalization for Lasagne.
Does not include a way to properly compute the normalization factors over the
full training set for testing, but can be used as a drop-in for training and
validation.
Author: Jan Schlüter
"""
@f0k
f0k / nvidia_boost.sh
Created December 6, 2017 17:45
Set Nvidia GPU application clocks and power limits to maximum supported values
#!/bin/bash
# Sets each CUDA device to persistence mode and sets the application clock
# and power limit to the device's maximum supported values.
# When run with "--dry-run" as first command line argument or not as superuser,
# will display the commands, otherwise it will execute them.
#
# Hint: To run this at boot time, place this script in /root and create a file
# /etc/cron.d/nvidia_boost with the following single line:
# @reboot root /root/nvidia_boost.sh >/dev/null
#
@f0k
f0k / rolling_median_bench.py
Last active December 22, 2022 08:49
rolling median implementations benchmark
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Compares some algorithms for computing a sliding median of an array.
Results:
scipy.signal.medfilt2d is a bit faster than scipy.ndimage.filter.median_filter
and significantly faster than scipy.signal.medfilt.
Maintaining a sorted list of the window becomes faster than that for a filter