Posts about python

2017-10-25 Designing a A0 poster using matplotlib

Poster GDR Vision

This poster was presented in Lille at a vision workshop, check out http://invibe.net/LaurentPerrinet/Publications/Perrinet17gdr

Apart the content (which is in French) which recaps some previous work inbetween art and science, this post demonstrates how to generate a A0 poster programmatically. In particular, we will use matplotlib and some quickly forged functions to ease up the formatting.

Read more…

Comments

2017-10-06 Improving calls to the LogGabor library

To code image as edges, for instance in the SparseEdges sparse coding scheme, we use a model of edges in images. A good model for these edges are bidimensional Log Gabor filter. This is implemented for instance in the LogGabor library. The library was designed to be precise, but not particularly for efficiency. In order to improve its speed, we demonstrate here the use of a cache to avoid redundant computations.

Read more…

Comments

2017-09-20 The fastest 2D convolution in the world

Convolutions are essential components of any neural networks, image processing, computer vision ... but these are also a bottleneck in terms of computations... I will here benchmark different solutions using numpy, scipy or tensorflow. This is work-in-progress, so that any suggestion is welcome (for instance on StackExchange!

Read more…

Comments

2017-03-09 Some basics around probabilities

basics of probability theory

In the context of a course in Computational Neuroscience, I am teaching a basic introduction in Probabilities, Bayes and the Free-energy principle.

Let's learn to use probabilities in practice by generating some "synthetic data", that is by using the computer's number generator.

Read more…

Comments

2017-01-15 Bogacz (2017) A tutorial on free-energy

I enjoyed reading "A tutorial on the free-energy framework for modelling perception and learning" by Rafal Bogacz, which is freely available here. In particular, the author encourages to replicate the results in the paper. He is himself giving solutions in matlab, so I had to do the same in python all within a notebook...

Read more…

Comments

2016-11-29 Resizing a bunch of files using the command-line interface

generating databases

A set of bash code to resize images to a fixed size.

Problem statement: we have a set of images with heterogeneous sizes and we want to homogenize the database to avoid problems when classifying them. Solution: ImageMagick.

We first identify the size and type of images in the database. The database is a collection of folders containing each a collection of files. We thus do a nested recursive loop:

Read more…

Comments

2016-11-24 Using generators in Python

Let's explore generators and the yield statement in the python language...

Read more…

Comments

2016-11-17 Finding extremal values in a nd-array

Sometimes, you need to pick up the $N$-th extremal values in a mutli-dimensional matrix.

Let's suppose it is represented as a nd-array (here, I further suppose you are using the numpy library from the python language). Finding extremal values is easy with argsort but this function operated on 1d vectors... Juggling around indices is sometimes not such an easy task, but luckily, we have the unravel_index function.

Let's unwrap an easy solution combining these functions:

Read more…

Comments

2016-11-15 Saving and displaying movies and dynamic figures

It is insanely useful to create movies to illustrate a talk, blog post or just to include in a notebook:

In [1]:
from IPython.display import HTML
HTML('<center><video controls autoplay loop src="../files/noise.mp4" width=61.8%/></center>')
Out[1]:

For years I have used a custom made solution made around saving single frames and then calling ffmpeg to save that files to a movie file. That function (called anim_save had to be maintained accross different libraries to reflect new needs (going to WEBM and MP4 formats for instance). That made the code longer than necessary and had not its place in a scientific library.

Here, I show how to use the animation library from matplotlib to replace that

Read more…

Comments

2016-01-19 élasticité trames V1

L'installation Elasticité dynamique agit comme un filtre et génère de nouveaux espaces démultipliés, comme un empilement quasi infini d'horizons. Par principe de réflexion, la pièce absorbe l'image de l'environnement et accumule les points de vue ; le mouvement permanent requalifie continuellement ce qui est regardé et entendu.

On va maintenant utiliser des forces elastiques pour coordonner la dynamique des lames dans la trame.

Read more…

Comments