Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Baque committed Jan 12, 2017
1 parent 906064d commit 120b2f7
Show file tree
Hide file tree
Showing 1,533 changed files with 1,183,620 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.so
.o
.dat
190 changes: 190 additions & 0 deletions .ipynb_checkpoints/KSP_notebook-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\n",
"sys.path.insert(0, '../')\n",
"\n",
"import matplotlib\n",
"matplotlib.use(\"nbagg\")\n",
"import skimage\n",
"import skimage.filters\n",
"import skimage.morphology\n",
"import math\n",
"import numpy.linalg as la\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import sklearn\n",
"import cv2\n",
"import scipy\n",
"import scipy.io as sio\n",
"import re, os, glob, pickle, shutil\n",
"from shutil import *\n",
"\n",
"import hickle as hkl\n",
"\n",
"\n",
"\n",
"import pandas as pd\n",
"\n",
"from random import randint\n",
"\n",
"from visualize import *\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"running build_ext\n",
"skipping 'kgraph.cpp' Cython extension (up-to-date)\n"
]
}
],
"source": [
"run setup.py build_ext -i"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from ksp import pyKShorthestPathGraph"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def get_fake():\n",
" out = np.zeros((37,36)) + 0.00001\n",
" out[15,15] = 0.99\n",
" out[10,20] = 0.99\n",
" \n",
" return out"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"\n",
"depth = 10\n",
"q_vector = np.zeros(37*36*depth)\n",
"\n",
"#Prepare flat vector for ksp\n",
"for t in range(0,depth):\n",
" #Q_loc = get_Q(t,M_ids[t])\n",
" Q_loc = get_fake()\n",
" flat_q = np.clip(np.ndarray.flatten(Q_loc),1e-6,0.999999)\n",
" q_vector[37*36*t:37*36*(t+1)] = -np.log(flat_q/(1-flat_q))\n",
" \n",
"access_points = np.asarray([0])\n",
"G = pyKShorthestPathGraph(q_vector,37,36,depth,3,access_points)\n",
"v = G.getPath(0,depth)\n",
"del G"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[555, 380, 555, 380, 555, 380, 555, 380, 555, 380, 555, 380, 555, 380, 555, 380, 555, 380, 555, 380, 1058, 0]\n"
]
}
],
"source": [
"print v"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"22\n"
]
}
],
"source": [
"555/36\n",
"print len(v)"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"print v.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
62 changes: 62 additions & 0 deletions pyKSP-Example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

import sys
sys.path.insert(0, 'pyKSP')

import numpy as np
import matplotlib.pyplot as plt


# Define a couple of usefull functions
def get_fake():
# To create fake tracks
out = np.zeros((37,36)) + 0.00001
out[10,10] = 0.99
out[20,20] = 0.99

return out

def convert_v(v,dims,depth):
# To convert the output of KSP into tracks format
MAP = np.zeros(dims)
n_tracks = len(v)/(depth)
out = np.zeros((depth,n_tracks,2))
for t in range(depth-1):
for i in range(n_tracks):
out[t,i,0] = v[t*n_tracks + i]/dims[1]
out[t,i,1] = v[t*n_tracks + i]%dims[1]

return np.int32(out)


# Import the wrapper
from ksp import pyKShorthestPathGraph

'''
We will need to create a pyKShorthestPathGraph object. The constructor takes the following inputs, which we are going to build:
- A flattened vector containing the costs of going through each grid location at each time step.
- The W and H dimensions of your grid here 36 and 37.
- The number of frames to be processed, called depth, here 10.
- The admissible radius for two consecutive detections of the same track.
- The access points of your grid, in flattened format as well. These are the points where tracks can enter and exit the grid.
'''

depth = 30 #Number of frames

# Prepare flat vector for ksp containing costs at each grid locations at each time step
q_vector = np.zeros(37*36*depth)
for t in range(0,depth):
Q_loc = get_fake()
flat_q = np.clip(np.ndarray.flatten(Q_loc),1e-6,0.999999)
q_vector[37*36*t:37*36*(t+1)] = -np.log(flat_q/(1-flat_q)) # Costs in -log() format

access_points = np.asarray([0]) # Define the access points on your grid
G = pyKShorthestPathGraph(q_vector,36,37,depth,4,access_points) #Be carefull ordering of dimensions inverted
v = G.getPath(0,depth-1) # From_frame - To_frame (inclusive). Be carrefull if you set To_frame>depth - 1, you get a memory leak
print v
del G


# Convert output to a "tracks" format
out = convert_v(v,(37,36),depth)
print out

27 changes: 27 additions & 0 deletions pyKSP/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
########################################################################
# (c) 2009-2011 Ecole Polytechnique Federale de Lausanne #
# All rights reserved. #
# #
# EPFL grants a non-exclusive and non-transferable license for non #
# commercial use of the Software for education and research purposes #
# only. Any other use of the Software is expressly excluded. #
# #
# Redistribution of the Software in source and binary forms, with or #
# without modification, is not permitted. #
# #
# Written by Engin Turetken and Jerome Berclaz. #
# #
# http://cvlab.epfl.ch/research/body/surv #
# Contact <[email protected]> for comments & bug reports. #
########################################################################

LDFLAGS=
CXXFLAGS=-O3 -msse2 -mfpmath=sse

all: ksp

ksp: ksp_graph.o ksp_computer.o main.o
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

clean:
$(RM) *.o *~ ksp
Loading

0 comments on commit 120b2f7

Please sign in to comment.