Generated by Cython 0.15.1 on Tue Jan 31 14:40:14 2012

Raw output: marginals.c

 1: from vision import convolution
  /* "vision/alearn/marginals.pyx":1
 * from vision import convolution             # <<<<<<<<<<<<<<
 * from vision import Box
 * from vision.track import interpolation
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__convolution));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__convolution));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__convolution));
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__vision), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__convolution); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__convolution, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "vision/alearn/marginals.pyx":1
 * from vision import convolution             # <<<<<<<<<<<<<<
 * from vision import Box
 * from vision.track import interpolation
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
 2: from vision import Box
  /* "vision/alearn/marginals.pyx":2
 * from vision import convolution
 * from vision import Box             # <<<<<<<<<<<<<<
 * from vision.track import interpolation
 * from vision.track import dp
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__Box));
  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__Box));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Box));
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__vision), ((PyObject *)__pyx_t_2), -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__Box); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Box, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 3: from vision.track import interpolation
  /* "vision/alearn/marginals.pyx":3
 * from vision import convolution
 * from vision import Box
 * from vision.track import interpolation             # <<<<<<<<<<<<<<
 * from vision.track import dp
 * from vision.model import PathModel
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__interpolation));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__interpolation));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__interpolation));
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s_56), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__interpolation); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__interpolation, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 4: from vision.track import dp
  /* "vision/alearn/marginals.pyx":4
 * from vision import Box
 * from vision.track import interpolation
 * from vision.track import dp             # <<<<<<<<<<<<<<
 * from vision.model import PathModel
 * import logging
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp));
  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__dp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp));
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s_56), ((PyObject *)__pyx_t_2), -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__dp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__dp, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 5: from vision.model import PathModel
  /* "vision/alearn/marginals.pyx":5
 * from vision.track import interpolation
 * from vision.track import dp
 * from vision.model import PathModel             # <<<<<<<<<<<<<<
 * import logging
 * import numpy
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__PathModel));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__PathModel));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__PathModel));
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s_57), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__PathModel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__PathModel, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 6: import logging
  /* "vision/alearn/marginals.pyx":6
 * from vision.track import dp
 * from vision.model import PathModel
 * import logging             # <<<<<<<<<<<<<<
 * import numpy
 * 
 */
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__logging), 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logging, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 7: import numpy
  /* "vision/alearn/marginals.pyx":7
 * from vision.model import PathModel
 * import logging
 * import numpy             # <<<<<<<<<<<<<<
 * 
 * cimport numpy
 */
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__numpy, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 8: 
 9: cimport numpy
 10: 
 11: from vision cimport annotations
 12: 
 13: cdef int debug = 1
  /* "vision/alearn/marginals.pyx":13
 * from vision cimport annotations
 * 
 * cdef int debug = 1             # <<<<<<<<<<<<<<
 * 
 * if debug:
 */
  __pyx_v_6vision_6alearn_9marginals_debug = 1;
 14: 
 15: if debug:
  /* "vision/alearn/marginals.pyx":15
 * cdef int debug = 1
 * 
 * if debug:             # <<<<<<<<<<<<<<
 *     import pylab
 * 
 */
  if (__pyx_v_6vision_6alearn_9marginals_debug) {
 16:     import pylab
    /* "vision/alearn/marginals.pyx":16
 * 
 * if debug:
 *     import pylab             # <<<<<<<<<<<<<<
 * 
 * logger = logging.getLogger("vision.alearn.marginals")
 */
    __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__pylab), 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s__pylab, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;
 17: 
 18: logger = logging.getLogger("vision.alearn.marginals")
  /* "vision/alearn/marginals.pyx":18
 *     import pylab
 * 
 * logger = logging.getLogger("vision.alearn.marginals")             # <<<<<<<<<<<<<<
 * 
 * cdef extern from "math.h":
 */
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logging); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__getLogger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_58), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logger, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 19: 
 20: cdef extern from "math.h":
 21:     float exp(float n)
 22: 
 23: cdef double Infinity = 1e300
  /* "vision/alearn/marginals.pyx":23
 *     float exp(float n)
 * 
 * cdef double Infinity = 1e300             # <<<<<<<<<<<<<<
 * 
 * def pick(givens, images, last = None,
 */
  __pyx_v_6vision_6alearn_9marginals_Infinity = 1e300;
 24: 
 25: def pick(givens, images, last = None,
/* "vision/alearn/marginals.pyx":25
 * cdef double Infinity = 1e300
 * 
 * def pick(givens, images, last = None,             # <<<<<<<<<<<<<<
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),
 */

static PyObject *__pyx_pf_6vision_6alearn_9marginals_pick(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6vision_6alearn_9marginals_pick[] = "pick(givens, images, last=None, pairwisecost=0.001, upperthreshold=10, lowerthreshold=-100, sigma=0.1, erroroverlap=0.5, skip=3, dim=(40, 40), rgbbin=8, hogbin=8, c=1, clickradius=10, pool=None)";
static PyMethodDef __pyx_mdef_6vision_6alearn_9marginals_pick = {__Pyx_NAMESTR("pick"), (PyCFunction)__pyx_pf_6vision_6alearn_9marginals_pick, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6vision_6alearn_9marginals_pick)};
static PyObject *__pyx_pf_6vision_6alearn_9marginals_pick(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct__pick *__pyx_cur_scope;
  PyObject *__pyx_v_givens = 0;
  PyObject *__pyx_v_images = 0;
  PyObject *__pyx_v_last = 0;
  PyObject *__pyx_v_pairwisecost = 0;
  PyObject *__pyx_v_upperthreshold = 0;
  PyObject *__pyx_v_lowerthreshold = 0;
  PyObject *__pyx_v_sigma = 0;
  PyObject *__pyx_v_erroroverlap = 0;
  PyObject *__pyx_v_skip = 0;
  PyObject *__pyx_v_dim = 0;
  PyObject *__pyx_v_rgbbin = 0;
  PyObject *__pyx_v_hogbin = 0;
  PyObject *__pyx_v_c = 0;
  PyObject *__pyx_v_clickradius = 0;
  PyObject *__pyx_v_pool = 0;
  PyObject *__pyx_v_model = NULL;
  PyObject *__pyx_v_fullpath = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  PyObject *__pyx_v_marginals = NULL;
  PyObject *__pyx_v_path = NULL;
  PyObject *__pyx_v_best = NULL;
  PyObject *__pyx_r = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__givens,&__pyx_n_s__images,&__pyx_n_s__last,&__pyx_n_s__pairwisecost,&__pyx_n_s__upperthreshold,&__pyx_n_s__lowerthreshold,&__pyx_n_s__sigma,&__pyx_n_s__erroroverlap,&__pyx_n_s__skip,&__pyx_n_s__dim,&__pyx_n_s__rgbbin,&__pyx_n_s__hogbin,&__pyx_n_s__c,&__pyx_n_s__clickradius,&__pyx_n_s__pool,0};
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("pick");
  __pyx_cur_scope = (struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct__pick *)__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct__pick->tp_new(__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct__pick, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_self = __pyx_self;
  {
    PyObject* values[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    values[2] = ((PyObject *)Py_None);
    values[3] = __pyx_k_1;
    values[4] = ((PyObject *)__pyx_int_10);
    values[5] = ((PyObject *)__pyx_int_neg_100);
    values[6] = __pyx_k_2;
    values[7] = __pyx_k_3;
    values[8] = ((PyObject *)__pyx_int_3);

  /* "vision/alearn/marginals.pyx":25
 * cdef double Infinity = 1e300
 * 
 * def pick(givens, images, last = None,             # <<<<<<<<<<<<<<
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6vision_6alearn_9marginals_pick, NULL, __pyx_n_s_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__pick, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "vision/alearn/marginals.pyx":25
 * cdef double Infinity = 1e300
 * 
 * def pick(givens, images, last = None,             # <<<<<<<<<<<<<<
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),
 */
struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct__pick {
  PyObject_HEAD
  PyObject *__pyx_v_fullmarginals;
};

 26:          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
  /* "vision/alearn/marginals.pyx":26
 * 
 * def pick(givens, images, last = None,
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,             # <<<<<<<<<<<<<<
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),
 *          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):
 */
  __pyx_t_2 = PyFloat_FromDouble(0.001); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_1 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
 27:          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),
    /* "vision/alearn/marginals.pyx":27
 * def pick(givens, images, last = None,
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),             # <<<<<<<<<<<<<<
 *          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):
 * 
 */
    values[9] = ((PyObject *)__pyx_k_tuple_4);
    values[10] = ((PyObject *)__pyx_int_8);
    values[11] = ((PyObject *)__pyx_int_8);
    values[12] = ((PyObject *)__pyx_int_1);
    values[13] = ((PyObject *)__pyx_int_10);

  /* "vision/alearn/marginals.pyx":27
 * def pick(givens, images, last = None,
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),             # <<<<<<<<<<<<<<
 *          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):
 * 
 */
  __pyx_k_tuple_4 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4));
  __Pyx_INCREF(__pyx_int_40);
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, __pyx_int_40);
  __Pyx_GIVEREF(__pyx_int_40);
  __Pyx_INCREF(__pyx_int_40);
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 1, __pyx_int_40);
  __Pyx_GIVEREF(__pyx_int_40);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));

  /* "vision/alearn/marginals.pyx":27
 * def pick(givens, images, last = None,
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),             # <<<<<<<<<<<<<<
 *          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):
 * 
 */
  __pyx_t_2 = PyFloat_FromDouble(.1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_2 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_3 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
 28:          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):
    /* "vision/alearn/marginals.pyx":28
 *          pairwisecost = 0.001, upperthreshold = 10, lowerthreshold = -100,
 *          sigma = .1, erroroverlap = 0.5, skip = 3, dim = (40, 40),
 *          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):             # <<<<<<<<<<<<<<
 * 
 *     givens.sort(key = lambda x: x.frame)
 */
    values[14] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__givens);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__images);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("pick", 0, 2, 15, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__last);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pairwisecost);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__upperthreshold);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lowerthreshold);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sigma);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__erroroverlap);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__skip);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dim);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__rgbbin);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hogbin);
          if (value) { values[11] = value; kw_args--; }
        }
        case 12:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__c);
          if (value) { values[12] = value; kw_args--; }
        }
        case 13:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__clickradius);
          if (value) { values[13] = value; kw_args--; }
        }
        case 14:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pool);
          if (value) { values[14] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "pick") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_givens = values[0];
    __pyx_v_images = values[1];
    __pyx_v_last = values[2];
    __pyx_v_pairwisecost = values[3];
    __pyx_v_upperthreshold = values[4];
    __pyx_v_lowerthreshold = values[5];
    __pyx_v_sigma = values[6];
    __pyx_v_erroroverlap = values[7];
    __pyx_v_skip = values[8];
    __pyx_v_dim = values[9];
    __pyx_v_rgbbin = values[10];
    __pyx_v_hogbin = values[11];
    __pyx_v_c = values[12];
    __pyx_v_clickradius = values[13];
    __pyx_v_pool = values[14];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pick", 0, 2, 15, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("vision.alearn.marginals.pick", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
 29: 
 30:     givens.sort(key = lambda x: x.frame)
/* "vision/alearn/marginals.pyx":30
 *          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):
 * 
 *     givens.sort(key = lambda x: x.frame)             # <<<<<<<<<<<<<<
 * 
 *     model = PathModel(images, givens, rgbbin = rgbbin, hogbin = hogbin, c = c)
 */

static PyObject *__pyx_lambda_funcdef_lambda1(PyObject *__pyx_self, PyObject *__pyx_v_x); /*proto*/
static PyMethodDef __pyx_lambda_methdef_lambda1 = {__Pyx_NAMESTR("lambda1"), (PyCFunction)__pyx_lambda_funcdef_lambda1, METH_O, __Pyx_DOCSTR(0)};
static PyObject *__pyx_lambda_funcdef_lambda1(PyObject *__pyx_self, PyObject *__pyx_v_x) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("lambda1");
  __pyx_self = __pyx_self;
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_x, __pyx_n_s__frame); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("vision.alearn.marginals.pick.lambda1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_6vision_6alearn_9marginals_4pick_1generator(struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_1_genexpr *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */

  /* "vision/alearn/marginals.pyx":30
 *          rgbbin = 8, hogbin = 8, c = 1, clickradius = 10, pool = None):
 * 
 *     givens.sort(key = lambda x: x.frame)             # <<<<<<<<<<<<<<
 * 
 *     model = PathModel(images, givens, rgbbin = rgbbin, hogbin = hogbin, c = c)
 */
  __pyx_t_1 = PyObject_GetAttr(__pyx_v_givens, __pyx_n_s__sort); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_3 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_lambda_methdef_lambda1, NULL, __pyx_n_s_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__key), __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 31: 
 32:     model = PathModel(images, givens, rgbbin = rgbbin, hogbin = hogbin, c = c)
  /* "vision/alearn/marginals.pyx":32
 *     givens.sort(key = lambda x: x.frame)
 * 
 *     model = PathModel(images, givens, rgbbin = rgbbin, hogbin = hogbin, c = c)             # <<<<<<<<<<<<<<
 * 
 *     fullpath = []
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__PathModel); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_INCREF(__pyx_v_images);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_images);
  __Pyx_GIVEREF(__pyx_v_images);
  __Pyx_INCREF(__pyx_v_givens);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_givens);
  __Pyx_GIVEREF(__pyx_v_givens);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rgbbin), __pyx_v_rgbbin) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__hogbin), __pyx_v_hogbin) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__c), __pyx_v_c) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyEval_CallObjectWithKeywords(__pyx_t_3, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_v_model = __pyx_t_4;
  __pyx_t_4 = 0;
 33: 
 34:     fullpath = []
  /* "vision/alearn/marginals.pyx":34
 *     model = PathModel(images, givens, rgbbin = rgbbin, hogbin = hogbin, c = c)
 * 
 *     fullpath = []             # <<<<<<<<<<<<<<
 *     fullmarginals = []
 *     for x, y in zip(givens, givens[1:]):
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_v_fullpath = __pyx_t_4;
  __pyx_t_4 = 0;
 35:     fullmarginals = []
  /* "vision/alearn/marginals.pyx":35
 * 
 *     fullpath = []
 *     fullmarginals = []             # <<<<<<<<<<<<<<
 *     for x, y in zip(givens, givens[1:]):
 *         if x.frame == y.frame:
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
  __pyx_cur_scope->__pyx_v_fullmarginals = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
 36:     for x, y in zip(givens, givens[1:]):
  /* "vision/alearn/marginals.pyx":36
 *     fullpath = []
 *     fullmarginals = []
 *     for x, y in zip(givens, givens[1:]):             # <<<<<<<<<<<<<<
 *         if x.frame == y.frame:
 *             raise RuntimeError("Frame {0} appears twice".format(x.frame))
 */
  __pyx_t_4 = __Pyx_PySequence_GetSlice(__pyx_v_givens, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __Pyx_INCREF(__pyx_v_givens);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_givens);
  __Pyx_GIVEREF(__pyx_v_givens);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_builtin_zip, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_1 = __pyx_t_4; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++;
    } else if (PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++;
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      if (likely(PyTuple_CheckExact(sequence))) {
        if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
          if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
          if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
      index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L8_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L8_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L9_unpacking_done;
      __pyx_L8_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
      if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L9_unpacking_done:;
    }
    __Pyx_XDECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_2;
    __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_v_y);
    __pyx_v_y = __pyx_t_3;
    __pyx_t_3 = 0;
 37:         if x.frame == y.frame:
    /* "vision/alearn/marginals.pyx":37
 *     fullmarginals = []
 *     for x, y in zip(givens, givens[1:]):
 *         if x.frame == y.frame:             # <<<<<<<<<<<<<<
 *             raise RuntimeError("Frame {0} appears twice".format(x.frame))
 *         logger.info("Scoring {0} to {1}".format(x.frame, y.frame))
 */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_x, __pyx_n_s__frame); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_y, __pyx_n_s__frame); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_9) {
 38:             raise RuntimeError("Frame {0} appears twice".format(x.frame))
      /* "vision/alearn/marginals.pyx":38
 *     for x, y in zip(givens, givens[1:]):
 *         if x.frame == y.frame:
 *             raise RuntimeError("Frame {0} appears twice".format(x.frame))             # <<<<<<<<<<<<<<
 *         logger.info("Scoring {0} to {1}".format(x.frame, y.frame))
 *         marginals, path = picksegment(x, y, model, images, pairwisecost,
 */
      __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_6), __pyx_n_s__format); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyObject_GetAttr(__pyx_v_x, __pyx_n_s__frame); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_4));
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L10;
    }
    __pyx_L10:;
 39:         logger.info("Scoring {0} to {1}".format(x.frame, y.frame))
    /* "vision/alearn/marginals.pyx":39
 *         if x.frame == y.frame:
 *             raise RuntimeError("Frame {0} appears twice".format(x.frame))
 *         logger.info("Scoring {0} to {1}".format(x.frame, y.frame))             # <<<<<<<<<<<<<<
 *         marginals, path = picksegment(x, y, model, images, pairwisecost,
 *                                         upperthreshold, lowerthreshold,
 */
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__format); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_x, __pyx_n_s__frame); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = PyObject_GetAttr(__pyx_v_y, __pyx_n_s__frame); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_2 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 40:         marginals, path = picksegment(x, y, model, images, pairwisecost,
    /* "vision/alearn/marginals.pyx":40
 *             raise RuntimeError("Frame {0} appears twice".format(x.frame))
 *         logger.info("Scoring {0} to {1}".format(x.frame, y.frame))
 *         marginals, path = picksegment(x, y, model, images, pairwisecost,             # <<<<<<<<<<<<<<
 *                                         upperthreshold, lowerthreshold,
 *                                         sigma, erroroverlap,
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__picksegment); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);

    /* "vision/alearn/marginals.pyx":40
 *             raise RuntimeError("Frame {0} appears twice".format(x.frame))
 *         logger.info("Scoring {0} to {1}".format(x.frame, y.frame))
 *         marginals, path = picksegment(x, y, model, images, pairwisecost,             # <<<<<<<<<<<<<<
 *                                         upperthreshold, lowerthreshold,
 *                                         sigma, erroroverlap,
 */
    __Pyx_XDECREF(__pyx_v_marginals);
    __pyx_v_marginals = __pyx_t_10;
    __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_v_path);
    __pyx_v_path = __pyx_t_7;
    __pyx_t_7 = 0;
 41:                                         upperthreshold, lowerthreshold,
 42:                                         sigma, erroroverlap,
 43:                                         skip, clickradius, pool)
    /* "vision/alearn/marginals.pyx":43
 *                                         upperthreshold, lowerthreshold,
 *                                         sigma, erroroverlap,
 *                                         skip, clickradius, pool)             # <<<<<<<<<<<<<<
 *         fullpath.extend(path[:-1])
 *         fullmarginals.extend(marginals[:-1])
 */
    __pyx_t_10 = PyTuple_New(12); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    __Pyx_INCREF(__pyx_v_x);
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_x);
    __Pyx_GIVEREF(__pyx_v_x);
    __Pyx_INCREF(__pyx_v_y);
    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_y);
    __Pyx_GIVEREF(__pyx_v_y);
    __Pyx_INCREF(__pyx_v_model);
    PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_model);
    __Pyx_GIVEREF(__pyx_v_model);
    __Pyx_INCREF(__pyx_v_images);
    PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_v_images);
    __Pyx_GIVEREF(__pyx_v_images);
    __Pyx_INCREF(__pyx_v_pairwisecost);
    PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_v_pairwisecost);
    __Pyx_GIVEREF(__pyx_v_pairwisecost);
    __Pyx_INCREF(__pyx_v_upperthreshold);
    PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_v_upperthreshold);
    __Pyx_GIVEREF(__pyx_v_upperthreshold);
    __Pyx_INCREF(__pyx_v_lowerthreshold);
    PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_v_lowerthreshold);
    __Pyx_GIVEREF(__pyx_v_lowerthreshold);
    __Pyx_INCREF(__pyx_v_sigma);
    PyTuple_SET_ITEM(__pyx_t_10, 7, __pyx_v_sigma);
    __Pyx_GIVEREF(__pyx_v_sigma);
    __Pyx_INCREF(__pyx_v_erroroverlap);
    PyTuple_SET_ITEM(__pyx_t_10, 8, __pyx_v_erroroverlap);
    __Pyx_GIVEREF(__pyx_v_erroroverlap);
    __Pyx_INCREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_10, 9, __pyx_v_skip);
    __Pyx_GIVEREF(__pyx_v_skip);
    __Pyx_INCREF(__pyx_v_clickradius);
    PyTuple_SET_ITEM(__pyx_t_10, 10, __pyx_v_clickradius);
    __Pyx_GIVEREF(__pyx_v_clickradius);
    __Pyx_INCREF(__pyx_v_pool);
    PyTuple_SET_ITEM(__pyx_t_10, 11, __pyx_v_pool);
    __Pyx_GIVEREF(__pyx_v_pool);
    __pyx_t_4 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      if (likely(PyTuple_CheckExact(sequence))) {
        if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
          if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
          if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_3 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext;
      index = 0; __pyx_t_10 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_10)) goto __pyx_L11_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_10);
      index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_3), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L12_unpacking_done;
      __pyx_L11_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
      if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L12_unpacking_done:;
    }
 44:         fullpath.extend(path[:-1])
    /* "vision/alearn/marginals.pyx":44
 *                                         sigma, erroroverlap,
 *                                         skip, clickradius, pool)
 *         fullpath.extend(path[:-1])             # <<<<<<<<<<<<<<
 *         fullmarginals.extend(marginals[:-1])
 * 
 */
    __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_fullpath), __pyx_n_s__extend); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PySequence_GetSlice(__pyx_v_path, 0, -1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 45:         fullmarginals.extend(marginals[:-1])
    /* "vision/alearn/marginals.pyx":45
 *                                         skip, clickradius, pool)
 *         fullpath.extend(path[:-1])
 *         fullmarginals.extend(marginals[:-1])             # <<<<<<<<<<<<<<
 * 
 *     if last is not None and last >= givens[-1].frame:
 */
    __pyx_t_7 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_fullmarginals, __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = __Pyx_PySequence_GetSlice(__pyx_v_marginals, 0, -1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 46: 
 47:     if last is not None and last >= givens[-1].frame:
  /* "vision/alearn/marginals.pyx":47
 *         fullmarginals.extend(marginals[:-1])
 * 
 *     if last is not None and last >= givens[-1].frame:             # <<<<<<<<<<<<<<
 *         logger.info("Scoring {0} to last at {1}".format(givens[-1].frame, last))
 *         marginals, path = picksegment(givens[-1], last, model, images,
 */
  __pyx_t_9 = (__pyx_v_last != Py_None);
  if (__pyx_t_9) {
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_givens, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__frame); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_last, __pyx_t_10, Py_GE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_12 = __pyx_t_11;
  } else {
    __pyx_t_12 = __pyx_t_9;
  }
  if (__pyx_t_12) {
 48:         logger.info("Scoring {0} to last at {1}".format(givens[-1].frame, last))
    /* "vision/alearn/marginals.pyx":48
 * 
 *     if last is not None and last >= givens[-1].frame:
 *         logger.info("Scoring {0} to last at {1}".format(givens[-1].frame, last))             # <<<<<<<<<<<<<<
 *         marginals, path = picksegment(givens[-1], last, model, images,
 *                                       pairwisecost, upperthreshold,
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_8), __pyx_n_s__format); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_givens, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__frame); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_last);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_last);
    __Pyx_GIVEREF(__pyx_v_last);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 49:         marginals, path = picksegment(givens[-1], last, model, images,
    /* "vision/alearn/marginals.pyx":49
 *     if last is not None and last >= givens[-1].frame:
 *         logger.info("Scoring {0} to last at {1}".format(givens[-1].frame, last))
 *         marginals, path = picksegment(givens[-1], last, model, images,             # <<<<<<<<<<<<<<
 *                                       pairwisecost, upperthreshold,
 *                                       lowerthreshold, sigma,
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__picksegment); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_givens, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "vision/alearn/marginals.pyx":49
 *     if last is not None and last >= givens[-1].frame:
 *         logger.info("Scoring {0} to last at {1}".format(givens[-1].frame, last))
 *         marginals, path = picksegment(givens[-1], last, model, images,             # <<<<<<<<<<<<<<
 *                                       pairwisecost, upperthreshold,
 *                                       lowerthreshold, sigma,
 */
    __Pyx_XDECREF(__pyx_v_marginals);
    __pyx_v_marginals = __pyx_t_10;
    __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_v_path);
    __pyx_v_path = __pyx_t_7;
    __pyx_t_7 = 0;
 50:                                       pairwisecost, upperthreshold,
 51:                                       lowerthreshold, sigma,
 52:                                       erroroverlap, skip, clickradius, pool)
    /* "vision/alearn/marginals.pyx":52
 *                                       pairwisecost, upperthreshold,
 *                                       lowerthreshold, sigma,
 *                                       erroroverlap, skip, clickradius, pool)             # <<<<<<<<<<<<<<
 *         fullpath.extend(path[:-1])
 *         fullmarginals.extend(marginals)
 */
    __pyx_t_10 = PyTuple_New(12); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_last);
    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_last);
    __Pyx_GIVEREF(__pyx_v_last);
    __Pyx_INCREF(__pyx_v_model);
    PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_model);
    __Pyx_GIVEREF(__pyx_v_model);
    __Pyx_INCREF(__pyx_v_images);
    PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_v_images);
    __Pyx_GIVEREF(__pyx_v_images);
    __Pyx_INCREF(__pyx_v_pairwisecost);
    PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_v_pairwisecost);
    __Pyx_GIVEREF(__pyx_v_pairwisecost);
    __Pyx_INCREF(__pyx_v_upperthreshold);
    PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_v_upperthreshold);
    __Pyx_GIVEREF(__pyx_v_upperthreshold);
    __Pyx_INCREF(__pyx_v_lowerthreshold);
    PyTuple_SET_ITEM(__pyx_t_10, 6, __pyx_v_lowerthreshold);
    __Pyx_GIVEREF(__pyx_v_lowerthreshold);
    __Pyx_INCREF(__pyx_v_sigma);
    PyTuple_SET_ITEM(__pyx_t_10, 7, __pyx_v_sigma);
    __Pyx_GIVEREF(__pyx_v_sigma);
    __Pyx_INCREF(__pyx_v_erroroverlap);
    PyTuple_SET_ITEM(__pyx_t_10, 8, __pyx_v_erroroverlap);
    __Pyx_GIVEREF(__pyx_v_erroroverlap);
    __Pyx_INCREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_10, 9, __pyx_v_skip);
    __Pyx_GIVEREF(__pyx_v_skip);
    __Pyx_INCREF(__pyx_v_clickradius);
    PyTuple_SET_ITEM(__pyx_t_10, 10, __pyx_v_clickradius);
    __Pyx_GIVEREF(__pyx_v_clickradius);
    __Pyx_INCREF(__pyx_v_pool);
    PyTuple_SET_ITEM(__pyx_t_10, 11, __pyx_v_pool);
    __Pyx_GIVEREF(__pyx_v_pool);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      if (likely(PyTuple_CheckExact(sequence))) {
        if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
          if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
          if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_1 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext;
      index = 0; __pyx_t_10 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_10)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_10);
      index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_1); if (unlikely(!__pyx_t_7)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_1), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L15_unpacking_done;
      __pyx_L14_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
      if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L15_unpacking_done:;
    }
 53:         fullpath.extend(path[:-1])
    /* "vision/alearn/marginals.pyx":53
 *                                       lowerthreshold, sigma,
 *                                       erroroverlap, skip, clickradius, pool)
 *         fullpath.extend(path[:-1])             # <<<<<<<<<<<<<<
 *         fullmarginals.extend(marginals)
 * 
 */
    __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_fullpath), __pyx_n_s__extend); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PySequence_GetSlice(__pyx_v_path, 0, -1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 54:         fullmarginals.extend(marginals)
    /* "vision/alearn/marginals.pyx":54
 *                                       erroroverlap, skip, clickradius, pool)
 *         fullpath.extend(path[:-1])
 *         fullmarginals.extend(marginals)             # <<<<<<<<<<<<<<
 * 
 *     if debug:
 */
    __pyx_t_7 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_fullmarginals, __pyx_n_s__extend); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    __Pyx_INCREF(__pyx_v_marginals);
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_marginals);
    __Pyx_GIVEREF(__pyx_v_marginals);
    __pyx_t_4 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L13;
  }
  __pyx_L13:;
 55: 
 56:     if debug:
  /* "vision/alearn/marginals.pyx":56
 *         fullmarginals.extend(marginals)
 * 
 *     if debug:             # <<<<<<<<<<<<<<
 *         pylab.plot([x[1] for x in fullmarginals],
 *                    [x[0] for x in fullmarginals])
 */
  if (__pyx_v_6vision_6alearn_9marginals_debug) {
 57:         pylab.plot([x[1] for x in fullmarginals],
    /* "vision/alearn/marginals.pyx":57
 * 
 *     if debug:
 *         pylab.plot([x[1] for x in fullmarginals],             # <<<<<<<<<<<<<<
 *                    [x[0] for x in fullmarginals])
 *         pylab.grid()
 */
    __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_10 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__plot); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_fullmarginals) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_fullmarginals)) {
      __pyx_t_7 = __pyx_cur_scope->__pyx_v_fullmarginals; __Pyx_INCREF(__pyx_t_7); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_fullmarginals); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext;
    }
    for (;;) {
      if (PyList_CheckExact(__pyx_t_7)) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_7)) break;
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
      } else if (PyTuple_CheckExact(__pyx_t_7)) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++;
      } else {
        __pyx_t_1 = __pyx_t_6(__pyx_t_7);
        if (unlikely(!__pyx_t_1)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF(__pyx_v_x);
      __pyx_v_x = __pyx_t_1;
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_x, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      if (unlikely(PyList_Append(__pyx_t_4, (PyObject*)__pyx_t_1))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 58:                    [x[0] for x in fullmarginals])
    /* "vision/alearn/marginals.pyx":58
 *     if debug:
 *         pylab.plot([x[1] for x in fullmarginals],
 *                    [x[0] for x in fullmarginals])             # <<<<<<<<<<<<<<
 *         pylab.grid()
 *         pylab.savefig("tmp/scoreplot.png")
 */
    __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_fullmarginals) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_fullmarginals)) {
      __pyx_t_1 = __pyx_cur_scope->__pyx_v_fullmarginals; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_fullmarginals); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext;
    }
    for (;;) {
      if (PyList_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++;
      } else if (PyTuple_CheckExact(__pyx_t_1)) {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++;
      } else {
        __pyx_t_3 = __pyx_t_6(__pyx_t_1);
        if (unlikely(!__pyx_t_3)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_XDECREF(__pyx_v_x);
      __pyx_v_x = __pyx_t_3;
      __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_x, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      if (unlikely(PyList_Append(__pyx_t_7, (PyObject*)__pyx_t_3))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __Pyx_INCREF(((PyObject *)__pyx_t_4));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_4));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_4));
    __Pyx_INCREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_t_7));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 59:         pylab.grid()
    /* "vision/alearn/marginals.pyx":59
 *         pylab.plot([x[1] for x in fullmarginals],
 *                    [x[0] for x in fullmarginals])
 *         pylab.grid()             # <<<<<<<<<<<<<<
 *         pylab.savefig("tmp/scoreplot.png")
 * 
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__grid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 60:         pylab.savefig("tmp/scoreplot.png")
    /* "vision/alearn/marginals.pyx":60
 *                    [x[0] for x in fullmarginals])
 *         pylab.grid()
 *         pylab.savefig("tmp/scoreplot.png")             # <<<<<<<<<<<<<<
 * 
 *     best = max(fullmarginals)
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__savefig); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L16;
  }
  __pyx_L16:;

  /* "vision/alearn/marginals.pyx":60
 *                    [x[0] for x in fullmarginals])
 *         pylab.grid()
 *         pylab.savefig("tmp/scoreplot.png")             # <<<<<<<<<<<<<<
 * 
 *     best = max(fullmarginals)
 */
  __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_9));
  PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_kp_s_9));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));
 61: 
 62:     best = max(fullmarginals)
  /* "vision/alearn/marginals.pyx":62
 *         pylab.savefig("tmp/scoreplot.png")
 * 
 *     best = max(fullmarginals)             # <<<<<<<<<<<<<<
 *     marginals = dict((x[1], x[0]) for x in fullmarginals)
 * 
 */
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_7));
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_fullmarginals);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_cur_scope->__pyx_v_fullmarginals);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_fullmarginals);
  __pyx_t_1 = PyObject_Call(__pyx_builtin_max, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
  __pyx_v_best = __pyx_t_1;
  __pyx_t_1 = 0;
 63:     marginals = dict((x[1], x[0]) for x in fullmarginals)
/* "vision/alearn/marginals.pyx":63
 * 
 *     best = max(fullmarginals)
 *     marginals = dict((x[1], x[0]) for x in fullmarginals)             # <<<<<<<<<<<<<<
 * 
 *     return best[1], best[0], fullpath, marginals
 */

static PyObject *__pyx_pf_6vision_6alearn_9marginals_4pick_genexpr(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6vision_6alearn_9marginals_4pick_genexpr(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_1_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr");
  __pyx_cur_scope = (struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_1_genexpr *)__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct_1_genexpr->tp_new(__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct__pick *)__pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  __pyx_self = __pyx_self;
  __pyx_cur_scope->__pyx_base.resume_label = 0;
  __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_6vision_6alearn_9marginals_4pick_1generator;
  __Pyx_GIVEREF(__pyx_cur_scope);
  __Pyx_RefNannyFinishContext();
  return (PyObject *) __pyx_cur_scope;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_6vision_6alearn_9marginals_4pick_1generator(struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_1_genexpr *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
{
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None");
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fullmarginals)) { __Pyx_RaiseClosureNameError("fullmarginals"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fullmarginals) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fullmarginals)) {
    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_fullmarginals; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_fullmarginals); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  for (;;) {
    if (PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++;
    } else if (PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++;
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_cur_scope->__pyx_v_x = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_4 = 0;
    __pyx_t_5 = 0;
    __pyx_r = ((PyObject *)__pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_3;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_cur_scope->__pyx_base.resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_cur_scope->__pyx_base.resume_label = -1;
  __Pyx_RefNannyFinishContext();
  return NULL;
}

  /* "vision/alearn/marginals.pyx":63
 * 
 *     best = max(fullmarginals)
 *     marginals = dict((x[1], x[0]) for x in fullmarginals)             # <<<<<<<<<<<<<<
 * 
 *     return best[1], best[0], fullpath, marginals
 */
  __pyx_t_1 = __pyx_pf_6vision_6alearn_9marginals_4pick_genexpr(((PyObject*)__pyx_cur_scope), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_7));
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
  __Pyx_XDECREF(__pyx_v_marginals);
  __pyx_v_marginals = __pyx_t_1;
  __pyx_t_1 = 0;

/* "vision/alearn/marginals.pyx":63
 * 
 *     best = max(fullmarginals)
 *     marginals = dict((x[1], x[0]) for x in fullmarginals)             # <<<<<<<<<<<<<<
 * 
 *     return best[1], best[0], fullpath, marginals
 */
struct __pyx_Generator_object {
  PyObject_HEAD
  __pyx_generator_body_t body;
  int is_running;
  int resume_label;
  PyObject *exc_type;
  PyObject *exc_value;
  PyObject *exc_traceback;
};

 64: 
 65:     return best[1], best[0], fullpath, marginals
  /* "vision/alearn/marginals.pyx":65
 *     marginals = dict((x[1], x[0]) for x in fullmarginals)
 * 
 *     return best[1], best[0], fullpath, marginals             # <<<<<<<<<<<<<<
 * 
 * def picksegment(start, stop, model, images,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_best, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_best, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_10 = PyTuple_New(4); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_10));
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)__pyx_v_fullpath));
  PyTuple_SET_ITEM(__pyx_t_10, 2, ((PyObject *)__pyx_v_fullpath));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fullpath));
  __Pyx_INCREF(__pyx_v_marginals);
  PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_v_marginals);
  __Pyx_GIVEREF(__pyx_v_marginals);
  __pyx_t_1 = 0;
  __pyx_t_7 = 0;
  __pyx_r = ((PyObject *)__pyx_t_10);
  __pyx_t_10 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("vision.alearn.marginals.pick", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_model);
  __Pyx_XDECREF(__pyx_v_fullpath);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_XDECREF(__pyx_v_marginals);
  __Pyx_XDECREF(__pyx_v_path);
  __Pyx_XDECREF(__pyx_v_best);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_6vision_6alearn_9marginals_11picksegment_1generator1(struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_3_genexpr *__pyx_cur_scope, PyObject *__pyx_sent_value); /* proto */
 66: 
 67: def picksegment(start, stop, model, images,
/* "vision/alearn/marginals.pyx":67
 *     return best[1], best[0], fullpath, marginals
 * 
 * def picksegment(start, stop, model, images,             # <<<<<<<<<<<<<<
 *                pairwisecost = 0.001, upperthreshold = 10,
 *                lowerthreshold = -100, sigma = .1, erroroverlap = 0.5, skip = 3,
 */

static PyObject *__pyx_pf_6vision_6alearn_9marginals_1picksegment(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6vision_6alearn_9marginals_1picksegment[] = "picksegment(start, stop, model, images, pairwisecost=0.001, upperthreshold=10, lowerthreshold=-100, sigma=0.1, erroroverlap=0.5, skip=3, clickradius=10, pool=None)";
static PyMethodDef __pyx_mdef_6vision_6alearn_9marginals_1picksegment = {__Pyx_NAMESTR("picksegment"), (PyCFunction)__pyx_pf_6vision_6alearn_9marginals_1picksegment, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6vision_6alearn_9marginals_1picksegment)};
static PyObject *__pyx_pf_6vision_6alearn_9marginals_1picksegment(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_2_picksegment *__pyx_cur_scope;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_model = 0;
  PyObject *__pyx_v_images = 0;
  PyObject *__pyx_v_pairwisecost = 0;
  PyObject *__pyx_v_upperthreshold = 0;
  PyObject *__pyx_v_lowerthreshold = 0;
  PyObject *__pyx_v_sigma = 0;
  PyObject *__pyx_v_erroroverlap = 0;
  PyObject *__pyx_v_skip = 0;
  PyObject *__pyx_v_clickradius = 0;
  PyObject *__pyx_v_pool = 0;
  PyObject *__pyx_v_mapper = NULL;
  PyObject *__pyx_v_imagesize = NULL;
  PyObject *__pyx_v_stopframe = NULL;
  int __pyx_v_constrained;
  PyObject *__pyx_v_constraints = NULL;
  PyObject *__pyx_v_stopxtl = NULL;
  PyObject *__pyx_v_stopytl = NULL;
  PyObject *__pyx_v_frames = NULL;
  PyObject *__pyx_v_orders = NULL;
  PyObject *__pyx_v_costs = NULL;
  PyObject *__pyx_v_forwardsargs = NULL;
  PyObject *__pyx_v_backwardsargs = NULL;
  PyObject *__pyx_v_forwards = NULL;
  PyObject *__pyx_v_backwards = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  PyObject *__pyx_v_frame = NULL;
  PyObject *__pyx_v_pathdict = NULL;
  PyObject *__pyx_v_forwarderror = NULL;
  PyObject *__pyx_v_backwarderror = NULL;
  PyObject *__pyx_v_marginals = NULL;
  PyObject *__pyx_r = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__stop,&__pyx_n_s__model,&__pyx_n_s__images,&__pyx_n_s__pairwisecost,&__pyx_n_s__upperthreshold,&__pyx_n_s__lowerthreshold,&__pyx_n_s__sigma,&__pyx_n_s__erroroverlap,&__pyx_n_s__skip,&__pyx_n_s__clickradius,&__pyx_n_s__pool,0};
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("picksegment");
  __pyx_cur_scope = (struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_2_picksegment *)__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct_2_picksegment->tp_new(__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct_2_picksegment, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_self = __pyx_self;
  {
    PyObject* values[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
    values[4] = __pyx_k_11;
    values[5] = ((PyObject *)__pyx_int_10);
    values[6] = ((PyObject *)__pyx_int_neg_100);
    values[7] = __pyx_k_12;
    values[8] = __pyx_k_13;
    values[9] = ((PyObject *)__pyx_int_3);
    values[10] = ((PyObject *)__pyx_int_10);

  /* "vision/alearn/marginals.pyx":67
 *     return best[1], best[0], fullpath, marginals
 * 
 * def picksegment(start, stop, model, images,             # <<<<<<<<<<<<<<
 *                pairwisecost = 0.001, upperthreshold = 10,
 *                lowerthreshold = -100, sigma = .1, erroroverlap = 0.5, skip = 3,
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6vision_6alearn_9marginals_1picksegment, NULL, __pyx_n_s_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__picksegment, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "vision/alearn/marginals.pyx":67
 *     return best[1], best[0], fullpath, marginals
 * 
 * def picksegment(start, stop, model, images,             # <<<<<<<<<<<<<<
 *                pairwisecost = 0.001, upperthreshold = 10,
 *                lowerthreshold = -100, sigma = .1, erroroverlap = 0.5, skip = 3,
 */
struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_2_picksegment {
  PyObject_HEAD
  PyObject *__pyx_v_path;
};

 68:                pairwisecost = 0.001, upperthreshold = 10,
  /* "vision/alearn/marginals.pyx":68
 * 
 * def picksegment(start, stop, model, images,
 *                pairwisecost = 0.001, upperthreshold = 10,             # <<<<<<<<<<<<<<
 *                lowerthreshold = -100, sigma = .1, erroroverlap = 0.5, skip = 3,
 *                clickradius = 10, pool = None):
 */
  __pyx_t_2 = PyFloat_FromDouble(0.001); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_11 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
 69:                lowerthreshold = -100, sigma = .1, erroroverlap = 0.5, skip = 3,
  /* "vision/alearn/marginals.pyx":69
 * def picksegment(start, stop, model, images,
 *                pairwisecost = 0.001, upperthreshold = 10,
 *                lowerthreshold = -100, sigma = .1, erroroverlap = 0.5, skip = 3,             # <<<<<<<<<<<<<<
 *                clickradius = 10, pool = None):
 * 
 */
  __pyx_t_2 = PyFloat_FromDouble(.1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_12 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_13 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
 70:                clickradius = 10, pool = None):
    /* "vision/alearn/marginals.pyx":70
 *                pairwisecost = 0.001, upperthreshold = 10,
 *                lowerthreshold = -100, sigma = .1, erroroverlap = 0.5, skip = 3,
 *                clickradius = 10, pool = None):             # <<<<<<<<<<<<<<
 * 
 *     if pool:
 */
    values[11] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__stop);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("picksegment", 0, 4, 12, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__model);
        if (likely(values[2])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("picksegment", 0, 4, 12, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__images);
        if (likely(values[3])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("picksegment", 0, 4, 12, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pairwisecost);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__upperthreshold);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__lowerthreshold);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sigma);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__erroroverlap);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__skip);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__clickradius);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pool);
          if (value) { values[11] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "picksegment") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_start = values[0];
    __pyx_v_stop = values[1];
    __pyx_v_model = values[2];
    __pyx_v_images = values[3];
    __pyx_v_pairwisecost = values[4];
    __pyx_v_upperthreshold = values[5];
    __pyx_v_lowerthreshold = values[6];
    __pyx_v_sigma = values[7];
    __pyx_v_erroroverlap = values[8];
    __pyx_v_skip = values[9];
    __pyx_v_clickradius = values[10];
    __pyx_v_pool = values[11];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("picksegment", 0, 4, 12, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("vision.alearn.marginals.picksegment", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __Pyx_INCREF(__pyx_v_stop);
 71: 
 72:     if pool:
  /* "vision/alearn/marginals.pyx":72
 *                clickradius = 10, pool = None):
 * 
 *     if pool:             # <<<<<<<<<<<<<<
 *         logger.info("Found a process pool, so attempting to parallelize")
 *         mapper = pool.map
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_pool); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {
 73:         logger.info("Found a process pool, so attempting to parallelize")
    /* "vision/alearn/marginals.pyx":73
 * 
 *     if pool:
 *         logger.info("Found a process pool, so attempting to parallelize")             # <<<<<<<<<<<<<<
 *         mapper = pool.map
 *     else:
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "vision/alearn/marginals.pyx":73
 * 
 *     if pool:
 *         logger.info("Found a process pool, so attempting to parallelize")             # <<<<<<<<<<<<<<
 *         mapper = pool.map
 *     else:
 */
  __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_15));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_14));
  PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15));
 74:         mapper = pool.map
    /* "vision/alearn/marginals.pyx":74
 *     if pool:
 *         logger.info("Found a process pool, so attempting to parallelize")
 *         mapper = pool.map             # <<<<<<<<<<<<<<
 *     else:
 *         logger.info("No process pool found, so remaining single threaded")
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_v_pool, __pyx_n_s__map); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_mapper = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L6;
  }
  /*else*/ {
 75:     else:
 76:         logger.info("No process pool found, so remaining single threaded")
    /* "vision/alearn/marginals.pyx":76
 *         mapper = pool.map
 *     else:
 *         logger.info("No process pool found, so remaining single threaded")             # <<<<<<<<<<<<<<
 *         mapper = map
 * 
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "vision/alearn/marginals.pyx":76
 *         mapper = pool.map
 *     else:
 *         logger.info("No process pool found, so remaining single threaded")             # <<<<<<<<<<<<<<
 *         mapper = map
 * 
 */
  __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_17));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_16));
  PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_kp_s_16));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17));
 77:         mapper = map
    /* "vision/alearn/marginals.pyx":77
 *     else:
 *         logger.info("No process pool found, so remaining single threaded")
 *         mapper = map             # <<<<<<<<<<<<<<
 * 
 *     imagesize = images[0].size
 */
    __Pyx_INCREF(__pyx_builtin_map);
    __pyx_v_mapper = __pyx_builtin_map;
  }
  __pyx_L6:;
 78: 
 79:     imagesize = images[0].size
  /* "vision/alearn/marginals.pyx":79
 *         mapper = map
 * 
 *     imagesize = images[0].size             # <<<<<<<<<<<<<<
 * 
 *     try:
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_images, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_imagesize = __pyx_t_3;
  __pyx_t_3 = 0;
 80: 
 81:     try:
  /* "vision/alearn/marginals.pyx":81
 *     imagesize = images[0].size
 * 
 *     try:             # <<<<<<<<<<<<<<
 *         stopframe = stop.frame
 *     except:
 */
  {
    __Pyx_ExceptionSave(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
    __Pyx_XGOTREF(__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_5);
    __Pyx_XGOTREF(__pyx_t_6);
    /*try:*/ {
 82:         stopframe = stop.frame
      /* "vision/alearn/marginals.pyx":82
 * 
 *     try:
 *         stopframe = stop.frame             # <<<<<<<<<<<<<<
 *     except:
 *         stopframe = stop
 */
      __pyx_t_3 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__frame); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L7_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_stopframe = __pyx_t_3;
      __pyx_t_3 = 0;
    }
    /*else:*/ {
 83:     except:
    /* "vision/alearn/marginals.pyx":83
 *     try:
 *         stopframe = stop.frame
 *     except:             # <<<<<<<<<<<<<<
 *         stopframe = stop
 *         constrained = False
 */
    /*except:*/ {
      __Pyx_AddTraceback("vision.alearn.marginals.picksegment", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_9, &__pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_t_7);
 84:         stopframe = stop
      /* "vision/alearn/marginals.pyx":84
 *         stopframe = stop.frame
 *     except:
 *         stopframe = stop             # <<<<<<<<<<<<<<
 *         constrained = False
 *         constraints = [start]
 */
      __Pyx_INCREF(__pyx_v_stop);
      __Pyx_XDECREF(__pyx_v_stopframe);
      __pyx_v_stopframe = __pyx_v_stop;
 85:         constrained = False
      /* "vision/alearn/marginals.pyx":85
 *     except:
 *         stopframe = stop
 *         constrained = False             # <<<<<<<<<<<<<<
 *         constraints = [start]
 *     else:
 */
      __pyx_v_constrained = 0;
 86:         constraints = [start]
      /* "vision/alearn/marginals.pyx":86
 *         stopframe = stop
 *         constrained = False
 *         constraints = [start]             # <<<<<<<<<<<<<<
 *     else:
 *         constrained = True
 */
      __pyx_t_8 = PyList_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_8));
      __Pyx_INCREF(__pyx_v_start);
      PyList_SET_ITEM(__pyx_t_8, 0, __pyx_v_start);
      __Pyx_GIVEREF(__pyx_v_start);
      __pyx_v_constraints = __pyx_t_8;
      __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L8_exception_handled;
    }
    __pyx_L9_except_error:;
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_XGIVEREF(__pyx_t_6);
    __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
    goto __pyx_L1_error;
    __pyx_L8_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_XGIVEREF(__pyx_t_5);
    __Pyx_XGIVEREF(__pyx_t_6);
    __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6);
    __pyx_L14_try_end:;
  }
 87:     else:
 88:         constrained = True
      /* "vision/alearn/marginals.pyx":88
 *         constraints = [start]
 *     else:
 *         constrained = True             # <<<<<<<<<<<<<<
 *         # adjust stop for scaling reasons
 *         if stop.xtl + start.width >= imagesize[0]:
 */
      __pyx_v_constrained = 1;
 89:         # adjust stop for scaling reasons
 90:         if stop.xtl + start.width >= imagesize[0]:
      /* "vision/alearn/marginals.pyx":90
 *         constrained = True
 *         # adjust stop for scaling reasons
 *         if stop.xtl + start.width >= imagesize[0]:             # <<<<<<<<<<<<<<
 *             stopxtl = imagesize[0] - start.width - 1
 *         else:
 */
      __pyx_t_3 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__xtl); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__width); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_imagesize, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_t_2, Py_GE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_1) {
 91:             stopxtl = imagesize[0] - start.width - 1
        /* "vision/alearn/marginals.pyx":91
 *         # adjust stop for scaling reasons
 *         if stop.xtl + start.width >= imagesize[0]:
 *             stopxtl = imagesize[0] - start.width - 1             # <<<<<<<<<<<<<<
 *         else:
 *             stopxtl = stop.xtl
 */
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_imagesize, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__width); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = PyNumber_Subtract(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyNumber_Subtract(__pyx_t_7, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_v_stopxtl = __pyx_t_2;
        __pyx_t_2 = 0;
        goto __pyx_L15;
      }
      /*else*/ {
 92:         else:
 93:             stopxtl = stop.xtl
        /* "vision/alearn/marginals.pyx":93
 *             stopxtl = imagesize[0] - start.width - 1
 *         else:
 *             stopxtl = stop.xtl             # <<<<<<<<<<<<<<
 *         if stop.ytl + start.height >= imagesize[1]:
 *             stopytl = imagesize[1] - start.height - 1
 */
        __pyx_t_2 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__xtl); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_v_stopxtl = __pyx_t_2;
        __pyx_t_2 = 0;
      }
      __pyx_L15:;
 94:         if stop.ytl + start.height >= imagesize[1]:
      /* "vision/alearn/marginals.pyx":94
 *         else:
 *             stopxtl = stop.xtl
 *         if stop.ytl + start.height >= imagesize[1]:             # <<<<<<<<<<<<<<
 *             stopytl = imagesize[1] - start.height - 1
 *         else:
 */
      __pyx_t_2 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__ytl); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__height); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_imagesize, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_t_7, Py_GE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_1) {
 95:             stopytl = imagesize[1] - start.height - 1
        /* "vision/alearn/marginals.pyx":95
 *             stopxtl = stop.xtl
 *         if stop.ytl + start.height >= imagesize[1]:
 *             stopytl = imagesize[1] - start.height - 1             # <<<<<<<<<<<<<<
 *         else:
 *             stopytl = stop.ytl
 */
        __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_imagesize, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__height); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_3 = PyNumber_Subtract(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyNumber_Subtract(__pyx_t_3, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_stopytl = __pyx_t_7;
        __pyx_t_7 = 0;
        goto __pyx_L16;
      }
      /*else*/ {
 96:         else:
 97:             stopytl = stop.ytl
        /* "vision/alearn/marginals.pyx":97
 *             stopytl = imagesize[1] - start.height - 1
 *         else:
 *             stopytl = stop.ytl             # <<<<<<<<<<<<<<
 *         stop = Box(stopxtl, stopytl, stopxtl + start.width,
 *                    stopytl + start.height, stop.frame)
 */
        __pyx_t_7 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__ytl); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_v_stopytl = __pyx_t_7;
        __pyx_t_7 = 0;
      }
      __pyx_L16:;
 98:         stop = Box(stopxtl, stopytl, stopxtl + start.width,
      /* "vision/alearn/marginals.pyx":98
 *         else:
 *             stopytl = stop.ytl
 *         stop = Box(stopxtl, stopytl, stopxtl + start.width,             # <<<<<<<<<<<<<<
 *                    stopytl + start.height, stop.frame)
 *         constraints = [start, stop]
 */
      __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__Box); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_3 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__width); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyNumber_Add(__pyx_v_stopxtl, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 99:                    stopytl + start.height, stop.frame)
      /* "vision/alearn/marginals.pyx":99
 *             stopytl = stop.ytl
 *         stop = Box(stopxtl, stopytl, stopxtl + start.width,
 *                    stopytl + start.height, stop.frame)             # <<<<<<<<<<<<<<
 *         constraints = [start, stop]
 * 
 */
      __pyx_t_3 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__height); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = PyNumber_Add(__pyx_v_stopytl, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__frame); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_9));
      __Pyx_INCREF(__pyx_v_stopxtl);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_stopxtl);
      __Pyx_GIVEREF(__pyx_v_stopxtl);
      __Pyx_INCREF(__pyx_v_stopytl);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_stopytl);
      __Pyx_GIVEREF(__pyx_v_stopytl);
      PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_2 = 0;
      __pyx_t_8 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_v_stop);
      __pyx_v_stop = __pyx_t_3;
      __pyx_t_3 = 0;
 100:         constraints = [start, stop]
      /* "vision/alearn/marginals.pyx":100
 *         stop = Box(stopxtl, stopytl, stopxtl + start.width,
 *                    stopytl + start.height, stop.frame)
 *         constraints = [start, stop]             # <<<<<<<<<<<<<<
 * 
 *     if start.frame == stopframe:
 */
      __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_3));
      __Pyx_INCREF(__pyx_v_start);
      PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_start);
      __Pyx_GIVEREF(__pyx_v_start);
      __Pyx_INCREF(__pyx_v_stop);
      PyList_SET_ITEM(__pyx_t_3, 1, __pyx_v_stop);
      __Pyx_GIVEREF(__pyx_v_stop);
      __pyx_v_constraints = __pyx_t_3;
      __pyx_t_3 = 0;
    }
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    goto __pyx_L14_try_end;
    __pyx_L7_error:;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
 101: 
 102:     if start.frame == stopframe:
  /* "vision/alearn/marginals.pyx":102
 *         constraints = [start, stop]
 * 
 *     if start.frame == stopframe:             # <<<<<<<<<<<<<<
 *         return [(0, start.frame)], [start]
 *     elif start.frame + 1 == stopframe:
 */
  __pyx_t_7 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__frame); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = PyObject_RichCompare(__pyx_t_7, __pyx_v_stopframe, Py_EQ); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (__pyx_t_1) {
 103:         return [(0, start.frame)], [start]
    /* "vision/alearn/marginals.pyx":103
 * 
 *     if start.frame == stopframe:
 *         return [(0, start.frame)], [start]             # <<<<<<<<<<<<<<
 *     elif start.frame + 1 == stopframe:
 *         if not constrained:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_9 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__frame); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __Pyx_INCREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = PyList_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    PyList_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_7));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
    __pyx_t_7 = 0;
    __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __Pyx_INCREF(__pyx_v_start);
    PyList_SET_ITEM(__pyx_t_7, 0, __pyx_v_start);
    __Pyx_GIVEREF(__pyx_v_start);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_9));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_7));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
    __pyx_t_9 = 0;
    __pyx_t_7 = 0;
    __pyx_r = ((PyObject *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L19;
  }
 104:     elif start.frame + 1 == stopframe:
  /* "vision/alearn/marginals.pyx":104
 *     if start.frame == stopframe:
 *         return [(0, start.frame)], [start]
 *     elif start.frame + 1 == stopframe:             # <<<<<<<<<<<<<<
 *         if not constrained:
 *             stop = Box(*start)
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__frame); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = PyNumber_Add(__pyx_t_3, __pyx_int_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_7, __pyx_v_stopframe, Py_EQ); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_1) {
 105:         if not constrained:
    /* "vision/alearn/marginals.pyx":105
 *         return [(0, start.frame)], [start]
 *     elif start.frame + 1 == stopframe:
 *         if not constrained:             # <<<<<<<<<<<<<<
 *             stop = Box(*start)
 *             stop.frame = stopframe
 */
    __pyx_t_1 = (!__pyx_v_constrained);
    if (__pyx_t_1) {
 106:             stop = Box(*start)
      /* "vision/alearn/marginals.pyx":106
 *     elif start.frame + 1 == stopframe:
 *         if not constrained:
 *             stop = Box(*start)             # <<<<<<<<<<<<<<
 *             stop.frame = stopframe
 *         return [(0, start.frame), (0, stopframe)], [start, stop]
 */
      __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__Box); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = PySequence_Tuple(__pyx_v_start); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_7));
      __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_v_stop);
      __pyx_v_stop = __pyx_t_9;
      __pyx_t_9 = 0;
 107:             stop.frame = stopframe
      /* "vision/alearn/marginals.pyx":107
 *         if not constrained:
 *             stop = Box(*start)
 *             stop.frame = stopframe             # <<<<<<<<<<<<<<
 *         return [(0, start.frame), (0, stopframe)], [start, stop]
 * 
 */
      if (PyObject_SetAttr(__pyx_v_stop, __pyx_n_s__frame, __pyx_v_stopframe) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L20;
    }
    __pyx_L20:;
 108:         return [(0, start.frame), (0, stopframe)], [start, stop]
    /* "vision/alearn/marginals.pyx":108
 *             stop = Box(*start)
 *             stop.frame = stopframe
 *         return [(0, start.frame), (0, stopframe)], [start, stop]             # <<<<<<<<<<<<<<
 * 
 *     frames = range(start.frame, stopframe + 1)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_9 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__frame); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __Pyx_INCREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    __Pyx_INCREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    __Pyx_INCREF(__pyx_v_stopframe);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_stopframe);
    __Pyx_GIVEREF(__pyx_v_stopframe);
    __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_7));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
    PyList_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_9));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;
    __pyx_t_9 = PyList_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    __Pyx_INCREF(__pyx_v_start);
    PyList_SET_ITEM(__pyx_t_9, 0, __pyx_v_start);
    __Pyx_GIVEREF(__pyx_v_start);
    __Pyx_INCREF(__pyx_v_stop);
    PyList_SET_ITEM(__pyx_t_9, 1, __pyx_v_stop);
    __Pyx_GIVEREF(__pyx_v_stop);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_t_3));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_t_9));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
    __pyx_t_3 = 0;
    __pyx_t_9 = 0;
    __pyx_r = ((PyObject *)__pyx_t_7);
    __pyx_t_7 = 0;
    goto __pyx_L0;
    goto __pyx_L19;
  }
  __pyx_L19:;
 109: 
 110:     frames = range(start.frame, stopframe + 1)
  /* "vision/alearn/marginals.pyx":110
 *         return [(0, start.frame), (0, stopframe)], [start, stop]
 * 
 *     frames = range(start.frame, stopframe + 1)             # <<<<<<<<<<<<<<
 * 
 *     # build dictionary of local scores
 */
  __pyx_t_7 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__frame); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_9 = PyNumber_Add(__pyx_v_stopframe, __pyx_int_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_7 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_v_frames = __pyx_t_9;
  __pyx_t_9 = 0;
 111: 
 112:     # build dictionary of local scores
 113:     # if there is a pool, this will happen in parallel
 114:     logger.info("Scoring frames")
  /* "vision/alearn/marginals.pyx":114
 *     # build dictionary of local scores
 *     # if there is a pool, this will happen in parallel
 *     logger.info("Scoring frames")             # <<<<<<<<<<<<<<
 *     orders = [(images, start, x, model) for x in frames]
 *     costs = dict(mapper(dp.scoreframe, orders))
 */
  __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "vision/alearn/marginals.pyx":114
 *     # build dictionary of local scores
 *     # if there is a pool, this will happen in parallel
 *     logger.info("Scoring frames")             # <<<<<<<<<<<<<<
 *     orders = [(images, start, x, model) for x in frames]
 *     costs = dict(mapper(dp.scoreframe, orders))
 */
  __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_19));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_18));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_18));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19));
 115:     orders = [(images, start, x, model) for x in frames]
  /* "vision/alearn/marginals.pyx":115
 *     # if there is a pool, this will happen in parallel
 *     logger.info("Scoring frames")
 *     orders = [(images, start, x, model) for x in frames]             # <<<<<<<<<<<<<<
 *     costs = dict(mapper(dp.scoreframe, orders))
 * 
 */
  __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  if (PyList_CheckExact(__pyx_v_frames) || PyTuple_CheckExact(__pyx_v_frames)) {
    __pyx_t_3 = __pyx_v_frames; __Pyx_INCREF(__pyx_t_3); __pyx_t_10 = 0;
    __pyx_t_11 = NULL;
  } else {
    __pyx_t_10 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_frames); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext;
  }
  for (;;) {
    if (PyList_CheckExact(__pyx_t_3)) {
      if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_3)) break;
      __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_7); __pyx_t_10++;
    } else if (PyTuple_CheckExact(__pyx_t_3)) {
      if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
      __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_7); __pyx_t_10++;
    } else {
      __pyx_t_7 = __pyx_t_11(__pyx_t_3);
      if (unlikely(!__pyx_t_7)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_7;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __Pyx_INCREF(__pyx_v_images);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_images);
    __Pyx_GIVEREF(__pyx_v_images);
    __Pyx_INCREF(__pyx_v_start);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_start);
    __Pyx_GIVEREF(__pyx_v_start);
    __Pyx_INCREF(__pyx_v_x);
    PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_x);
    __Pyx_GIVEREF(__pyx_v_x);
    __Pyx_INCREF(__pyx_v_model);
    PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_v_model);
    __Pyx_GIVEREF(__pyx_v_model);
    if (unlikely(PyList_Append(__pyx_t_9, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_INCREF(((PyObject *)__pyx_t_9));
  __pyx_v_orders = __pyx_t_9;
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
 116:     costs = dict(mapper(dp.scoreframe, orders))
  /* "vision/alearn/marginals.pyx":116
 *     logger.info("Scoring frames")
 *     orders = [(images, start, x, model) for x in frames]
 *     costs = dict(mapper(dp.scoreframe, orders))             # <<<<<<<<<<<<<<
 * 
 *     # forward and backwards passes
 */
  __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__dp); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__scoreframe); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_orders));
  PyTuple_SET_ITEM(__pyx_t_9, 1, ((PyObject *)__pyx_v_orders));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_orders));
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_v_mapper, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  __pyx_v_costs = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
 117: 
 118:     # forward and backwards passes
 119:     # if there is a pool, this will use up to 2 cores
 120:     forwardsargs  = [frames, imagesize, model, costs, pairwisecost,
 121:                      upperthreshold, lowerthreshold, skip, constraints]
  /* "vision/alearn/marginals.pyx":121
 *     # if there is a pool, this will use up to 2 cores
 *     forwardsargs  = [frames, imagesize, model, costs, pairwisecost,
 *                      upperthreshold, lowerthreshold, skip, constraints]             # <<<<<<<<<<<<<<
 *     backwardsargs = list(forwardsargs)
 *     backwardsargs[0] = list(reversed(frames))
 */
  __pyx_t_3 = PyList_New(9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(__pyx_v_frames);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_frames);
  __Pyx_GIVEREF(__pyx_v_frames);
  __Pyx_INCREF(__pyx_v_imagesize);
  PyList_SET_ITEM(__pyx_t_3, 1, __pyx_v_imagesize);
  __Pyx_GIVEREF(__pyx_v_imagesize);
  __Pyx_INCREF(__pyx_v_model);
  PyList_SET_ITEM(__pyx_t_3, 2, __pyx_v_model);
  __Pyx_GIVEREF(__pyx_v_model);
  __Pyx_INCREF(((PyObject *)__pyx_v_costs));
  PyList_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_costs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_costs));
  __Pyx_INCREF(__pyx_v_pairwisecost);
  PyList_SET_ITEM(__pyx_t_3, 4, __pyx_v_pairwisecost);
  __Pyx_GIVEREF(__pyx_v_pairwisecost);
  __Pyx_INCREF(__pyx_v_upperthreshold);
  PyList_SET_ITEM(__pyx_t_3, 5, __pyx_v_upperthreshold);
  __Pyx_GIVEREF(__pyx_v_upperthreshold);
  __Pyx_INCREF(__pyx_v_lowerthreshold);
  PyList_SET_ITEM(__pyx_t_3, 6, __pyx_v_lowerthreshold);
  __Pyx_GIVEREF(__pyx_v_lowerthreshold);
  __Pyx_INCREF(__pyx_v_skip);
  PyList_SET_ITEM(__pyx_t_3, 7, __pyx_v_skip);
  __Pyx_GIVEREF(__pyx_v_skip);
  __Pyx_INCREF(((PyObject *)__pyx_v_constraints));
  PyList_SET_ITEM(__pyx_t_3, 8, ((PyObject *)__pyx_v_constraints));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_constraints));
  __pyx_v_forwardsargs = __pyx_t_3;
  __pyx_t_3 = 0;
 122:     backwardsargs = list(forwardsargs)
  /* "vision/alearn/marginals.pyx":122
 *     forwardsargs  = [frames, imagesize, model, costs, pairwisecost,
 *                      upperthreshold, lowerthreshold, skip, constraints]
 *     backwardsargs = list(forwardsargs)             # <<<<<<<<<<<<<<
 *     backwardsargs[0] = list(reversed(frames))
 *     if False and pool:
 */
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(((PyObject *)__pyx_v_forwardsargs));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_forwardsargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_forwardsargs));
  __pyx_t_9 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_v_backwardsargs = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;
 123:     backwardsargs[0] = list(reversed(frames))
  /* "vision/alearn/marginals.pyx":123
 *                      upperthreshold, lowerthreshold, skip, constraints]
 *     backwardsargs = list(forwardsargs)
 *     backwardsargs[0] = list(reversed(frames))             # <<<<<<<<<<<<<<
 *     if False and pool:
 *         logger.info("Building forwards and backwards graphs")
 */
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  __Pyx_INCREF(__pyx_v_frames);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_frames);
  __Pyx_GIVEREF(__pyx_v_frames);
  __pyx_t_3 = PyObject_Call(__pyx_builtin_reversed, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  if (__Pyx_SetItemInt(((PyObject *)__pyx_v_backwardsargs), 0, __pyx_t_3, sizeof(long), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 124:     if False and pool:
  /* "vision/alearn/marginals.pyx":124
 *     backwardsargs = list(forwardsargs)
 *     backwardsargs[0] = list(reversed(frames))
 *     if False and pool:             # <<<<<<<<<<<<<<
 *         logger.info("Building forwards and backwards graphs")
 *         forwards  = pool.apply_async(dp.buildgraph, forwardsargs)
 */
  __pyx_t_1 = 0;
  if (__pyx_t_1) {
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_pool); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_13 = __pyx_t_12;
  } else {
    __pyx_t_13 = __pyx_t_1;
  }
  if (__pyx_t_13) {
 125:         logger.info("Building forwards and backwards graphs")
    /* "vision/alearn/marginals.pyx":125
 *     backwardsargs[0] = list(reversed(frames))
 *     if False and pool:
 *         logger.info("Building forwards and backwards graphs")             # <<<<<<<<<<<<<<
 *         forwards  = pool.apply_async(dp.buildgraph, forwardsargs)
 *         backwards = dp.buildgraph(*backwardsargs)
 */
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_21), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "vision/alearn/marginals.pyx":125
 *     backwardsargs[0] = list(reversed(frames))
 *     if False and pool:
 *         logger.info("Building forwards and backwards graphs")             # <<<<<<<<<<<<<<
 *         forwards  = pool.apply_async(dp.buildgraph, forwardsargs)
 *         backwards = dp.buildgraph(*backwardsargs)
 */
  __pyx_k_tuple_21 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_21));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_20));
  PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, ((PyObject *)__pyx_kp_s_20));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_20));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21));
 126:         forwards  = pool.apply_async(dp.buildgraph, forwardsargs)
    /* "vision/alearn/marginals.pyx":126
 *     if False and pool:
 *         logger.info("Building forwards and backwards graphs")
 *         forwards  = pool.apply_async(dp.buildgraph, forwardsargs)             # <<<<<<<<<<<<<<
 *         backwards = dp.buildgraph(*backwardsargs)
 *         forwards  = forwards.get() # blocks until forwards graph done
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_pool, __pyx_n_s__apply_async); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__dp); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__buildgraph); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_INCREF(((PyObject *)__pyx_v_forwardsargs));
    PyTuple_SET_ITEM(__pyx_t_9, 1, ((PyObject *)__pyx_v_forwardsargs));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_forwardsargs));
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __pyx_v_forwards = __pyx_t_7;
    __pyx_t_7 = 0;
 127:         backwards = dp.buildgraph(*backwardsargs)
    /* "vision/alearn/marginals.pyx":127
 *         logger.info("Building forwards and backwards graphs")
 *         forwards  = pool.apply_async(dp.buildgraph, forwardsargs)
 *         backwards = dp.buildgraph(*backwardsargs)             # <<<<<<<<<<<<<<
 *         forwards  = forwards.get() # blocks until forwards graph done
 *     else:
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__dp); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__buildgraph); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PySequence_Tuple(((PyObject *)__pyx_v_backwardsargs)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __pyx_t_3 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __pyx_v_backwards = __pyx_t_3;
    __pyx_t_3 = 0;
 128:         forwards  = forwards.get() # blocks until forwards graph done
    /* "vision/alearn/marginals.pyx":128
 *         forwards  = pool.apply_async(dp.buildgraph, forwardsargs)
 *         backwards = dp.buildgraph(*backwardsargs)
 *         forwards  = forwards.get() # blocks until forwards graph done             # <<<<<<<<<<<<<<
 *     else:
 *         logger.info("Building forwards graph")
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_forwards, __pyx_n_s__get); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_v_forwards);
    __pyx_v_forwards = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L23;
  }
  /*else*/ {
 129:     else:
 130:         logger.info("Building forwards graph")
    /* "vision/alearn/marginals.pyx":130
 *         forwards  = forwards.get() # blocks until forwards graph done
 *     else:
 *         logger.info("Building forwards graph")             # <<<<<<<<<<<<<<
 *         forwards  = dp.buildgraph(*forwardsargs)
 *         logger.info("Building backwards graph")
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__info); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "vision/alearn/marginals.pyx":130
 *         forwards  = forwards.get() # blocks until forwards graph done
 *     else:
 *         logger.info("Building forwards graph")             # <<<<<<<<<<<<<<
 *         forwards  = dp.buildgraph(*forwardsargs)
 *         logger.info("Building backwards graph")
 */
  __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_23));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_22));
  PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_kp_s_22));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_22));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));
 131:         forwards  = dp.buildgraph(*forwardsargs)
    /* "vision/alearn/marginals.pyx":131
 *     else:
 *         logger.info("Building forwards graph")
 *         forwards  = dp.buildgraph(*forwardsargs)             # <<<<<<<<<<<<<<
 *         logger.info("Building backwards graph")
 *         backwards = dp.buildgraph(*backwardsargs)
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__dp); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__buildgraph); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PySequence_Tuple(((PyObject *)__pyx_v_forwardsargs)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __pyx_v_forwards = __pyx_t_9;
    __pyx_t_9 = 0;
 132:         logger.info("Building backwards graph")
    /* "vision/alearn/marginals.pyx":132
 *         logger.info("Building forwards graph")
 *         forwards  = dp.buildgraph(*forwardsargs)
 *         logger.info("Building backwards graph")             # <<<<<<<<<<<<<<
 *         backwards = dp.buildgraph(*backwardsargs)
 * 
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__info); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "vision/alearn/marginals.pyx":132
 *         logger.info("Building forwards graph")
 *         forwards  = dp.buildgraph(*forwardsargs)
 *         logger.info("Building backwards graph")             # <<<<<<<<<<<<<<
 *         backwards = dp.buildgraph(*backwardsargs)
 * 
 */
  __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_25));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_24));
  PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_kp_s_24));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_24));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25));
 133:         backwards = dp.buildgraph(*backwardsargs)
    /* "vision/alearn/marginals.pyx":133
 *         forwards  = dp.buildgraph(*forwardsargs)
 *         logger.info("Building backwards graph")
 *         backwards = dp.buildgraph(*backwardsargs)             # <<<<<<<<<<<<<<
 * 
 *     # backtrack
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__dp); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__buildgraph); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PySequence_Tuple(((PyObject *)__pyx_v_backwardsargs)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    __pyx_t_3 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __pyx_v_backwards = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L23:;
 134: 
 135:     # backtrack
 136:     logger.info("Backtracking")
  /* "vision/alearn/marginals.pyx":136
 * 
 *     # backtrack
 *     logger.info("Backtracking")             # <<<<<<<<<<<<<<
 *     if constrained:
 *         x, y, frame = stop.xtl, stop.ytl, stop.frame
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_9 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_26), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "vision/alearn/marginals.pyx":136
 * 
 *     # backtrack
 *     logger.info("Backtracking")             # <<<<<<<<<<<<<<
 *     if constrained:
 *         x, y, frame = stop.xtl, stop.ytl, stop.frame
 */
  __pyx_k_tuple_26 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_26));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__Backtracking));
  PyTuple_SET_ITEM(__pyx_k_tuple_26, 0, ((PyObject *)__pyx_n_s__Backtracking));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Backtracking));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_26));
 137:     if constrained:
  /* "vision/alearn/marginals.pyx":137
 *     # backtrack
 *     logger.info("Backtracking")
 *     if constrained:             # <<<<<<<<<<<<<<
 *         x, y, frame = stop.xtl, stop.ytl, stop.frame
 *     else:
 */
  if (__pyx_v_constrained) {
 138:         x, y, frame = stop.xtl, stop.ytl, stop.frame
    /* "vision/alearn/marginals.pyx":138
 *     logger.info("Backtracking")
 *     if constrained:
 *         x, y, frame = stop.xtl, stop.ytl, stop.frame             # <<<<<<<<<<<<<<
 *     else:
 *         x, y = numpy.unravel_index(numpy.argmin(forwards[stopframe][0]),
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__xtl); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__ytl); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyObject_GetAttr(__pyx_v_stop, __pyx_n_s__frame); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_XDECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_3;
    __pyx_t_3 = 0;
    __pyx_v_y = __pyx_t_9;
    __pyx_t_9 = 0;
    __pyx_v_frame = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L24;
  }
  /*else*/ {
 139:     else:
 140:         x, y = numpy.unravel_index(numpy.argmin(forwards[stopframe][0]),
    /* "vision/alearn/marginals.pyx":140
 *         x, y, frame = stop.xtl, stop.ytl, stop.frame
 *     else:
 *         x, y = numpy.unravel_index(numpy.argmin(forwards[stopframe][0]),             # <<<<<<<<<<<<<<
 *                                                 forwards[stopframe][0].shape)
 *         x = x * skip
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__unravel_index); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__argmin); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_GetItem(__pyx_v_forwards, __pyx_v_stopframe); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_7, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;

    /* "vision/alearn/marginals.pyx":140
 *         x, y, frame = stop.xtl, stop.ytl, stop.frame
 *     else:
 *         x, y = numpy.unravel_index(numpy.argmin(forwards[stopframe][0]),             # <<<<<<<<<<<<<<
 *                                                 forwards[stopframe][0].shape)
 *         x = x * skip
 */
    __Pyx_XDECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_3;
    __pyx_t_3 = 0;
    __pyx_v_y = __pyx_t_9;
    __pyx_t_9 = 0;
 141:                                                 forwards[stopframe][0].shape)
    /* "vision/alearn/marginals.pyx":141
 *     else:
 *         x, y = numpy.unravel_index(numpy.argmin(forwards[stopframe][0]),
 *                                                 forwards[stopframe][0].shape)             # <<<<<<<<<<<<<<
 *         x = x * skip
 *         y = y * skip
 */
    __pyx_t_7 = PyObject_GetItem(__pyx_v_forwards, __pyx_v_stopframe); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_7, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__shape); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_8 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
      PyObject* sequence = __pyx_t_7;
      if (likely(PyTuple_CheckExact(sequence))) {
        if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) {
          if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        if (unlikely(PyList_GET_SIZE(sequence) != 2)) {
          if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2);
          else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_14 = Py_TYPE(__pyx_t_8)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_14(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L25_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_9 = __pyx_t_14(__pyx_t_8); if (unlikely(!__pyx_t_9)) goto __pyx_L25_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L26_unpacking_done;
      __pyx_L25_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
      if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L26_unpacking_done:;
    }
 142:         x = x * skip
    /* "vision/alearn/marginals.pyx":142
 *         x, y = numpy.unravel_index(numpy.argmin(forwards[stopframe][0]),
 *                                                 forwards[stopframe][0].shape)
 *         x = x * skip             # <<<<<<<<<<<<<<
 *         y = y * skip
 *         frame = stopframe
 */
    __pyx_t_7 = PyNumber_Multiply(__pyx_v_x, __pyx_v_skip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_7;
    __pyx_t_7 = 0;
 143:         y = y * skip
    /* "vision/alearn/marginals.pyx":143
 *                                                 forwards[stopframe][0].shape)
 *         x = x * skip
 *         y = y * skip             # <<<<<<<<<<<<<<
 *         frame = stopframe
 *     path = []
 */
    __pyx_t_7 = PyNumber_Multiply(__pyx_v_y, __pyx_v_skip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_v_y);
    __pyx_v_y = __pyx_t_7;
    __pyx_t_7 = 0;
 144:         frame = stopframe
    /* "vision/alearn/marginals.pyx":144
 *         x = x * skip
 *         y = y * skip
 *         frame = stopframe             # <<<<<<<<<<<<<<
 *     path = []
 *     while frame > start.frame:
 */
    __Pyx_INCREF(__pyx_v_stopframe);
    __pyx_v_frame = __pyx_v_stopframe;
  }
  __pyx_L24:;
 145:     path = []
  /* "vision/alearn/marginals.pyx":145
 *         y = y * skip
 *         frame = stopframe
 *     path = []             # <<<<<<<<<<<<<<
 *     while frame > start.frame:
 *         path.append(annotations.Box(x, y,
 */
  __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_7));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_7));
  __pyx_cur_scope->__pyx_v_path = ((PyObject *)__pyx_t_7);
  __pyx_t_7 = 0;
 146:     while frame > start.frame:
  /* "vision/alearn/marginals.pyx":146
 *         frame = stopframe
 *     path = []
 *     while frame > start.frame:             # <<<<<<<<<<<<<<
 *         path.append(annotations.Box(x, y,
 *                                     x + start.width,
 */
  while (1) {
    __pyx_t_7 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__frame); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyObject_RichCompare(__pyx_v_frame, __pyx_t_7, Py_GT); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_13 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (!__pyx_t_13) break;
 147:         path.append(annotations.Box(x, y,
 148:                                     x + start.width,
    /* "vision/alearn/marginals.pyx":148
 *     while frame > start.frame:
 *         path.append(annotations.Box(x, y,
 *                                     x + start.width,             # <<<<<<<<<<<<<<
 *                                     y + start.height,
 *                                     frame))
 */
    __pyx_t_9 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__width); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyNumber_Add(__pyx_v_x, __pyx_t_9); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 149:                                     y + start.height,
    /* "vision/alearn/marginals.pyx":149
 *         path.append(annotations.Box(x, y,
 *                                     x + start.width,
 *                                     y + start.height,             # <<<<<<<<<<<<<<
 *                                     frame))
 *         x, y = (forwards[frame][1][x // skip, y // skip] * skip,
 */
    __pyx_t_9 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__height); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_3 = PyNumber_Add(__pyx_v_y, __pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 150:                                     frame))
    /* "vision/alearn/marginals.pyx":150
 *                                     x + start.width,
 *                                     y + start.height,
 *                                     frame))             # <<<<<<<<<<<<<<
 *         x, y = (forwards[frame][1][x // skip, y // skip] * skip,
 *                 forwards[frame][2][x // skip, y // skip] * skip)
 */
    __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    __Pyx_INCREF(__pyx_v_x);
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_x);
    __Pyx_GIVEREF(__pyx_v_x);
    __Pyx_INCREF(__pyx_v_y);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_y);
    __Pyx_GIVEREF(__pyx_v_y);
    PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_frame);
    PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_v_frame);
    __Pyx_GIVEREF(__pyx_v_frame);
    __pyx_t_7 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_6vision_11annotations_Box)), ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_PyObject_Append(__pyx_cur_scope->__pyx_v_path, __pyx_t_3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 151:         x, y = (forwards[frame][1][x // skip, y // skip] * skip,
    /* "vision/alearn/marginals.pyx":151
 *                                     y + start.height,
 *                                     frame))
 *         x, y = (forwards[frame][1][x // skip, y // skip] * skip,             # <<<<<<<<<<<<<<
 *                 forwards[frame][2][x // skip, y // skip] * skip)
 *         frame = frame - 1
 */
    __pyx_t_9 = PyObject_GetItem(__pyx_v_forwards, __pyx_v_frame); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_9, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyNumber_FloorDivide(__pyx_v_x, __pyx_v_skip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyNumber_FloorDivide(__pyx_v_y, __pyx_v_skip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_9 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_GetItem(__pyx_t_3, ((PyObject *)__pyx_t_8)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_t_8 = PyNumber_Multiply(__pyx_t_7, __pyx_v_skip); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 152:                 forwards[frame][2][x // skip, y // skip] * skip)
    /* "vision/alearn/marginals.pyx":152
 *                                     frame))
 *         x, y = (forwards[frame][1][x // skip, y // skip] * skip,
 *                 forwards[frame][2][x // skip, y // skip] * skip)             # <<<<<<<<<<<<<<
 *         frame = frame - 1
 *     path.append(start)
 */
    __pyx_t_7 = PyObject_GetItem(__pyx_v_forwards, __pyx_v_frame); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_7, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_FloorDivide(__pyx_v_x, __pyx_v_skip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyNumber_FloorDivide(__pyx_v_y, __pyx_v_skip); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_2));
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_GetItem(__pyx_t_3, ((PyObject *)__pyx_t_2)); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_t_2 = PyNumber_Multiply(__pyx_t_9, __pyx_v_skip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_8;
    __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_v_y);
    __pyx_v_y = __pyx_t_2;
    __pyx_t_2 = 0;
 153:         frame = frame - 1
    /* "vision/alearn/marginals.pyx":153
 *         x, y = (forwards[frame][1][x // skip, y // skip] * skip,
 *                 forwards[frame][2][x // skip, y // skip] * skip)
 *         frame = frame - 1             # <<<<<<<<<<<<<<
 *     path.append(start)
 *     path.reverse()
 */
    __pyx_t_2 = PyNumber_Subtract(__pyx_v_frame, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_v_frame);
    __pyx_v_frame = __pyx_t_2;
    __pyx_t_2 = 0;
  }
 154:     path.append(start)
  /* "vision/alearn/marginals.pyx":154
 *                 forwards[frame][2][x // skip, y // skip] * skip)
 *         frame = frame - 1
 *     path.append(start)             # <<<<<<<<<<<<<<
 *     path.reverse()
 *     pathdict = dict((x.frame, x) for x in path)
 */
  __pyx_t_2 = __Pyx_PyObject_Append(__pyx_cur_scope->__pyx_v_path, __pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 155:     path.reverse()
  /* "vision/alearn/marginals.pyx":155
 *         frame = frame - 1
 *     path.append(start)
 *     path.reverse()             # <<<<<<<<<<<<<<
 *     pathdict = dict((x.frame, x) for x in path)
 * 
 */
  __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_path, __pyx_n_s__reverse); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 156:     pathdict = dict((x.frame, x) for x in path)
/* "vision/alearn/marginals.pyx":156
 *     path.append(start)
 *     path.reverse()
 *     pathdict = dict((x.frame, x) for x in path)             # <<<<<<<<<<<<<<
 * 
 *     # calculating error
 */

static PyObject *__pyx_pf_6vision_6alearn_9marginals_11picksegment_genexpr(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_pf_6vision_6alearn_9marginals_11picksegment_genexpr(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_3_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("genexpr");
  __pyx_cur_scope = (struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_3_genexpr *)__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct_3_genexpr->tp_new(__pyx_ptype_6vision_6alearn_9marginals___pyx_scope_struct_3_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_2_picksegment *)__pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  __pyx_self = __pyx_self;
  __pyx_cur_scope->__pyx_base.resume_label = 0;
  __pyx_cur_scope->__pyx_base.body = (__pyx_generator_body_t) __pyx_gb_6vision_6alearn_9marginals_11picksegment_1generator1;
  __Pyx_GIVEREF(__pyx_cur_scope);
  __Pyx_RefNannyFinishContext();
  return (PyObject *) __pyx_cur_scope;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_6vision_6alearn_9marginals_11picksegment_1generator1(struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_3_genexpr *__pyx_cur_scope, PyObject *__pyx_sent_value) /* generator body */
{
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None");
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_path)) { __Pyx_RaiseClosureNameError("path"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_path) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_path)) {
    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_path; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_path); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  for (;;) {
    if (PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++;
    } else if (PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++;
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_cur_scope->__pyx_v_x = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_x, __pyx_n_s__frame); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_cur_scope->__pyx_v_x);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_x);
    __pyx_t_4 = 0;
    __pyx_r = ((PyObject *)__pyx_t_5);
    __pyx_t_5 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_3;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_cur_scope->__pyx_base.resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyErr_SetNone(PyExc_StopIteration); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r);
  __pyx_cur_scope->__pyx_base.resume_label = -1;
  __Pyx_RefNannyFinishContext();
  return NULL;
}

  /* "vision/alearn/marginals.pyx":156
 *     path.append(start)
 *     path.reverse()
 *     pathdict = dict((x.frame, x) for x in path)             # <<<<<<<<<<<<<<
 * 
 *     # calculating error
 */
  __pyx_t_8 = __pyx_pf_6vision_6alearn_9marginals_11picksegment_genexpr(((PyObject*)__pyx_cur_scope), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_v_pathdict = ((PyObject*)__pyx_t_8);
  __pyx_t_8 = 0;

/* "vision/alearn/marginals.pyx":156
 *     path.append(start)
 *     path.reverse()
 *     pathdict = dict((x.frame, x) for x in path)             # <<<<<<<<<<<<<<
 * 
 *     # calculating error
 */
struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_3_genexpr {
  struct __pyx_Generator_object __pyx_base;
  struct __pyx_obj_6vision_6alearn_9marginals___pyx_scope_struct_2_picksegment *__pyx_outer_scope;
  PyObject *__pyx_v_x;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};

 157: 
 158:     # calculating error
 159:     # if there is a pool, this will use up to 2 cores
 160:     if False and pool:
  /* "vision/alearn/marginals.pyx":160
 *     # calculating error
 *     # if there is a pool, this will use up to 2 cores
 *     if False and pool:             # <<<<<<<<<<<<<<
 *         logger.info("Calculating forward and backwards errors")
 *         forwarderror  = pool.apply_async(calcerror, (pathdict,
 */
  __pyx_t_13 = 0;
  if (__pyx_t_13) {
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_pool); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_12 = __pyx_t_1;
  } else {
    __pyx_t_12 = __pyx_t_13;
  }
  if (__pyx_t_12) {
 161:         logger.info("Calculating forward and backwards errors")
    /* "vision/alearn/marginals.pyx":161
 *     # if there is a pool, this will use up to 2 cores
 *     if False and pool:
 *         logger.info("Calculating forward and backwards errors")             # <<<<<<<<<<<<<<
 *         forwarderror  = pool.apply_async(calcerror, (pathdict,
 *                                                      forwards,
 */
    __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_28), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "vision/alearn/marginals.pyx":161
 *     # if there is a pool, this will use up to 2 cores
 *     if False and pool:
 *         logger.info("Calculating forward and backwards errors")             # <<<<<<<<<<<<<<
 *         forwarderror  = pool.apply_async(calcerror, (pathdict,
 *                                                      forwards,
 */
  __pyx_k_tuple_28 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_28));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_27));
  PyTuple_SET_ITEM(__pyx_k_tuple_28, 0, ((PyObject *)__pyx_kp_s_27));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_27));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_28));
 162:         forwarderror  = pool.apply_async(calcerror, (pathdict,
    /* "vision/alearn/marginals.pyx":162
 *     if False and pool:
 *         logger.info("Calculating forward and backwards errors")
 *         forwarderror  = pool.apply_async(calcerror, (pathdict,             # <<<<<<<<<<<<<<
 *                                                      forwards,
 *                                                      erroroverlap,
 */
    __pyx_t_8 = PyObject_GetAttr(__pyx_v_pool, __pyx_n_s__apply_async); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__calcerror); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
 163:                                                      forwards,
 164:                                                      erroroverlap,
 165:                                                      skip,
 166:                                                      frames))
    /* "vision/alearn/marginals.pyx":166
 *                                                      erroroverlap,
 *                                                      skip,
 *                                                      frames))             # <<<<<<<<<<<<<<
 *         backwarderror = calcerror(pathdict,
 *                                   backwards,
 */
    __pyx_t_9 = PyTuple_New(5); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    __Pyx_INCREF(((PyObject *)__pyx_v_pathdict));
    PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_v_pathdict));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_pathdict));
    __Pyx_INCREF(__pyx_v_forwards);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_forwards);
    __Pyx_GIVEREF(__pyx_v_forwards);
    __Pyx_INCREF(__pyx_v_erroroverlap);
    PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_erroroverlap);
    __Pyx_GIVEREF(__pyx_v_erroroverlap);
    __Pyx_INCREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_v_skip);
    __Pyx_GIVEREF(__pyx_v_skip);
    __Pyx_INCREF(__pyx_v_frames);
    PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_v_frames);
    __Pyx_GIVEREF(__pyx_v_frames);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_t_9));
    __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
    __pyx_t_2 = 0;
    __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_v_forwarderror = __pyx_t_9;
    __pyx_t_9 = 0;
 167:         backwarderror = calcerror(pathdict,
    /* "vision/alearn/marginals.pyx":167
 *                                                      skip,
 *                                                      frames))
 *         backwarderror = calcerror(pathdict,             # <<<<<<<<<<<<<<
 *                                   backwards,
 *                                   erroroverlap,
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__calcerror); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
 168:                                   backwards,
 169:                                   erroroverlap,
 170:                                   skip,
 171:                                   list(reversed(frames)))
    /* "vision/alearn/marginals.pyx":171
 *                                   erroroverlap,
 *                                   skip,
 *                                   list(reversed(frames)))             # <<<<<<<<<<<<<<
 *         forwarderror  = forwarderror.get() # blocks until forwards is done
 *     else:
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(__pyx_v_frames);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_frames);
    __Pyx_GIVEREF(__pyx_v_frames);
    __pyx_t_8 = PyObject_Call(__pyx_builtin_reversed, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_3));
    __Pyx_INCREF(((PyObject *)__pyx_v_pathdict));
    PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_pathdict));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_pathdict));
    __Pyx_INCREF(__pyx_v_backwards);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_backwards);
    __Pyx_GIVEREF(__pyx_v_backwards);
    __Pyx_INCREF(__pyx_v_erroroverlap);
    PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_erroroverlap);
    __Pyx_GIVEREF(__pyx_v_erroroverlap);
    __Pyx_INCREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_skip);
    __Pyx_GIVEREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __pyx_v_backwarderror = __pyx_t_8;
    __pyx_t_8 = 0;
 172:         forwarderror  = forwarderror.get() # blocks until forwards is done
    /* "vision/alearn/marginals.pyx":172
 *                                   skip,
 *                                   list(reversed(frames)))
 *         forwarderror  = forwarderror.get() # blocks until forwards is done             # <<<<<<<<<<<<<<
 *     else:
 *         logger.info("Calculating forward error")
 */
    __pyx_t_8 = PyObject_GetAttr(__pyx_v_forwarderror, __pyx_n_s__get); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_v_forwarderror);
    __pyx_v_forwarderror = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L29;
  }
  /*else*/ {
 173:     else:
 174:         logger.info("Calculating forward error")
    /* "vision/alearn/marginals.pyx":174
 *         forwarderror  = forwarderror.get() # blocks until forwards is done
 *     else:
 *         logger.info("Calculating forward error")             # <<<<<<<<<<<<<<
 *         forwarderror  = calcerror(pathdict,
 *                                   forwards,
 */
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_30), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "vision/alearn/marginals.pyx":174
 *         forwarderror  = forwarderror.get() # blocks until forwards is done
 *     else:
 *         logger.info("Calculating forward error")             # <<<<<<<<<<<<<<
 *         forwarderror  = calcerror(pathdict,
 *                                   forwards,
 */
  __pyx_k_tuple_30 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_30));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_29));
  PyTuple_SET_ITEM(__pyx_k_tuple_30, 0, ((PyObject *)__pyx_kp_s_29));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_29));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_30));
 175:         forwarderror  = calcerror(pathdict,
    /* "vision/alearn/marginals.pyx":175
 *     else:
 *         logger.info("Calculating forward error")
 *         forwarderror  = calcerror(pathdict,             # <<<<<<<<<<<<<<
 *                                   forwards,
 *                                   erroroverlap,
 */
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__calcerror); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
 176:                                   forwards,
 177:                                   erroroverlap,
 178:                                   skip,
 179:                                   frames)
    /* "vision/alearn/marginals.pyx":179
 *                                   erroroverlap,
 *                                   skip,
 *                                   frames)             # <<<<<<<<<<<<<<
 *         logger.info("Calculating backward error")
 *         backwarderror = calcerror(pathdict,
 */
    __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    __Pyx_INCREF(((PyObject *)__pyx_v_pathdict));
    PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_pathdict));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_pathdict));
    __Pyx_INCREF(__pyx_v_forwards);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_forwards);
    __Pyx_GIVEREF(__pyx_v_forwards);
    __Pyx_INCREF(__pyx_v_erroroverlap);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_erroroverlap);
    __Pyx_GIVEREF(__pyx_v_erroroverlap);
    __Pyx_INCREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_v_skip);
    __Pyx_GIVEREF(__pyx_v_skip);
    __Pyx_INCREF(__pyx_v_frames);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_v_frames);
    __Pyx_GIVEREF(__pyx_v_frames);
    __pyx_t_9 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_v_forwarderror = __pyx_t_9;
    __pyx_t_9 = 0;
 180:         logger.info("Calculating backward error")
    /* "vision/alearn/marginals.pyx":180
 *                                   skip,
 *                                   frames)
 *         logger.info("Calculating backward error")             # <<<<<<<<<<<<<<
 *         backwarderror = calcerror(pathdict,
 *                                   backwards,
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__info); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_32), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "vision/alearn/marginals.pyx":180
 *                                   skip,
 *                                   frames)
 *         logger.info("Calculating backward error")             # <<<<<<<<<<<<<<
 *         backwarderror = calcerror(pathdict,
 *                                   backwards,
 */
  __pyx_k_tuple_32 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_32));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_31));
  PyTuple_SET_ITEM(__pyx_k_tuple_32, 0, ((PyObject *)__pyx_kp_s_31));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_31));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_32));
 181:         backwarderror = calcerror(pathdict,
    /* "vision/alearn/marginals.pyx":181
 *                                   frames)
 *         logger.info("Calculating backward error")
 *         backwarderror = calcerror(pathdict,             # <<<<<<<<<<<<<<
 *                                   backwards,
 *                                   erroroverlap,
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__calcerror); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
 182:                                   backwards,
 183:                                   erroroverlap,
 184:                                   skip,
 185:                                   list(reversed(frames)))
    /* "vision/alearn/marginals.pyx":185
 *                                   erroroverlap,
 *                                   skip,
 *                                   list(reversed(frames)))             # <<<<<<<<<<<<<<
 * 
 *     # score marginals on the frames
 */
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    __Pyx_INCREF(__pyx_v_frames);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_frames);
    __Pyx_GIVEREF(__pyx_v_frames);
    __pyx_t_3 = PyObject_Call(__pyx_builtin_reversed, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyList_Type))), ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    __Pyx_INCREF(((PyObject *)__pyx_v_pathdict));
    PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_pathdict));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_pathdict));
    __Pyx_INCREF(__pyx_v_backwards);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_backwards);
    __Pyx_GIVEREF(__pyx_v_backwards);
    __Pyx_INCREF(__pyx_v_erroroverlap);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_v_erroroverlap);
    __Pyx_GIVEREF(__pyx_v_erroroverlap);
    __Pyx_INCREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_v_skip);
    __Pyx_GIVEREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_v_backwarderror = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L29:;
 186: 
 187:     # score marginals on the frames
 188:     # if there is a pool, this will happen in parallel
 189:     logger.info("Computing marginals")
  /* "vision/alearn/marginals.pyx":189
 *     # score marginals on the frames
 *     # if there is a pool, this will happen in parallel
 *     logger.info("Computing marginals")             # <<<<<<<<<<<<<<
 *     orders = [(forwards[x], backwards[x],
 *                forwarderror[x], backwarderror[x],
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__info); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_34), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "vision/alearn/marginals.pyx":189
 *     # score marginals on the frames
 *     # if there is a pool, this will happen in parallel
 *     logger.info("Computing marginals")             # <<<<<<<<<<<<<<
 *     orders = [(forwards[x], backwards[x],
 *                forwarderror[x], backwarderror[x],
 */
  __pyx_k_tuple_34 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_34));
  __Pyx_INCREF(((PyObject *)__pyx_kp_s_33));
  PyTuple_SET_ITEM(__pyx_k_tuple_34, 0, ((PyObject *)__pyx_kp_s_33));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_33));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_34));
 190:     orders = [(forwards[x], backwards[x],
  /* "vision/alearn/marginals.pyx":190
 *     # if there is a pool, this will happen in parallel
 *     logger.info("Computing marginals")
 *     orders = [(forwards[x], backwards[x],             # <<<<<<<<<<<<<<
 *                forwarderror[x], backwarderror[x],
 *                costs[x], sigma, model.dim, start, skip, clickradius, x)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));

    /* "vision/alearn/marginals.pyx":190
 *     # if there is a pool, this will happen in parallel
 *     logger.info("Computing marginals")
 *     orders = [(forwards[x], backwards[x],             # <<<<<<<<<<<<<<
 *                forwarderror[x], backwarderror[x],
 *                costs[x], sigma, model.dim, start, skip, clickradius, x)
 */
    __pyx_t_8 = PyObject_GetItem(__pyx_v_forwards, __pyx_v_x); if (!__pyx_t_8) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = PyObject_GetItem(__pyx_v_backwards, __pyx_v_x); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
 191:                forwarderror[x], backwarderror[x],
    /* "vision/alearn/marginals.pyx":191
 *     logger.info("Computing marginals")
 *     orders = [(forwards[x], backwards[x],
 *                forwarderror[x], backwarderror[x],             # <<<<<<<<<<<<<<
 *                costs[x], sigma, model.dim, start, skip, clickradius, x)
 *                for x in frames[1:-1]]
 */
    __pyx_t_7 = PyObject_GetItem(__pyx_v_forwarderror, __pyx_v_x); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_15 = PyObject_GetItem(__pyx_v_backwarderror, __pyx_v_x); if (!__pyx_t_15) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
 192:                costs[x], sigma, model.dim, start, skip, clickradius, x)
    /* "vision/alearn/marginals.pyx":192
 *     orders = [(forwards[x], backwards[x],
 *                forwarderror[x], backwarderror[x],
 *                costs[x], sigma, model.dim, start, skip, clickradius, x)             # <<<<<<<<<<<<<<
 *                for x in frames[1:-1]]
 *     marginals = mapper(scoremarginals, orders)
 */
    __pyx_t_16 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_v_costs), __pyx_v_x); if (!__pyx_t_16) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_17 = PyObject_GetAttr(__pyx_v_model, __pyx_n_s__dim); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_17);
    __pyx_t_18 = PyTuple_New(11); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_18));
    PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_18, 2, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_18, 3, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_18, 4, __pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_16);
    __Pyx_INCREF(__pyx_v_sigma);
    PyTuple_SET_ITEM(__pyx_t_18, 5, __pyx_v_sigma);
    __Pyx_GIVEREF(__pyx_v_sigma);
    PyTuple_SET_ITEM(__pyx_t_18, 6, __pyx_t_17);
    __Pyx_GIVEREF(__pyx_t_17);
    __Pyx_INCREF(__pyx_v_start);
    PyTuple_SET_ITEM(__pyx_t_18, 7, __pyx_v_start);
    __Pyx_GIVEREF(__pyx_v_start);
    __Pyx_INCREF(__pyx_v_skip);
    PyTuple_SET_ITEM(__pyx_t_18, 8, __pyx_v_skip);
    __Pyx_GIVEREF(__pyx_v_skip);
    __Pyx_INCREF(__pyx_v_clickradius);
    PyTuple_SET_ITEM(__pyx_t_18, 9, __pyx_v_clickradius);
    __Pyx_GIVEREF(__pyx_v_clickradius);
    __Pyx_INCREF(__pyx_v_x);
    PyTuple_SET_ITEM(__pyx_t_18, 10, __pyx_v_x);
    __Pyx_GIVEREF(__pyx_v_x);
    __pyx_t_8 = 0;
    __pyx_t_2 = 0;
    __pyx_t_7 = 0;
    __pyx_t_15 = 0;
    __pyx_t_16 = 0;
    __pyx_t_17 = 0;
    if (unlikely(PyList_Append(__pyx_t_3, (PyObject*)__pyx_t_18))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_18)); __pyx_t_18 = 0;
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_INCREF(((PyObject *)__pyx_t_3));
  __Pyx_DECREF(((PyObject *)__pyx_v_orders));
  __pyx_v_orders = __pyx_t_3;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
 193:                for x in frames[1:-1]]
  /* "vision/alearn/marginals.pyx":193
 *                forwarderror[x], backwarderror[x],
 *                costs[x], sigma, model.dim, start, skip, clickradius, x)
 *                for x in frames[1:-1]]             # <<<<<<<<<<<<<<
 *     marginals = mapper(scoremarginals, orders)
 *     marginals = [(0, start.frame)] + marginals + [(0, stopframe)]
 */
  __pyx_t_8 = __Pyx_PySequence_GetSlice(__pyx_v_frames, 1, -1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  if (PyList_CheckExact(__pyx_t_8) || PyTuple_CheckExact(__pyx_t_8)) {
    __pyx_t_9 = __pyx_t_8; __Pyx_INCREF(__pyx_t_9); __pyx_t_10 = 0;
    __pyx_t_11 = NULL;
  } else {
    __pyx_t_10 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = Py_TYPE(__pyx_t_9)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  for (;;) {
    if (PyList_CheckExact(__pyx_t_9)) {
      if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_9)) break;
      __pyx_t_8 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_10); __Pyx_INCREF(__pyx_t_8); __pyx_t_10++;
    } else if (PyTuple_CheckExact(__pyx_t_9)) {
      if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
      __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_10); __Pyx_INCREF(__pyx_t_8); __pyx_t_10++;
    } else {
      __pyx_t_8 = __pyx_t_11(__pyx_t_9);
      if (unlikely(!__pyx_t_8)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_8);
    }
    __Pyx_DECREF(__pyx_v_x);
    __pyx_v_x = __pyx_t_8;
    __pyx_t_8 = 0;
 194:     marginals = mapper(scoremarginals, orders)
  /* "vision/alearn/marginals.pyx":194
 *                costs[x], sigma, model.dim, start, skip, clickradius, x)
 *                for x in frames[1:-1]]
 *     marginals = mapper(scoremarginals, orders)             # <<<<<<<<<<<<<<
 *     marginals = [(0, start.frame)] + marginals + [(0, stopframe)]
 * 
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__scoremarginals); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_orders));
  PyTuple_SET_ITEM(__pyx_t_9, 1, ((PyObject *)__pyx_v_orders));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_orders));
  __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_v_mapper, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  __pyx_v_marginals = __pyx_t_3;
  __pyx_t_3 = 0;
 195:     marginals = [(0, start.frame)] + marginals + [(0, stopframe)]
  /* "vision/alearn/marginals.pyx":195
 *                for x in frames[1:-1]]
 *     marginals = mapper(scoremarginals, orders)
 *     marginals = [(0, start.frame)] + marginals + [(0, stopframe)]             # <<<<<<<<<<<<<<
 * 
 *     return marginals, path
 */
  __pyx_t_3 = PyObject_GetAttr(__pyx_v_start, __pyx_n_s__frame); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_9));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_9));
  __pyx_t_9 = 0;
  __pyx_t_9 = PyNumber_Add(((PyObject *)__pyx_t_3), __pyx_v_marginals); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_v_stopframe);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_stopframe);
  __Pyx_GIVEREF(__pyx_v_stopframe);
  __pyx_t_18 = PyList_New(1); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_18));
  PyList_SET_ITEM(__pyx_t_18, 0, ((PyObject *)__pyx_t_3));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_3));
  __pyx_t_3 = 0;
  __pyx_t_3 = PyNumber_Add(__pyx_t_9, ((PyObject *)__pyx_t_18)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_18)); __pyx_t_18 = 0;
  __Pyx_DECREF(__pyx_v_marginals);
  __pyx_v_marginals = __pyx_t_3;
  __pyx_t_3 = 0;
 196: 
 197:     return marginals, path
  /* "vision/alearn/marginals.pyx":197
 *     marginals = [(0, start.frame)] + marginals + [(0, stopframe)]
 * 
 *     return marginals, path             # <<<<<<<<<<<<<<
 * 
 * cdef double calcerroroverlap(int i, int j, annotations.Box box, double thres,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(__pyx_v_marginals);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_marginals);
  __Pyx_GIVEREF(__pyx_v_marginals);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_path);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_cur_scope->__pyx_v_path);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_path);
  __pyx_r = ((PyObject *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("vision.alearn.marginals.picksegment", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mapper);
  __Pyx_XDECREF(__pyx_v_imagesize);
  __Pyx_XDECREF(__pyx_v_stopframe);
  __Pyx_XDECREF(__pyx_v_constraints);
  __Pyx_XDECREF(__pyx_v_stopxtl);
  __Pyx_XDECREF(__pyx_v_stopytl);
  __Pyx_XDECREF(__pyx_v_frames);
  __Pyx_XDECREF(__pyx_v_orders);
  __Pyx_XDECREF(__pyx_v_costs);
  __Pyx_XDECREF(__pyx_v_forwardsargs);
  __Pyx_XDECREF(__pyx_v_backwardsargs);
  __Pyx_XDECREF(__pyx_v_forwards);
  __Pyx_XDECREF(__pyx_v_backwards);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_XDECREF(__pyx_v_frame);
  __Pyx_XDECREF(__pyx_v_pathdict);
  __Pyx_XDECREF(__pyx_v_forwarderror);
  __Pyx_XDECREF(__pyx_v_backwarderror);
  __Pyx_XDECREF(__pyx_v_marginals);
  __Pyx_XDECREF(__pyx_v_stop);
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 198: 
 199: cdef double calcerroroverlap(int i, int j, annotations.Box box, double thres,
/* "vision/alearn/marginals.pyx":199
 *     return marginals, path
 * 
 * cdef double calcerroroverlap(int i, int j, annotations.Box box, double thres,             # <<<<<<<<<<<<<<
 *                              int skip):
 *     boxw = (box.xbr - box.xtl) // skip
 */

static double __pyx_f_6vision_6alearn_9marginals_calcerroroverlap(int __pyx_v_i, int __pyx_v_j, struct __pyx_obj_6vision_11annotations_Box *__pyx_v_box, double __pyx_v_thres, int __pyx_v_skip) {
  int __pyx_v_boxw;
  int __pyx_v_boxh;
  int __pyx_v_xdiff;
  int __pyx_v_ydiff;
  double __pyx_v_error;
  long __pyx_v_uni;
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calcerroroverlap");
 200:                              int skip):
 201:     boxw = (box.xbr - box.xtl) // skip
  /* "vision/alearn/marginals.pyx":201
 * cdef double calcerroroverlap(int i, int j, annotations.Box box, double thres,
 *                              int skip):
 *     boxw = (box.xbr - box.xtl) // skip             # <<<<<<<<<<<<<<
 *     boxh = (box.ybr - box.ytl) // skip
 * 
 */
  __pyx_v_boxw = ((__pyx_v_box->xbr - __pyx_v_box->xtl) / __pyx_v_skip);
 202:     boxh = (box.ybr - box.ytl) // skip
  /* "vision/alearn/marginals.pyx":202
 *                              int skip):
 *     boxw = (box.xbr - box.xtl) // skip
 *     boxh = (box.ybr - box.ytl) // skip             # <<<<<<<<<<<<<<
 * 
 *     xdiff = min(i + boxw, box.xbr // skip) - max(i, box.xtl // skip)
 */
  __pyx_v_boxh = ((__pyx_v_box->ybr - __pyx_v_box->ytl) / __pyx_v_skip);
 203: 
 204:     xdiff = min(i + boxw, box.xbr // skip) - max(i, box.xtl // skip)
  /* "vision/alearn/marginals.pyx":204
 *     boxh = (box.ybr - box.ytl) // skip
 * 
 *     xdiff = min(i + boxw, box.xbr // skip) - max(i, box.xtl // skip)             # <<<<<<<<<<<<<<
 *     ydiff = min(j + boxh, box.ybr // skip) - max(j, box.ytl // skip)
 * 
 */
  __pyx_t_1 = (__pyx_v_box->xbr / __pyx_v_skip);
  __pyx_t_2 = (__pyx_v_i + __pyx_v_boxw);
  if ((__pyx_t_1 < __pyx_t_2)) {
    __pyx_t_3 = __pyx_t_1;
  } else {
    __pyx_t_3 = __pyx_t_2;
  }
  __pyx_t_1 = (__pyx_v_box->xtl / __pyx_v_skip);
  __pyx_t_2 = __pyx_v_i;
  if ((__pyx_t_1 > __pyx_t_2)) {
    __pyx_t_4 = __pyx_t_1;
  } else {
    __pyx_t_4 = __pyx_t_2;
  }
  __pyx_v_xdiff = (__pyx_t_3 - __pyx_t_4);
 205:     ydiff = min(j + boxh, box.ybr // skip) - max(j, box.ytl // skip)
  /* "vision/alearn/marginals.pyx":205
 * 
 *     xdiff = min(i + boxw, box.xbr // skip) - max(i, box.xtl // skip)
 *     ydiff = min(j + boxh, box.ybr // skip) - max(j, box.ytl // skip)             # <<<<<<<<<<<<<<
 * 
 *     if xdiff <= 0 or ydiff <= 0:
 */
  __pyx_t_4 = (__pyx_v_box->ybr / __pyx_v_skip);
  __pyx_t_3 = (__pyx_v_j + __pyx_v_boxh);
  if ((__pyx_t_4 < __pyx_t_3)) {
    __pyx_t_1 = __pyx_t_4;
  } else {
    __pyx_t_1 = __pyx_t_3;
  }
  __pyx_t_4 = (__pyx_v_box->ytl / __pyx_v_skip);
  __pyx_t_3 = __pyx_v_j;
  if ((__pyx_t_4 > __pyx_t_3)) {
    __pyx_t_2 = __pyx_t_4;
  } else {
    __pyx_t_2 = __pyx_t_3;
  }
  __pyx_v_ydiff = (__pyx_t_1 - __pyx_t_2);
 206: 
 207:     if xdiff <= 0 or ydiff <= 0:
  /* "vision/alearn/marginals.pyx":207
 *     ydiff = min(j + boxh, box.ybr // skip) - max(j, box.ytl // skip)
 * 
 *     if xdiff <= 0 or ydiff <= 0:             # <<<<<<<<<<<<<<
 *         error = 1.
 *     else:
 */
  __pyx_t_5 = (__pyx_v_xdiff <= 0);
  if (!__pyx_t_5) {
    __pyx_t_6 = (__pyx_v_ydiff <= 0);
    __pyx_t_7 = __pyx_t_6;
  } else {
    __pyx_t_7 = __pyx_t_5;
  }
  if (__pyx_t_7) {
 208:         error = 1.
    /* "vision/alearn/marginals.pyx":208
 * 
 *     if xdiff <= 0 or ydiff <= 0:
 *         error = 1.             # <<<<<<<<<<<<<<
 *     else:
 *         uni = boxw * boxh * 2 - xdiff * ydiff
 */
    __pyx_v_error = 1.;
    goto __pyx_L3;
  }
  /*else*/ {
 209:     else:
 210:         uni = boxw * boxh * 2 - xdiff * ydiff
    /* "vision/alearn/marginals.pyx":210
 *         error = 1.
 *     else:
 *         uni = boxw * boxh * 2 - xdiff * ydiff             # <<<<<<<<<<<<<<
 *         error = xdiff * ydiff / float(uni)
 *         if error >= thres:
 */
    __pyx_v_uni = (((__pyx_v_boxw * __pyx_v_boxh) * 2) - (__pyx_v_xdiff * __pyx_v_ydiff));
 211:         error = xdiff * ydiff / float(uni)
    /* "vision/alearn/marginals.pyx":211
 *     else:
 *         uni = boxw * boxh * 2 - xdiff * ydiff
 *         error = xdiff * ydiff / float(uni)             # <<<<<<<<<<<<<<
 *         if error >= thres:
 *             error = 0.
 */
    __pyx_v_error = ((__pyx_v_xdiff * __pyx_v_ydiff) / ((double)__pyx_v_uni));
 212:         if error >= thres:
    /* "vision/alearn/marginals.pyx":212
 *         uni = boxw * boxh * 2 - xdiff * ydiff
 *         error = xdiff * ydiff / float(uni)
 *         if error >= thres:             # <<<<<<<<<<<<<<
 *             error = 0.
 *         else:
 */
    __pyx_t_7 = (__pyx_v_error >= __pyx_v_thres);
    if (__pyx_t_7) {
 213:             error = 0.
      /* "vision/alearn/marginals.pyx":213
 *         error = xdiff * ydiff / float(uni)
 *         if error >= thres:
 *             error = 0.             # <<<<<<<<<<<<<<
 *         else:
 *             error = 1.
 */
      __pyx_v_error = 0.;
      goto __pyx_L4;
    }
    /*else*/ {
 214:         else:
 215:             error = 1.
      /* "vision/alearn/marginals.pyx":215
 *             error = 0.
 *         else:
 *             error = 1.             # <<<<<<<<<<<<<<
 *     return error
 * 
 */
      __pyx_v_error = 1.;
    }
    __pyx_L4:;
  }
  __pyx_L3:;
 216:     return error
  /* "vision/alearn/marginals.pyx":216
 *         else:
 *             error = 1.
 *     return error             # <<<<<<<<<<<<<<
 * 
 * def calcerror(pathdict, pointers, double erroroverlap, int skip, frames):
 */
  __pyx_r = __pyx_v_error;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 217: 
 218: def calcerror(pathdict, pointers, double erroroverlap, int skip, frames):
/* "vision/alearn/marginals.pyx":218
 *     return error
 * 
 * def calcerror(pathdict, pointers, double erroroverlap, int skip, frames):             # <<<<<<<<<<<<<<
 *     """
 *     Calculates the error going through a path at a certain point.
 */

static PyObject *__pyx_pf_6vision_6alearn_9marginals_2calcerror(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6vision_6alearn_9marginals_2calcerror[] = "calcerror(pathdict, pointers, double erroroverlap, int skip, frames)\n\n    Calculates the error going through a path at a certain point.\n\n    We use dynamic programming to calculate error here in order to speed up\n    the error calculation. We simply use the pairwise results from the\n    previous results.\n    ";
static PyMethodDef __pyx_mdef_6vision_6alearn_9marginals_2calcerror = {__Pyx_NAMESTR("calcerror"), (PyCFunction)__pyx_pf_6vision_6alearn_9marginals_2calcerror, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6vision_6alearn_9marginals_2calcerror)};
static PyObject *__pyx_pf_6vision_6alearn_9marginals_2calcerror(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_pathdict = 0;
  PyObject *__pyx_v_pointers = 0;
  double __pyx_v_erroroverlap;
  int __pyx_v_skip;
  PyObject *__pyx_v_frames = 0;
  int __pyx_v_frame;
  struct __pyx_obj_6vision_11annotations_Box *__pyx_v_box = 0;
  PyArrayObject *__pyx_v_previous = 0;
  PyArrayObject *__pyx_v_current = 0;
  PyArrayObject *__pyx_v_local = 0;
  PyArrayObject *__pyx_v_xpointer = 0;
  PyArrayObject *__pyx_v_ypointer = 0;
  PyObject *__pyx_v_size = NULL;
  int __pyx_v_w;
  int __pyx_v_h;
  int __pyx_v_xp;
  int __pyx_v_yp;
  double __pyx_v_message;
  PyObject *__pyx_v_graph = NULL;
  int __pyx_v_i;
  int __pyx_v_j;
  double __pyx_v_error;
  Py_buffer __pyx_bstruct_current;
  Py_ssize_t __pyx_bstride_0_current = 0;
  Py_ssize_t __pyx_bstride_1_current = 0;
  Py_ssize_t __pyx_bshape_0_current = 0;
  Py_ssize_t __pyx_bshape_1_current = 0;
  Py_buffer __pyx_bstruct_xpointer;
  Py_ssize_t __pyx_bstride_0_xpointer = 0;
  Py_ssize_t __pyx_bstride_1_xpointer = 0;
  Py_ssize_t __pyx_bshape_0_xpointer = 0;
  Py_ssize_t __pyx_bshape_1_xpointer = 0;
  Py_buffer __pyx_bstruct_local;
  Py_ssize_t __pyx_bstride_0_local = 0;
  Py_ssize_t __pyx_bstride_1_local = 0;
  Py_ssize_t __pyx_bshape_0_local = 0;
  Py_ssize_t __pyx_bshape_1_local = 0;
  Py_buffer __pyx_bstruct_ypointer;
  Py_ssize_t __pyx_bstride_0_ypointer = 0;
  Py_ssize_t __pyx_bstride_1_ypointer = 0;
  Py_ssize_t __pyx_bshape_0_ypointer = 0;
  Py_ssize_t __pyx_bshape_1_ypointer = 0;
  Py_buffer __pyx_bstruct_previous;
  Py_ssize_t __pyx_bstride_0_previous = 0;
  Py_ssize_t __pyx_bstride_1_previous = 0;
  Py_ssize_t __pyx_bshape_0_previous = 0;
  Py_ssize_t __pyx_bshape_1_previous = 0;
  PyObject *__pyx_r = NULL;
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__pathdict,&__pyx_n_s__pointers,&__pyx_n_s__erroroverlap,&__pyx_n_s__skip,&__pyx_n_s__frames,0};
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calcerror");
  __pyx_self = __pyx_self;
  {
    PyObject* values[5] = {0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  0:
        values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pathdict);
        if (likely(values[0])) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pointers);
        if (likely(values[1])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcerror", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__erroroverlap);
        if (likely(values[2])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcerror", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__skip);
        if (likely(values[3])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcerror", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__frames);
        if (likely(values[4])) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcerror", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "calcerror") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
    }
    __pyx_v_pathdict = values[0];
    __pyx_v_pointers = values[1];
    __pyx_v_erroroverlap = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_erroroverlap == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_skip = __Pyx_PyInt_AsInt(values[3]); if (unlikely((__pyx_v_skip == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_frames = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calcerror", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("vision.alearn.marginals.calcerror", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_bstruct_previous.buf = NULL;
  __pyx_bstruct_current.buf = NULL;
  __pyx_bstruct_local.buf = NULL;
  __pyx_bstruct_xpointer.buf = NULL;
  __pyx_bstruct_ypointer.buf = NULL;

  /* "vision/alearn/marginals.pyx":218
 *     return error
 * 
 * def calcerror(pathdict, pointers, double erroroverlap, int skip, frames):             # <<<<<<<<<<<<<<
 *     """
 *     Calculates the error going through a path at a certain point.
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6vision_6alearn_9marginals_2calcerror, NULL, __pyx_n_s_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__calcerror, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 219:     """
 220:     Calculates the error going through a path at a certain point.
 221: 
 222:     We use dynamic programming to calculate error here in order to speed up
 223:     the error calculation. We simply use the pairwise results from the
 224:     previous results.
 225:     """
 226:     cdef int frame = frames[0]
  /* "vision/alearn/marginals.pyx":226
 *     previous results.
 *     """
 *     cdef int frame = frames[0]             # <<<<<<<<<<<<<<
 *     cdef annotations.Box box = pathdict[frame]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] previous, current, local
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_frames, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 226; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_frame = __pyx_t_2;
 227:     cdef annotations.Box box = pathdict[frame]
  /* "vision/alearn/marginals.pyx":227
 *     """
 *     cdef int frame = frames[0]
 *     cdef annotations.Box box = pathdict[frame]             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] previous, current, local
 *     cdef numpy.ndarray[numpy.int_t, ndim=2] xpointer, ypointer
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_pathdict, __pyx_v_frame, sizeof(int), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_6vision_11annotations_Box))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_box = ((struct __pyx_obj_6vision_11annotations_Box *)__pyx_t_1);
  __pyx_t_1 = 0;
 228:     cdef numpy.ndarray[numpy.double_t, ndim=2] previous, current, local
 229:     cdef numpy.ndarray[numpy.int_t, ndim=2] xpointer, ypointer
 230:     size = pointers[frames[-1]][1].shape
  /* "vision/alearn/marginals.pyx":230
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] previous, current, local
 *     cdef numpy.ndarray[numpy.int_t, ndim=2] xpointer, ypointer
 *     size = pointers[frames[-1]][1].shape             # <<<<<<<<<<<<<<
 *     cdef int w = size[0], h = size[1]
 *     cdef int xp, yp
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_frames, -1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PyObject_GetItem(__pyx_v_pointers, __pyx_t_1); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__shape); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_size = __pyx_t_3;
  __pyx_t_3 = 0;
 231:     cdef int w = size[0], h = size[1]
  /* "vision/alearn/marginals.pyx":231
 *     cdef numpy.ndarray[numpy.int_t, ndim=2] xpointer, ypointer
 *     size = pointers[frames[-1]][1].shape
 *     cdef int w = size[0], h = size[1]             # <<<<<<<<<<<<<<
 *     cdef int xp, yp
 *     cdef double message
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_size, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_w = __pyx_t_2;
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_size, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_3); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_h = __pyx_t_2;
 232:     cdef int xp, yp
 233:     cdef double message
 234: 
 235:     graph = {}
  /* "vision/alearn/marginals.pyx":235
 *     cdef double message
 * 
 *     graph = {}             # <<<<<<<<<<<<<<
 * 
 *     # setup the base case
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __pyx_v_graph = __pyx_t_3;
  __pyx_t_3 = 0;
 236: 
 237:     # setup the base case
 238:     previous = numpy.zeros(size, dtype = numpy.double)
  /* "vision/alearn/marginals.pyx":238
 * 
 *     # setup the base case
 *     previous = numpy.zeros(size, dtype = numpy.double)             # <<<<<<<<<<<<<<
 *     for i in range(w):
 *         for j in range(h):
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  __Pyx_INCREF(__pyx_v_size);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_size);
  __Pyx_GIVEREF(__pyx_v_size);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__double); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dtype), __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_previous);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_previous, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_previous, (PyObject*)__pyx_v_previous, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_bstride_0_previous = __pyx_bstruct_previous.strides[0]; __pyx_bstride_1_previous = __pyx_bstruct_previous.strides[1];
    __pyx_bshape_0_previous = __pyx_bstruct_previous.shape[0]; __pyx_bshape_1_previous = __pyx_bstruct_previous.shape[1];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_7 = 0;
  __pyx_v_previous = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;
 239:     for i in range(w):
  /* "vision/alearn/marginals.pyx":239
 *     # setup the base case
 *     previous = numpy.zeros(size, dtype = numpy.double)
 *     for i in range(w):             # <<<<<<<<<<<<<<
 *         for j in range(h):
 *             previous[i, j] = calcerroroverlap(i, j, box, erroroverlap, skip)
 */
  __pyx_t_2 = __pyx_v_w;
  for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_2; __pyx_t_11+=1) {
    __pyx_v_i = __pyx_t_11;
 240:         for j in range(h):
    /* "vision/alearn/marginals.pyx":240
 *     previous = numpy.zeros(size, dtype = numpy.double)
 *     for i in range(w):
 *         for j in range(h):             # <<<<<<<<<<<<<<
 *             previous[i, j] = calcerroroverlap(i, j, box, erroroverlap, skip)
 *     graph[frame] = previous, previous
 */
    __pyx_t_12 = __pyx_v_h;
    for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
      __pyx_v_j = __pyx_t_13;
 241:             previous[i, j] = calcerroroverlap(i, j, box, erroroverlap, skip)
      /* "vision/alearn/marginals.pyx":241
 *     for i in range(w):
 *         for j in range(h):
 *             previous[i, j] = calcerroroverlap(i, j, box, erroroverlap, skip)             # <<<<<<<<<<<<<<
 *     graph[frame] = previous, previous
 * 
 */
      __pyx_t_14 = __pyx_v_i;
      __pyx_t_15 = __pyx_v_j;
      if (__pyx_t_14 < 0) __pyx_t_14 += __pyx_bshape_0_previous;
      if (__pyx_t_15 < 0) __pyx_t_15 += __pyx_bshape_1_previous;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_previous.buf, __pyx_t_14, __pyx_bstride_0_previous, __pyx_t_15, __pyx_bstride_1_previous) = __pyx_f_6vision_6alearn_9marginals_calcerroroverlap(__pyx_v_i, __pyx_v_j, __pyx_v_box, __pyx_v_erroroverlap, __pyx_v_skip);
    }
  }
 242:     graph[frame] = previous, previous
  /* "vision/alearn/marginals.pyx":242
 *         for j in range(h):
 *             previous[i, j] = calcerroroverlap(i, j, box, erroroverlap, skip)
 *     graph[frame] = previous, previous             # <<<<<<<<<<<<<<
 * 
 *     # do the inductive steps
 */
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_6));
  __Pyx_INCREF(((PyObject *)__pyx_v_previous));
  PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_previous));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_previous));
  __Pyx_INCREF(((PyObject *)__pyx_v_previous));
  PyTuple_SET_ITEM(__pyx_t_6, 1, ((PyObject *)__pyx_v_previous));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_previous));
  if (__Pyx_SetItemInt(((PyObject *)__pyx_v_graph), __pyx_v_frame, ((PyObject *)__pyx_t_6), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
 243: 
 244:     # do the inductive steps
 245:     for frame in frames[1:]:
  /* "vision/alearn/marginals.pyx":245
 * 
 *     # do the inductive steps
 *     for frame in frames[1:]:             # <<<<<<<<<<<<<<
 *         current = numpy.zeros(size, dtype = numpy.double)
 *         local = numpy.zeros(size, dtype = numpy.double)
 */
  __pyx_t_6 = __Pyx_PySequence_GetSlice(__pyx_v_frames, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (PyList_CheckExact(__pyx_t_6) || PyTuple_CheckExact(__pyx_t_6)) {
    __pyx_t_4 = __pyx_t_6; __Pyx_INCREF(__pyx_t_4); __pyx_t_16 = 0;
    __pyx_t_17 = NULL;
  } else {
    __pyx_t_16 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_17 = Py_TYPE(__pyx_t_4)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  for (;;) {
    if (PyList_CheckExact(__pyx_t_4)) {
      if (__pyx_t_16 >= PyList_GET_SIZE(__pyx_t_4)) break;
      __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_16); __Pyx_INCREF(__pyx_t_6); __pyx_t_16++;
    } else if (PyTuple_CheckExact(__pyx_t_4)) {
      if (__pyx_t_16 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
      __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_16); __Pyx_INCREF(__pyx_t_6); __pyx_t_16++;
    } else {
      __pyx_t_6 = __pyx_t_17(__pyx_t_4);
      if (unlikely(!__pyx_t_6)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_6);
    }
    __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_6); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_frame = __pyx_t_2;
 246:         current = numpy.zeros(size, dtype = numpy.double)
    /* "vision/alearn/marginals.pyx":246
 *     # do the inductive steps
 *     for frame in frames[1:]:
 *         current = numpy.zeros(size, dtype = numpy.double)             # <<<<<<<<<<<<<<
 *         local = numpy.zeros(size, dtype = numpy.double)
 *         box = pathdict[frame]
 */
    __pyx_t_6 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_6, __pyx_n_s__zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __Pyx_INCREF(__pyx_v_size);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_size);
    __Pyx_GIVEREF(__pyx_v_size);
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_1));
    __pyx_t_5 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_18 = PyObject_GetAttr(__pyx_t_5, __pyx_n_s__double); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_18) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = PyEval_CallObjectWithKeywords(__pyx_t_3, ((PyObject *)__pyx_t_6), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    if (!(likely(((__pyx_t_18) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_18, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = ((PyArrayObject *)__pyx_t_18);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_bstruct_current);
      __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_current, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_2 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_current, (PyObject*)__pyx_v_current, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
      }
      __pyx_bstride_0_current = __pyx_bstruct_current.strides[0]; __pyx_bstride_1_current = __pyx_bstruct_current.strides[1];
      __pyx_bshape_0_current = __pyx_bstruct_current.shape[0]; __pyx_bshape_1_current = __pyx_bstruct_current.shape[1];
      if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_7 = 0;
    __Pyx_XDECREF(((PyObject *)__pyx_v_current));
    __pyx_v_current = ((PyArrayObject *)__pyx_t_18);
    __pyx_t_18 = 0;
 247:         local = numpy.zeros(size, dtype = numpy.double)
    /* "vision/alearn/marginals.pyx":247
 *     for frame in frames[1:]:
 *         current = numpy.zeros(size, dtype = numpy.double)
 *         local = numpy.zeros(size, dtype = numpy.double)             # <<<<<<<<<<<<<<
 *         box = pathdict[frame]
 *         xpointer = pointers[frame][1]
 */
    __pyx_t_18 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_1 = PyObject_GetAttr(__pyx_t_18, __pyx_n_s__zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_18));
    __Pyx_INCREF(__pyx_v_size);
    PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_v_size);
    __Pyx_GIVEREF(__pyx_v_size);
    __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_6));
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__double); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_6, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyEval_CallObjectWithKeywords(__pyx_t_1, ((PyObject *)__pyx_t_18), ((PyObject *)__pyx_t_6)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_18)); __pyx_t_18 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_bstruct_local);
      __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_local, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_2 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_local, (PyObject*)__pyx_v_local, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
      }
      __pyx_bstride_0_local = __pyx_bstruct_local.strides[0]; __pyx_bstride_1_local = __pyx_bstruct_local.strides[1];
      __pyx_bshape_0_local = __pyx_bstruct_local.shape[0]; __pyx_bshape_1_local = __pyx_bstruct_local.shape[1];
      if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_7 = 0;
    __Pyx_XDECREF(((PyObject *)__pyx_v_local));
    __pyx_v_local = ((PyArrayObject *)__pyx_t_5);
    __pyx_t_5 = 0;
 248:         box = pathdict[frame]
    /* "vision/alearn/marginals.pyx":248
 *         current = numpy.zeros(size, dtype = numpy.double)
 *         local = numpy.zeros(size, dtype = numpy.double)
 *         box = pathdict[frame]             # <<<<<<<<<<<<<<
 *         xpointer = pointers[frame][1]
 *         ypointer = pointers[frame][2]
 */
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_pathdict, __pyx_v_frame, sizeof(int), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_6vision_11annotations_Box))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_v_box));
    __pyx_v_box = ((struct __pyx_obj_6vision_11annotations_Box *)__pyx_t_5);
    __pyx_t_5 = 0;
 249:         xpointer = pointers[frame][1]
    /* "vision/alearn/marginals.pyx":249
 *         local = numpy.zeros(size, dtype = numpy.double)
 *         box = pathdict[frame]
 *         xpointer = pointers[frame][1]             # <<<<<<<<<<<<<<
 *         ypointer = pointers[frame][2]
 * 
 */
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_pointers, __pyx_v_frame, sizeof(int), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_t_5, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_19 = ((PyArrayObject *)__pyx_t_6);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_bstruct_xpointer);
      __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_xpointer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_2 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_xpointer, (PyObject*)__pyx_v_xpointer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
      }
      __pyx_bstride_0_xpointer = __pyx_bstruct_xpointer.strides[0]; __pyx_bstride_1_xpointer = __pyx_bstruct_xpointer.strides[1];
      __pyx_bshape_0_xpointer = __pyx_bstruct_xpointer.shape[0]; __pyx_bshape_1_xpointer = __pyx_bstruct_xpointer.shape[1];
      if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_19 = 0;
    __Pyx_XDECREF(((PyObject *)__pyx_v_xpointer));
    __pyx_v_xpointer = ((PyArrayObject *)__pyx_t_6);
    __pyx_t_6 = 0;
 250:         ypointer = pointers[frame][2]
    /* "vision/alearn/marginals.pyx":250
 *         box = pathdict[frame]
 *         xpointer = pointers[frame][1]
 *         ypointer = pointers[frame][2]             # <<<<<<<<<<<<<<
 * 
 *         for i in range(w):
 */
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_pointers, __pyx_v_frame, sizeof(int), PyInt_FromLong); if (!__pyx_t_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_6, 2, sizeof(long), PyInt_FromLong); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_19 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ypointer);
      __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_ypointer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_2 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_ypointer, (PyObject*)__pyx_v_ypointer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
      }
      __pyx_bstride_0_ypointer = __pyx_bstruct_ypointer.strides[0]; __pyx_bstride_1_ypointer = __pyx_bstruct_ypointer.strides[1];
      __pyx_bshape_0_ypointer = __pyx_bstruct_ypointer.shape[0]; __pyx_bshape_1_ypointer = __pyx_bstruct_ypointer.shape[1];
      if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_19 = 0;
    __Pyx_XDECREF(((PyObject *)__pyx_v_ypointer));
    __pyx_v_ypointer = ((PyArrayObject *)__pyx_t_5);
    __pyx_t_5 = 0;
 251: 
 252:         for i in range(w):
    /* "vision/alearn/marginals.pyx":252
 *         ypointer = pointers[frame][2]
 * 
 *         for i in range(w):             # <<<<<<<<<<<<<<
 *             for j in range(h):
 *                 error = calcerroroverlap(i, j, box, erroroverlap, skip)
 */
    __pyx_t_2 = __pyx_v_w;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_2; __pyx_t_11+=1) {
      __pyx_v_i = __pyx_t_11;
 253:             for j in range(h):
      /* "vision/alearn/marginals.pyx":253
 * 
 *         for i in range(w):
 *             for j in range(h):             # <<<<<<<<<<<<<<
 *                 error = calcerroroverlap(i, j, box, erroroverlap, skip)
 *                 xp = xpointer[i, j]
 */
      __pyx_t_12 = __pyx_v_h;
      for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
        __pyx_v_j = __pyx_t_13;
 254:                 error = calcerroroverlap(i, j, box, erroroverlap, skip)
        /* "vision/alearn/marginals.pyx":254
 *         for i in range(w):
 *             for j in range(h):
 *                 error = calcerroroverlap(i, j, box, erroroverlap, skip)             # <<<<<<<<<<<<<<
 *                 xp = xpointer[i, j]
 *                 yp = ypointer[i, j]
 */
        __pyx_v_error = __pyx_f_6vision_6alearn_9marginals_calcerroroverlap(__pyx_v_i, __pyx_v_j, __pyx_v_box, __pyx_v_erroroverlap, __pyx_v_skip);
 255:                 xp = xpointer[i, j]
        /* "vision/alearn/marginals.pyx":255
 *             for j in range(h):
 *                 error = calcerroroverlap(i, j, box, erroroverlap, skip)
 *                 xp = xpointer[i, j]             # <<<<<<<<<<<<<<
 *                 yp = ypointer[i, j]
 *                 message = previous[xp, yp]
 */
        __pyx_t_20 = __pyx_v_i;
        __pyx_t_21 = __pyx_v_j;
        if (__pyx_t_20 < 0) __pyx_t_20 += __pyx_bshape_0_xpointer;
        if (__pyx_t_21 < 0) __pyx_t_21 += __pyx_bshape_1_xpointer;
        __pyx_v_xp = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_xpointer.buf, __pyx_t_20, __pyx_bstride_0_xpointer, __pyx_t_21, __pyx_bstride_1_xpointer));
 256:                 yp = ypointer[i, j]
        /* "vision/alearn/marginals.pyx":256
 *                 error = calcerroroverlap(i, j, box, erroroverlap, skip)
 *                 xp = xpointer[i, j]
 *                 yp = ypointer[i, j]             # <<<<<<<<<<<<<<
 *                 message = previous[xp, yp]
 *                 local[i, j] = error
 */
        __pyx_t_22 = __pyx_v_i;
        __pyx_t_23 = __pyx_v_j;
        if (__pyx_t_22 < 0) __pyx_t_22 += __pyx_bshape_0_ypointer;
        if (__pyx_t_23 < 0) __pyx_t_23 += __pyx_bshape_1_ypointer;
        __pyx_v_yp = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_int_t *, __pyx_bstruct_ypointer.buf, __pyx_t_22, __pyx_bstride_0_ypointer, __pyx_t_23, __pyx_bstride_1_ypointer));
 257:                 message = previous[xp, yp]
        /* "vision/alearn/marginals.pyx":257
 *                 xp = xpointer[i, j]
 *                 yp = ypointer[i, j]
 *                 message = previous[xp, yp]             # <<<<<<<<<<<<<<
 *                 local[i, j] = error
 *                 current[i, j] = error + message
 */
        __pyx_t_24 = __pyx_v_xp;
        __pyx_t_25 = __pyx_v_yp;
        if (__pyx_t_24 < 0) __pyx_t_24 += __pyx_bshape_0_previous;
        if (__pyx_t_25 < 0) __pyx_t_25 += __pyx_bshape_1_previous;
        __pyx_v_message = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_previous.buf, __pyx_t_24, __pyx_bstride_0_previous, __pyx_t_25, __pyx_bstride_1_previous));
 258:                 local[i, j] = error
        /* "vision/alearn/marginals.pyx":258
 *                 yp = ypointer[i, j]
 *                 message = previous[xp, yp]
 *                 local[i, j] = error             # <<<<<<<<<<<<<<
 *                 current[i, j] = error + message
 *         graph[frame] = current, local
 */
        __pyx_t_26 = __pyx_v_i;
        __pyx_t_27 = __pyx_v_j;
        if (__pyx_t_26 < 0) __pyx_t_26 += __pyx_bshape_0_local;
        if (__pyx_t_27 < 0) __pyx_t_27 += __pyx_bshape_1_local;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_local.buf, __pyx_t_26, __pyx_bstride_0_local, __pyx_t_27, __pyx_bstride_1_local) = __pyx_v_error;
 259:                 current[i, j] = error + message
        /* "vision/alearn/marginals.pyx":259
 *                 message = previous[xp, yp]
 *                 local[i, j] = error
 *                 current[i, j] = error + message             # <<<<<<<<<<<<<<
 *         graph[frame] = current, local
 *         previous = current
 */
        __pyx_t_28 = __pyx_v_i;
        __pyx_t_29 = __pyx_v_j;
        if (__pyx_t_28 < 0) __pyx_t_28 += __pyx_bshape_0_current;
        if (__pyx_t_29 < 0) __pyx_t_29 += __pyx_bshape_1_current;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_current.buf, __pyx_t_28, __pyx_bstride_0_current, __pyx_t_29, __pyx_bstride_1_current) = (__pyx_v_error + __pyx_v_message);
      }
    }
 260:         graph[frame] = current, local
    /* "vision/alearn/marginals.pyx":260
 *                 local[i, j] = error
 *                 current[i, j] = error + message
 *         graph[frame] = current, local             # <<<<<<<<<<<<<<
 *         previous = current
 *     return graph
 */
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_5));
    __Pyx_INCREF(((PyObject *)__pyx_v_current));
    PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_current));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_current));
    __Pyx_INCREF(((PyObject *)__pyx_v_local));
    PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_local));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_local));
    if (__Pyx_SetItemInt(((PyObject *)__pyx_v_graph), __pyx_v_frame, ((PyObject *)__pyx_t_5), sizeof(int), PyInt_FromLong) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
 261:         previous = current
    /* "vision/alearn/marginals.pyx":261
 *                 current[i, j] = error + message
 *         graph[frame] = current, local
 *         previous = current             # <<<<<<<<<<<<<<
 *     return graph
 * 
 */
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_bstruct_previous);
      __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_previous, (PyObject*)__pyx_v_current, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_2 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_previous, (PyObject*)__pyx_v_previous, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
      }
      __pyx_bstride_0_previous = __pyx_bstruct_previous.strides[0]; __pyx_bstride_1_previous = __pyx_bstruct_previous.strides[1];
      __pyx_bshape_0_previous = __pyx_bstruct_previous.shape[0]; __pyx_bshape_1_previous = __pyx_bstruct_previous.shape[1];
      if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_current));
    __Pyx_DECREF(((PyObject *)__pyx_v_previous));
    __pyx_v_previous = __pyx_v_current;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 262:     return graph
  /* "vision/alearn/marginals.pyx":262
 *         graph[frame] = current, local
 *         previous = current
 *     return graph             # <<<<<<<<<<<<<<
 * 
 * def scoremarginals(workorder):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_graph));
  __pyx_r = ((PyObject *)__pyx_v_graph);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_18);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_current);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_xpointer);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_local);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ypointer);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_previous);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("vision.alearn.marginals.calcerror", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_current);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_xpointer);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_local);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_ypointer);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_previous);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_box);
  __Pyx_XDECREF((PyObject *)__pyx_v_previous);
  __Pyx_XDECREF((PyObject *)__pyx_v_current);
  __Pyx_XDECREF((PyObject *)__pyx_v_local);
  __Pyx_XDECREF((PyObject *)__pyx_v_xpointer);
  __Pyx_XDECREF((PyObject *)__pyx_v_ypointer);
  __Pyx_XDECREF(__pyx_v_size);
  __Pyx_XDECREF(__pyx_v_graph);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 263: 
 264: def scoremarginals(workorder):
/* "vision/alearn/marginals.pyx":264
 *     return graph
 * 
 * def scoremarginals(workorder):             # <<<<<<<<<<<<<<
 *     cdef double sigma
 *     cdef int frame, radius
 */

static PyObject *__pyx_pf_6vision_6alearn_9marginals_3scoremarginals(PyObject *__pyx_self, PyObject *__pyx_v_workorder); /*proto*/
static char __pyx_doc_6vision_6alearn_9marginals_3scoremarginals[] = "scoremarginals(workorder)";
static PyMethodDef __pyx_mdef_6vision_6alearn_9marginals_3scoremarginals = {__Pyx_NAMESTR("scoremarginals"), (PyCFunction)__pyx_pf_6vision_6alearn_9marginals_3scoremarginals, METH_O, __Pyx_DOCSTR(__pyx_doc_6vision_6alearn_9marginals_3scoremarginals)};
static PyObject *__pyx_pf_6vision_6alearn_9marginals_3scoremarginals(PyObject *__pyx_self, PyObject *__pyx_v_workorder) {
  double __pyx_v_sigma;
  int __pyx_v_frame;
  int __pyx_v_radius;
  struct __pyx_obj_6vision_11annotations_Box *__pyx_v_start = 0;
  PyObject *__pyx_v_forw = NULL;
  PyObject *__pyx_v_backw = NULL;
  PyObject *__pyx_v_forwerr = NULL;
  PyObject *__pyx_v_backwerr = NULL;
  PyObject *__pyx_v_costs = NULL;
  PyObject *__pyx_v_dim = NULL;
  PyObject *__pyx_v_skip = NULL;
  double __pyx_v_score;
  double __pyx_v_normalizer;
  double __pyx_v_matchscore;
  double __pyx_v_localscore;
  PyArrayObject *__pyx_v_forwrt = 0;
  PyArrayObject *__pyx_v_backwrt = 0;
  PyArrayObject *__pyx_v_costrt = 0;
  PyArrayObject *__pyx_v_forwe = 0;
  PyArrayObject *__pyx_v_backwe = 0;
  PyArrayObject *__pyx_v_forwloce = 0;
  int __pyx_v_w;
  int __pyx_v_h;
  double __pyx_v_wr;
  double __pyx_v_hr;
  PyArrayObject *__pyx_v_gprob = 0;
  PyArrayObject *__pyx_v_greduct = 0;
  PyArrayObject *__pyx_v_gerrors = 0;
  PyArrayObject *__pyx_v_gmargin = 0;
  PyArrayObject *__pyx_v_matchscores = 0;
  PyArrayObject *__pyx_v_errors = 0;
  PyArrayObject *__pyx_v_errorsvert = 0;
  double __pyx_v_maxmatchscore;
  int __pyx_v_i;
  int __pyx_v_j;
  long __pyx_v_y;
  long __pyx_v_x;
  Py_buffer __pyx_bstruct_backwrt;
  Py_ssize_t __pyx_bstride_0_backwrt = 0;
  Py_ssize_t __pyx_bstride_1_backwrt = 0;
  Py_ssize_t __pyx_bshape_0_backwrt = 0;
  Py_ssize_t __pyx_bshape_1_backwrt = 0;
  Py_buffer __pyx_bstruct_errorsvert;
  Py_ssize_t __pyx_bstride_0_errorsvert = 0;
  Py_ssize_t __pyx_bstride_1_errorsvert = 0;
  Py_ssize_t __pyx_bshape_0_errorsvert = 0;
  Py_ssize_t __pyx_bshape_1_errorsvert = 0;
  Py_buffer __pyx_bstruct_forwrt;
  Py_ssize_t __pyx_bstride_0_forwrt = 0;
  Py_ssize_t __pyx_bstride_1_forwrt = 0;
  Py_ssize_t __pyx_bshape_0_forwrt = 0;
  Py_ssize_t __pyx_bshape_1_forwrt = 0;
  Py_buffer __pyx_bstruct_matchscores;
  Py_ssize_t __pyx_bstride_0_matchscores = 0;
  Py_ssize_t __pyx_bstride_1_matchscores = 0;
  Py_ssize_t __pyx_bshape_0_matchscores = 0;
  Py_ssize_t __pyx_bshape_1_matchscores = 0;
  Py_buffer __pyx_bstruct_errors;
  Py_ssize_t __pyx_bstride_0_errors = 0;
  Py_ssize_t __pyx_bstride_1_errors = 0;
  Py_ssize_t __pyx_bshape_0_errors = 0;
  Py_ssize_t __pyx_bshape_1_errors = 0;
  Py_buffer __pyx_bstruct_gprob;
  Py_ssize_t __pyx_bstride_0_gprob = 0;
  Py_ssize_t __pyx_bstride_1_gprob = 0;
  Py_ssize_t __pyx_bshape_0_gprob = 0;
  Py_ssize_t __pyx_bshape_1_gprob = 0;
  Py_buffer __pyx_bstruct_forwloce;
  Py_ssize_t __pyx_bstride_0_forwloce = 0;
  Py_ssize_t __pyx_bstride_1_forwloce = 0;
  Py_ssize_t __pyx_bshape_0_forwloce = 0;
  Py_ssize_t __pyx_bshape_1_forwloce = 0;
  Py_buffer __pyx_bstruct_costrt;
  Py_ssize_t __pyx_bstride_0_costrt = 0;
  Py_ssize_t __pyx_bstride_1_costrt = 0;
  Py_ssize_t __pyx_bshape_0_costrt = 0;
  Py_ssize_t __pyx_bshape_1_costrt = 0;
  Py_buffer __pyx_bstruct_backwe;
  Py_ssize_t __pyx_bstride_0_backwe = 0;
  Py_ssize_t __pyx_bstride_1_backwe = 0;
  Py_ssize_t __pyx_bshape_0_backwe = 0;
  Py_ssize_t __pyx_bshape_1_backwe = 0;
  Py_buffer __pyx_bstruct_forwe;
  Py_ssize_t __pyx_bstride_0_forwe = 0;
  Py_ssize_t __pyx_bstride_1_forwe = 0;
  Py_ssize_t __pyx_bshape_0_forwe = 0;
  Py_ssize_t __pyx_bshape_1_forwe = 0;
  Py_buffer __pyx_bstruct_gerrors;
  Py_ssize_t __pyx_bstride_0_gerrors = 0;
  Py_ssize_t __pyx_bstride_1_gerrors = 0;
  Py_ssize_t __pyx_bshape_0_gerrors = 0;
  Py_ssize_t __pyx_bshape_1_gerrors = 0;
  Py_buffer __pyx_bstruct_greduct;
  Py_ssize_t __pyx_bstride_0_greduct = 0;
  Py_ssize_t __pyx_bstride_1_greduct = 0;
  Py_ssize_t __pyx_bshape_0_greduct = 0;
  Py_ssize_t __pyx_bshape_1_greduct = 0;
  Py_buffer __pyx_bstruct_gmargin;
  Py_ssize_t __pyx_bstride_0_gmargin = 0;
  Py_ssize_t __pyx_bstride_1_gmargin = 0;
  Py_ssize_t __pyx_bshape_0_gmargin = 0;
  Py_ssize_t __pyx_bshape_1_gmargin = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("scoremarginals");
  __pyx_self = __pyx_self;
  __pyx_bstruct_forwrt.buf = NULL;
  __pyx_bstruct_backwrt.buf = NULL;
  __pyx_bstruct_costrt.buf = NULL;
  __pyx_bstruct_forwe.buf = NULL;
  __pyx_bstruct_backwe.buf = NULL;
  __pyx_bstruct_forwloce.buf = NULL;
  __pyx_bstruct_gprob.buf = NULL;
  __pyx_bstruct_greduct.buf = NULL;
  __pyx_bstruct_gerrors.buf = NULL;
  __pyx_bstruct_gmargin.buf = NULL;
  __pyx_bstruct_matchscores.buf = NULL;
  __pyx_bstruct_errors.buf = NULL;
  __pyx_bstruct_errorsvert.buf = NULL;

  /* "vision/alearn/marginals.pyx":264
 *     return graph
 * 
 * def scoremarginals(workorder):             # <<<<<<<<<<<<<<
 *     cdef double sigma
 *     cdef int frame, radius
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_6vision_6alearn_9marginals_3scoremarginals, NULL, __pyx_n_s_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__scoremarginals, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 265:     cdef double sigma
 266:     cdef int frame, radius
 267:     cdef annotations.Box start
 268:     (forw, backw, forwerr, backwerr, costs, sigma, dim, start, skip, radius, frame) = workorder
  /* "vision/alearn/marginals.pyx":268
 *     cdef int frame, radius
 *     cdef annotations.Box start
 *     (forw, backw, forwerr, backwerr, costs, sigma, dim, start, skip, radius, frame) = workorder             # <<<<<<<<<<<<<<
 * 
 *     cdef double score = 0, normalizer = 0, matchscore, error, localscore
 */
  if ((likely(PyTuple_CheckExact(__pyx_v_workorder))) || (PyList_CheckExact(__pyx_v_workorder))) {
    PyObject* sequence = __pyx_v_workorder;
    if (likely(PyTuple_CheckExact(sequence))) {
      if (unlikely(PyTuple_GET_SIZE(sequence) != 11)) {
        if (PyTuple_GET_SIZE(sequence) > 11) __Pyx_RaiseTooManyValuesError(11);
        else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence));
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 3); 
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 4); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 5); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 6); 
      __pyx_t_8 = PyTuple_GET_ITEM(sequence, 7); 
      __pyx_t_9 = PyTuple_GET_ITEM(sequence, 8); 
      __pyx_t_10 = PyTuple_GET_ITEM(sequence, 9); 
      __pyx_t_11 = PyTuple_GET_ITEM(sequence, 10); 
    } else {
      if (unlikely(PyList_GET_SIZE(sequence) != 11)) {
        if (PyList_GET_SIZE(sequence) > 11) __Pyx_RaiseTooManyValuesError(11);
        else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence));
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 3); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 4); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 5); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 6); 
      __pyx_t_8 = PyList_GET_ITEM(sequence, 7); 
      __pyx_t_9 = PyList_GET_ITEM(sequence, 8); 
      __pyx_t_10 = PyList_GET_ITEM(sequence, 9); 
      __pyx_t_11 = PyList_GET_ITEM(sequence, 10); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_t_10);
    __Pyx_INCREF(__pyx_t_11);
  } else {
    Py_ssize_t index = -1;
    __pyx_t_12 = PyObject_GetIter(__pyx_v_workorder); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_13 = Py_TYPE(__pyx_t_12)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_2 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 2; __pyx_t_3 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 3; __pyx_t_4 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    index = 4; __pyx_t_5 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_5)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_5);
    index = 5; __pyx_t_6 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_6)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_6);
    index = 6; __pyx_t_7 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_7)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_7);
    index = 7; __pyx_t_8 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_8)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_8);
    index = 8; __pyx_t_9 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_9)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_9);
    index = 9; __pyx_t_10 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_10)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_10);
    index = 10; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_11);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 11) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    goto __pyx_L6_unpacking_done;
    __pyx_L5_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear();
    if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L6_unpacking_done:;
  }
  __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_t_6); if (unlikely((__pyx_t_14 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_6vision_11annotations_Box))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_15 = __Pyx_PyInt_AsInt(__pyx_t_10); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_t_11); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_forw = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_backw = __pyx_t_2;
  __pyx_t_2 = 0;
  __pyx_v_forwerr = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_backwerr = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_costs = __pyx_t_5;
  __pyx_t_5 = 0;
  __pyx_v_sigma = __pyx_t_14;
  __pyx_v_dim = __pyx_t_7;
  __pyx_t_7 = 0;
  __pyx_v_start = ((struct __pyx_obj_6vision_11annotations_Box *)__pyx_t_8);
  __pyx_t_8 = 0;
  __pyx_v_skip = __pyx_t_9;
  __pyx_t_9 = 0;
  __pyx_v_radius = __pyx_t_15;
  __pyx_v_frame = __pyx_t_16;
 269: 
 270:     cdef double score = 0, normalizer = 0, matchscore, error, localscore
  /* "vision/alearn/marginals.pyx":270
 *     (forw, backw, forwerr, backwerr, costs, sigma, dim, start, skip, radius, frame) = workorder
 * 
 *     cdef double score = 0, normalizer = 0, matchscore, error, localscore             # <<<<<<<<<<<<<<
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwrt = forw[0]
 */
  __pyx_v_score = 0.0;
  __pyx_v_normalizer = 0.0;
 271: 
 272:     cdef numpy.ndarray[numpy.double_t, ndim=2] forwrt = forw[0]
  /* "vision/alearn/marginals.pyx":272
 *     cdef double score = 0, normalizer = 0, matchscore, error, localscore
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwrt = forw[0]             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwrt = backw[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] costrt = costs
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_forw, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_17 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_forwrt, (PyObject*)__pyx_t_17, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_forwrt = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_forwrt.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_forwrt = __pyx_bstruct_forwrt.strides[0]; __pyx_bstride_1_forwrt = __pyx_bstruct_forwrt.strides[1];
      __pyx_bshape_0_forwrt = __pyx_bstruct_forwrt.shape[0]; __pyx_bshape_1_forwrt = __pyx_bstruct_forwrt.shape[1];
    }
  }
  __pyx_t_17 = 0;
  __pyx_v_forwrt = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 273:     cdef numpy.ndarray[numpy.double_t, ndim=2] backwrt = backw[0]
  /* "vision/alearn/marginals.pyx":273
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwrt = forw[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwrt = backw[0]             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] costrt = costs
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwe = forwerr[0]
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_backw, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_18 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_backwrt, (PyObject*)__pyx_t_18, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_backwrt = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_backwrt.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_backwrt = __pyx_bstruct_backwrt.strides[0]; __pyx_bstride_1_backwrt = __pyx_bstruct_backwrt.strides[1];
      __pyx_bshape_0_backwrt = __pyx_bstruct_backwrt.shape[0]; __pyx_bshape_1_backwrt = __pyx_bstruct_backwrt.shape[1];
    }
  }
  __pyx_t_18 = 0;
  __pyx_v_backwrt = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 274:     cdef numpy.ndarray[numpy.double_t, ndim=2] costrt = costs
  /* "vision/alearn/marginals.pyx":274
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwrt = forw[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwrt = backw[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] costrt = costs             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwe = forwerr[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwe = backwerr[0]
 */
  if (!(likely(((__pyx_v_costs) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_costs, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_19 = ((PyArrayObject *)__pyx_v_costs);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_costrt, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_costrt = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_costrt.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_costrt = __pyx_bstruct_costrt.strides[0]; __pyx_bstride_1_costrt = __pyx_bstruct_costrt.strides[1];
      __pyx_bshape_0_costrt = __pyx_bstruct_costrt.shape[0]; __pyx_bshape_1_costrt = __pyx_bstruct_costrt.shape[1];
    }
  }
  __pyx_t_19 = 0;
  __Pyx_INCREF(__pyx_v_costs);
  __pyx_v_costrt = ((PyArrayObject *)__pyx_v_costs);
 275:     cdef numpy.ndarray[numpy.double_t, ndim=2] forwe = forwerr[0]
  /* "vision/alearn/marginals.pyx":275
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwrt = backw[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] costrt = costs
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwe = forwerr[0]             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwe = backwerr[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwloce = forwerr[1]
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_forwerr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_20 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_forwe, (PyObject*)__pyx_t_20, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_forwe = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_forwe.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_forwe = __pyx_bstruct_forwe.strides[0]; __pyx_bstride_1_forwe = __pyx_bstruct_forwe.strides[1];
      __pyx_bshape_0_forwe = __pyx_bstruct_forwe.shape[0]; __pyx_bshape_1_forwe = __pyx_bstruct_forwe.shape[1];
    }
  }
  __pyx_t_20 = 0;
  __pyx_v_forwe = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 276:     cdef numpy.ndarray[numpy.double_t, ndim=2] backwe = backwerr[0]
  /* "vision/alearn/marginals.pyx":276
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] costrt = costs
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwe = forwerr[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwe = backwerr[0]             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwloce = forwerr[1]
 * 
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_backwerr, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_21 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_backwe, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_backwe = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_backwe.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_backwe = __pyx_bstruct_backwe.strides[0]; __pyx_bstride_1_backwe = __pyx_bstruct_backwe.strides[1];
      __pyx_bshape_0_backwe = __pyx_bstruct_backwe.shape[0]; __pyx_bshape_1_backwe = __pyx_bstruct_backwe.shape[1];
    }
  }
  __pyx_t_21 = 0;
  __pyx_v_backwe = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 277:     cdef numpy.ndarray[numpy.double_t, ndim=2] forwloce = forwerr[1]
  /* "vision/alearn/marginals.pyx":277
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwe = forwerr[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] backwe = backwerr[0]
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwloce = forwerr[1]             # <<<<<<<<<<<<<<
 * 
 *     cdef int w = forw[1].shape[0]
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_forwerr, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_22 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_forwloce, (PyObject*)__pyx_t_22, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_forwloce = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_forwloce.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_forwloce = __pyx_bstruct_forwloce.strides[0]; __pyx_bstride_1_forwloce = __pyx_bstruct_forwloce.strides[1];
      __pyx_bshape_0_forwloce = __pyx_bstruct_forwloce.shape[0]; __pyx_bshape_1_forwloce = __pyx_bstruct_forwloce.shape[1];
    }
  }
  __pyx_t_22 = 0;
  __pyx_v_forwloce = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 278: 
 279:     cdef int w = forw[1].shape[0]
  /* "vision/alearn/marginals.pyx":279
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] forwloce = forwerr[1]
 * 
 *     cdef int w = forw[1].shape[0]             # <<<<<<<<<<<<<<
 *     cdef int h = forw[1].shape[1]
 * 
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_forw, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__shape); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_10, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_t_11); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_w = __pyx_t_16;
 280:     cdef int h = forw[1].shape[1]
  /* "vision/alearn/marginals.pyx":280
 * 
 *     cdef int w = forw[1].shape[0]
 *     cdef int h = forw[1].shape[1]             # <<<<<<<<<<<<<<
 * 
 *     cdef double wr = dim[0] / (<double>start.width)
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_forw, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__shape); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_10, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_16 = __Pyx_PyInt_AsInt(__pyx_t_11); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_h = __pyx_t_16;
 281: 
 282:     cdef double wr = dim[0] / (<double>start.width)
  /* "vision/alearn/marginals.pyx":282
 *     cdef int h = forw[1].shape[1]
 * 
 *     cdef double wr = dim[0] / (<double>start.width)             # <<<<<<<<<<<<<<
 *     cdef double hr = dim[1] / (<double>start.height)
 * 
 */
  __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_dim, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_11) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_start), __pyx_n_s__width); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_t_10); if (unlikely((__pyx_t_14 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyFloat_FromDouble(((double)__pyx_t_14)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_9 = __Pyx_PyNumber_Divide(__pyx_t_11, __pyx_t_10); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_t_9); if (unlikely((__pyx_t_14 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_wr = __pyx_t_14;
 283:     cdef double hr = dim[1] / (<double>start.height)
  /* "vision/alearn/marginals.pyx":283
 * 
 *     cdef double wr = dim[0] / (<double>start.width)
 *     cdef double hr = dim[1] / (<double>start.height)             # <<<<<<<<<<<<<<
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gprob = numpy.zeros((w, h))
 */
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_dim, 1, sizeof(long), PyInt_FromLong); if (!__pyx_t_9) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_start), __pyx_n_s__height); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_t_10); if (unlikely((__pyx_t_14 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = PyFloat_FromDouble(((double)__pyx_t_14)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = __Pyx_PyNumber_Divide(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_14 = __pyx_PyFloat_AsDouble(__pyx_t_11); if (unlikely((__pyx_t_14 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_hr = __pyx_t_14;
 284: 
 285:     cdef numpy.ndarray[numpy.double_t, ndim=2] gprob = numpy.zeros((w, h))
  /* "vision/alearn/marginals.pyx":285
 *     cdef double hr = dim[1] / (<double>start.height)
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gprob = numpy.zeros((w, h))             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] greduct = numpy.zeros((w, h))
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gerrors = numpy.zeros((w, h))
 */
  __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__zeros); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyInt_FromLong(__pyx_v_w); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_9 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_11 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
  __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_23 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_gprob, (PyObject*)__pyx_t_23, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_gprob = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_gprob.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_gprob = __pyx_bstruct_gprob.strides[0]; __pyx_bstride_1_gprob = __pyx_bstruct_gprob.strides[1];
      __pyx_bshape_0_gprob = __pyx_bstruct_gprob.shape[0]; __pyx_bshape_1_gprob = __pyx_bstruct_gprob.shape[1];
    }
  }
  __pyx_t_23 = 0;
  __pyx_v_gprob = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;
 286:     cdef numpy.ndarray[numpy.double_t, ndim=2] greduct = numpy.zeros((w, h))
  /* "vision/alearn/marginals.pyx":286
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gprob = numpy.zeros((w, h))
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] greduct = numpy.zeros((w, h))             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gerrors = numpy.zeros((w, h))
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gmargin = numpy.zeros((w, h))
 */
  __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__zeros); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyInt_FromLong(__pyx_v_w); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_10 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_11));
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  __pyx_t_8 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_10));
  PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_11));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_11));
  __pyx_t_11 = 0;
  __pyx_t_11 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_24 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_greduct, (PyObject*)__pyx_t_24, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_greduct = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_greduct.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_greduct = __pyx_bstruct_greduct.strides[0]; __pyx_bstride_1_greduct = __pyx_bstruct_greduct.strides[1];
      __pyx_bshape_0_greduct = __pyx_bstruct_greduct.shape[0]; __pyx_bshape_1_greduct = __pyx_bstruct_greduct.shape[1];
    }
  }
  __pyx_t_24 = 0;
  __pyx_v_greduct = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 287:     cdef numpy.ndarray[numpy.double_t, ndim=2] gerrors = numpy.zeros((w, h))
  /* "vision/alearn/marginals.pyx":287
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gprob = numpy.zeros((w, h))
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] greduct = numpy.zeros((w, h))
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gerrors = numpy.zeros((w, h))             # <<<<<<<<<<<<<<
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gmargin = numpy.zeros((w, h))
 * 
 */
  __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__zeros); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyInt_FromLong(__pyx_v_w); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_9 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_11 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
  __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_25 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_gerrors, (PyObject*)__pyx_t_25, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_gerrors = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_gerrors.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_gerrors = __pyx_bstruct_gerrors.strides[0]; __pyx_bstride_1_gerrors = __pyx_bstruct_gerrors.strides[1];
      __pyx_bshape_0_gerrors = __pyx_bstruct_gerrors.shape[0]; __pyx_bshape_1_gerrors = __pyx_bstruct_gerrors.shape[1];
    }
  }
  __pyx_t_25 = 0;
  __pyx_v_gerrors = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;
 288:     cdef numpy.ndarray[numpy.double_t, ndim=2] gmargin = numpy.zeros((w, h))
  /* "vision/alearn/marginals.pyx":288
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] greduct = numpy.zeros((w, h))
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gerrors = numpy.zeros((w, h))
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] gmargin = numpy.zeros((w, h))             # <<<<<<<<<<<<<<
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] matchscores
 */
  __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__zeros); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyInt_FromLong(__pyx_v_w); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_10 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_11));
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  __pyx_t_8 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_10));
  PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_11));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_11));
  __pyx_t_11 = 0;
  __pyx_t_11 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_26 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_gmargin, (PyObject*)__pyx_t_26, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_gmargin = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_gmargin.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_bstride_0_gmargin = __pyx_bstruct_gmargin.strides[0]; __pyx_bstride_1_gmargin = __pyx_bstruct_gmargin.strides[1];
      __pyx_bshape_0_gmargin = __pyx_bstruct_gmargin.shape[0]; __pyx_bshape_1_gmargin = __pyx_bstruct_gmargin.shape[1];
    }
  }
  __pyx_t_26 = 0;
  __pyx_v_gmargin = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 289: 
 290:     cdef numpy.ndarray[numpy.double_t, ndim=2] matchscores
 291:     matchscores = numpy.zeros((w, h))
  /* "vision/alearn/marginals.pyx":291
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] matchscores
 *     matchscores = numpy.zeros((w, h))             # <<<<<<<<<<<<<<
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] errors, errorsvert
 */
  __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__zeros); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyInt_FromLong(__pyx_v_w); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_9 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_11 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
  __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_27 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_matchscores);
    __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_matchscores, (PyObject*)__pyx_t_27, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_16 < 0)) {
      PyErr_Fetch(&__pyx_t_28, &__pyx_t_29, &__pyx_t_30);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_matchscores, (PyObject*)__pyx_v_matchscores, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_28); Py_XDECREF(__pyx_t_29); Py_XDECREF(__pyx_t_30);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_28, __pyx_t_29, __pyx_t_30);
      }
    }
    __pyx_bstride_0_matchscores = __pyx_bstruct_matchscores.strides[0]; __pyx_bstride_1_matchscores = __pyx_bstruct_matchscores.strides[1];
    __pyx_bshape_0_matchscores = __pyx_bstruct_matchscores.shape[0]; __pyx_bshape_1_matchscores = __pyx_bstruct_matchscores.shape[1];
    if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_27 = 0;
  __pyx_v_matchscores = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;
 292: 
 293:     cdef numpy.ndarray[numpy.double_t, ndim=2] errors, errorsvert
 294:     errors = numpy.zeros((w, h))
  /* "vision/alearn/marginals.pyx":294
 * 
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] errors, errorsvert
 *     errors = numpy.zeros((w, h))             # <<<<<<<<<<<<<<
 *     errorsvert = numpy.zeros((w, h))
 * 
 */
  __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__zeros); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyInt_FromLong(__pyx_v_w); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_10 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_11));
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  __pyx_t_8 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_10));
  PyTuple_SET_ITEM(__pyx_t_10, 0, ((PyObject *)__pyx_t_11));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_11));
  __pyx_t_11 = 0;
  __pyx_t_11 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_31 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_errors);
    __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_errors, (PyObject*)__pyx_t_31, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_16 < 0)) {
      PyErr_Fetch(&__pyx_t_30, &__pyx_t_29, &__pyx_t_28);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_errors, (PyObject*)__pyx_v_errors, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_30); Py_XDECREF(__pyx_t_29); Py_XDECREF(__pyx_t_28);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_30, __pyx_t_29, __pyx_t_28);
      }
    }
    __pyx_bstride_0_errors = __pyx_bstruct_errors.strides[0]; __pyx_bstride_1_errors = __pyx_bstruct_errors.strides[1];
    __pyx_bshape_0_errors = __pyx_bstruct_errors.shape[0]; __pyx_bshape_1_errors = __pyx_bstruct_errors.shape[1];
    if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_31 = 0;
  __pyx_v_errors = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;
 295:     errorsvert = numpy.zeros((w, h))
  /* "vision/alearn/marginals.pyx":295
 *     cdef numpy.ndarray[numpy.double_t, ndim=2] errors, errorsvert
 *     errors = numpy.zeros((w, h))
 *     errorsvert = numpy.zeros((w, h))             # <<<<<<<<<<<<<<
 * 
 *     cdef double maxmatchscore = Infinity
 */
  __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__numpy); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__zeros); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = PyInt_FromLong(__pyx_v_w); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_9 = PyInt_FromLong(__pyx_v_h); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_8));
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_11 = 0;
  __pyx_t_9 = 0;
  __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_9));
  PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)__pyx_t_8));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
  __pyx_t_8 = 0;
  __pyx_t_8 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_31 = ((PyArrayObject *)__pyx_t_8);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_errorsvert);
    __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_errorsvert, (PyObject*)__pyx_t_31, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_16 < 0)) {
      PyErr_Fetch(&__pyx_t_28, &__pyx_t_29, &__pyx_t_30);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_errorsvert, (PyObject*)__pyx_v_errorsvert, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_28); Py_XDECREF(__pyx_t_29); Py_XDECREF(__pyx_t_30);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_28, __pyx_t_29, __pyx_t_30);
      }
    }
    __pyx_bstride_0_errorsvert = __pyx_bstruct_errorsvert.strides[0]; __pyx_bstride_1_errorsvert = __pyx_bstruct_errorsvert.strides[1];
    __pyx_bshape_0_errorsvert = __pyx_bstruct_errorsvert.shape[0]; __pyx_bshape_1_errorsvert = __pyx_bstruct_errorsvert.shape[1];
    if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_31 = 0;
  __pyx_v_errorsvert = ((PyArrayObject *)__pyx_t_8);
  __pyx_t_8 = 0;
 296: 
 297:     cdef double maxmatchscore = Infinity
  /* "vision/alearn/marginals.pyx":297
 *     errorsvert = numpy.zeros((w, h))
 * 
 *     cdef double maxmatchscore = Infinity             # <<<<<<<<<<<<<<
 * 
 *     # for numerical reasons, we want to subtract the most best score
 */
  __pyx_v_maxmatchscore = __pyx_v_6vision_6alearn_9marginals_Infinity;
 298: 
 299:     # for numerical reasons, we want to subtract the most best score
 300:     for i in range(w):
  /* "vision/alearn/marginals.pyx":300
 * 
 *     # for numerical reasons, we want to subtract the most best score
 *     for i in range(w):             # <<<<<<<<<<<<<<
 *         for j in range(h):
 *             matchscore = forwrt[i, j] + backwrt[i, j]
 */
  __pyx_t_16 = __pyx_v_w;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_16; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;
 301:         for j in range(h):
    /* "vision/alearn/marginals.pyx":301
 *     # for numerical reasons, we want to subtract the most best score
 *     for i in range(w):
 *         for j in range(h):             # <<<<<<<<<<<<<<
 *             matchscore = forwrt[i, j] + backwrt[i, j]
 *             matchscore = matchscore - costrt[<int>(i * wr), <int>(j * hr)]
 */
    __pyx_t_32 = __pyx_v_h;
    for (__pyx_t_33 = 0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) {
      __pyx_v_j = __pyx_t_33;
 302:             matchscore = forwrt[i, j] + backwrt[i, j]
      /* "vision/alearn/marginals.pyx":302
 *     for i in range(w):
 *         for j in range(h):
 *             matchscore = forwrt[i, j] + backwrt[i, j]             # <<<<<<<<<<<<<<
 *             matchscore = matchscore - costrt[<int>(i * wr), <int>(j * hr)]
 *             matchscores[i, j] = matchscore
 */
      __pyx_t_34 = __pyx_v_i;
      __pyx_t_35 = __pyx_v_j;
      if (__pyx_t_34 < 0) __pyx_t_34 += __pyx_bshape_0_forwrt;
      if (__pyx_t_35 < 0) __pyx_t_35 += __pyx_bshape_1_forwrt;
      __pyx_t_36 = __pyx_v_i;
      __pyx_t_37 = __pyx_v_j;
      if (__pyx_t_36 < 0) __pyx_t_36 += __pyx_bshape_0_backwrt;
      if (__pyx_t_37 < 0) __pyx_t_37 += __pyx_bshape_1_backwrt;
      __pyx_v_matchscore = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_forwrt.buf, __pyx_t_34, __pyx_bstride_0_forwrt, __pyx_t_35, __pyx_bstride_1_forwrt)) + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_backwrt.buf, __pyx_t_36, __pyx_bstride_0_backwrt, __pyx_t_37, __pyx_bstride_1_backwrt)));
 303:             matchscore = matchscore - costrt[<int>(i * wr), <int>(j * hr)]
      /* "vision/alearn/marginals.pyx":303
 *         for j in range(h):
 *             matchscore = forwrt[i, j] + backwrt[i, j]
 *             matchscore = matchscore - costrt[<int>(i * wr), <int>(j * hr)]             # <<<<<<<<<<<<<<
 *             matchscores[i, j] = matchscore
 *             if matchscore < maxmatchscore:
 */
      __pyx_t_38 = ((int)(__pyx_v_i * __pyx_v_wr));
      __pyx_t_39 = ((int)(__pyx_v_j * __pyx_v_hr));
      if (__pyx_t_38 < 0) __pyx_t_38 += __pyx_bshape_0_costrt;
      if (__pyx_t_39 < 0) __pyx_t_39 += __pyx_bshape_1_costrt;
      __pyx_v_matchscore = (__pyx_v_matchscore - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_costrt.buf, __pyx_t_38, __pyx_bstride_0_costrt, __pyx_t_39, __pyx_bstride_1_costrt)));
 304:             matchscores[i, j] = matchscore
      /* "vision/alearn/marginals.pyx":304
 *             matchscore = forwrt[i, j] + backwrt[i, j]
 *             matchscore = matchscore - costrt[<int>(i * wr), <int>(j * hr)]
 *             matchscores[i, j] = matchscore             # <<<<<<<<<<<<<<
 *             if matchscore < maxmatchscore:
 *                 maxmatchscore = matchscore
 */
      __pyx_t_40 = __pyx_v_i;
      __pyx_t_41 = __pyx_v_j;
      if (__pyx_t_40 < 0) __pyx_t_40 += __pyx_bshape_0_matchscores;
      if (__pyx_t_41 < 0) __pyx_t_41 += __pyx_bshape_1_matchscores;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_matchscores.buf, __pyx_t_40, __pyx_bstride_0_matchscores, __pyx_t_41, __pyx_bstride_1_matchscores) = __pyx_v_matchscore;
 305:             if matchscore < maxmatchscore:
      /* "vision/alearn/marginals.pyx":305
 *             matchscore = matchscore - costrt[<int>(i * wr), <int>(j * hr)]
 *             matchscores[i, j] = matchscore
 *             if matchscore < maxmatchscore:             # <<<<<<<<<<<<<<
 *                 maxmatchscore = matchscore
 * 
 */
      __pyx_t_42 = (__pyx_v_matchscore < __pyx_v_maxmatchscore);
      if (__pyx_t_42) {
 306:                 maxmatchscore = matchscore
        /* "vision/alearn/marginals.pyx":306
 *             matchscores[i, j] = matchscore
 *             if matchscore < maxmatchscore:
 *                 maxmatchscore = matchscore             # <<<<<<<<<<<<<<
 * 
 *     # compute error image
 */
        __pyx_v_maxmatchscore = __pyx_v_matchscore;
        goto __pyx_L11;
      }
      __pyx_L11:;
    }
  }
 307: 
 308:     # compute error image
 309:     for i in range(w):
  /* "vision/alearn/marginals.pyx":309
 * 
 *     # compute error image
 *     for i in range(w):             # <<<<<<<<<<<<<<
 *         for j in range(h):
 *             errors[i, j] = forwe[i, j] + backwe[i, j] - forwloce[i, j]
 */
  __pyx_t_16 = __pyx_v_w;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_16; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;
 310:         for j in range(h):
    /* "vision/alearn/marginals.pyx":310
 *     # compute error image
 *     for i in range(w):
 *         for j in range(h):             # <<<<<<<<<<<<<<
 *             errors[i, j] = forwe[i, j] + backwe[i, j] - forwloce[i, j]
 * 
 */
    __pyx_t_32 = __pyx_v_h;
    for (__pyx_t_33 = 0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) {
      __pyx_v_j = __pyx_t_33;
 311:             errors[i, j] = forwe[i, j] + backwe[i, j] - forwloce[i, j]
      /* "vision/alearn/marginals.pyx":311
 *     for i in range(w):
 *         for j in range(h):
 *             errors[i, j] = forwe[i, j] + backwe[i, j] - forwloce[i, j]             # <<<<<<<<<<<<<<
 * 
 *     # vertical pass on min
 */
      __pyx_t_43 = __pyx_v_i;
      __pyx_t_44 = __pyx_v_j;
      if (__pyx_t_43 < 0) __pyx_t_43 += __pyx_bshape_0_forwe;
      if (__pyx_t_44 < 0) __pyx_t_44 += __pyx_bshape_1_forwe;
      __pyx_t_45 = __pyx_v_i;
      __pyx_t_46 = __pyx_v_j;
      if (__pyx_t_45 < 0) __pyx_t_45 += __pyx_bshape_0_backwe;
      if (__pyx_t_46 < 0) __pyx_t_46 += __pyx_bshape_1_backwe;
      __pyx_t_47 = __pyx_v_i;
      __pyx_t_48 = __pyx_v_j;
      if (__pyx_t_47 < 0) __pyx_t_47 += __pyx_bshape_0_forwloce;
      if (__pyx_t_48 < 0) __pyx_t_48 += __pyx_bshape_1_forwloce;
      __pyx_t_49 = __pyx_v_i;
      __pyx_t_50 = __pyx_v_j;
      if (__pyx_t_49 < 0) __pyx_t_49 += __pyx_bshape_0_errors;
      if (__pyx_t_50 < 0) __pyx_t_50 += __pyx_bshape_1_errors;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_49, __pyx_bstride_0_errors, __pyx_t_50, __pyx_bstride_1_errors) = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_forwe.buf, __pyx_t_43, __pyx_bstride_0_forwe, __pyx_t_44, __pyx_bstride_1_forwe)) + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_backwe.buf, __pyx_t_45, __pyx_bstride_0_backwe, __pyx_t_46, __pyx_bstride_1_backwe))) - (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_forwloce.buf, __pyx_t_47, __pyx_bstride_0_forwloce, __pyx_t_48, __pyx_bstride_1_forwloce)));
    }
  }
 312: 
 313:     # vertical pass on min
 314:     for i in range(w):
  /* "vision/alearn/marginals.pyx":314
 * 
 *     # vertical pass on min
 *     for i in range(w):             # <<<<<<<<<<<<<<
 *         for j in range(h):
 *             errorsvert[i, j] = errors[i, j]
 */
  __pyx_t_16 = __pyx_v_w;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_16; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;
 315:         for j in range(h):
    /* "vision/alearn/marginals.pyx":315
 *     # vertical pass on min
 *     for i in range(w):
 *         for j in range(h):             # <<<<<<<<<<<<<<
 *             errorsvert[i, j] = errors[i, j]
 *             for y in range(max(0, j - radius), min(h - 1, j + radius)):
 */
    __pyx_t_32 = __pyx_v_h;
    for (__pyx_t_33 = 0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) {
      __pyx_v_j = __pyx_t_33;
 316:             errorsvert[i, j] = errors[i, j]
      /* "vision/alearn/marginals.pyx":316
 *     for i in range(w):
 *         for j in range(h):
 *             errorsvert[i, j] = errors[i, j]             # <<<<<<<<<<<<<<
 *             for y in range(max(0, j - radius), min(h - 1, j + radius)):
 *                 errorsvert[i, j] = min(errorsvert[i, j], errors[i, y])
 */
      __pyx_t_51 = __pyx_v_i;
      __pyx_t_52 = __pyx_v_j;
      if (__pyx_t_51 < 0) __pyx_t_51 += __pyx_bshape_0_errors;
      if (__pyx_t_52 < 0) __pyx_t_52 += __pyx_bshape_1_errors;
      __pyx_t_53 = __pyx_v_i;
      __pyx_t_54 = __pyx_v_j;
      if (__pyx_t_53 < 0) __pyx_t_53 += __pyx_bshape_0_errorsvert;
      if (__pyx_t_54 < 0) __pyx_t_54 += __pyx_bshape_1_errorsvert;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errorsvert.buf, __pyx_t_53, __pyx_bstride_0_errorsvert, __pyx_t_54, __pyx_bstride_1_errorsvert) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_51, __pyx_bstride_0_errors, __pyx_t_52, __pyx_bstride_1_errors));
 317:             for y in range(max(0, j - radius), min(h - 1, j + radius)):
      /* "vision/alearn/marginals.pyx":317
 *         for j in range(h):
 *             errorsvert[i, j] = errors[i, j]
 *             for y in range(max(0, j - radius), min(h - 1, j + radius)):             # <<<<<<<<<<<<<<
 *                 errorsvert[i, j] = min(errorsvert[i, j], errors[i, y])
 * 
 */
      __pyx_t_55 = (__pyx_v_j + __pyx_v_radius);
      __pyx_t_56 = (__pyx_v_h - 1);
      if ((__pyx_t_55 < __pyx_t_56)) {
        __pyx_t_57 = __pyx_t_55;
      } else {
        __pyx_t_57 = __pyx_t_56;
      }
      __pyx_t_56 = __pyx_t_57;
      __pyx_t_55 = (__pyx_v_j - __pyx_v_radius);
      __pyx_t_57 = 0;
      if ((__pyx_t_55 > __pyx_t_57)) {
        __pyx_t_58 = __pyx_t_55;
      } else {
        __pyx_t_58 = __pyx_t_57;
      }
      for (__pyx_t_57 = __pyx_t_58; __pyx_t_57 < __pyx_t_56; __pyx_t_57+=1) {
        __pyx_v_y = __pyx_t_57;
 318:                 errorsvert[i, j] = min(errorsvert[i, j], errors[i, y])
        /* "vision/alearn/marginals.pyx":318
 *             errorsvert[i, j] = errors[i, j]
 *             for y in range(max(0, j - radius), min(h - 1, j + radius)):
 *                 errorsvert[i, j] = min(errorsvert[i, j], errors[i, y])             # <<<<<<<<<<<<<<
 * 
 *     # horizontal pass on min
 */
        __pyx_t_55 = __pyx_v_i;
        __pyx_t_59 = __pyx_v_y;
        if (__pyx_t_55 < 0) __pyx_t_55 += __pyx_bshape_0_errors;
        if (__pyx_t_59 < 0) __pyx_t_59 += __pyx_bshape_1_errors;
        __pyx_t_60 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_55, __pyx_bstride_0_errors, __pyx_t_59, __pyx_bstride_1_errors));
        __pyx_t_61 = __pyx_v_i;
        __pyx_t_62 = __pyx_v_j;
        if (__pyx_t_61 < 0) __pyx_t_61 += __pyx_bshape_0_errorsvert;
        if (__pyx_t_62 < 0) __pyx_t_62 += __pyx_bshape_1_errorsvert;
        __pyx_t_63 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errorsvert.buf, __pyx_t_61, __pyx_bstride_0_errorsvert, __pyx_t_62, __pyx_bstride_1_errorsvert));
        if ((__pyx_t_60 < __pyx_t_63)) {
          __pyx_t_64 = __pyx_t_60;
        } else {
          __pyx_t_64 = __pyx_t_63;
        }
        __pyx_t_65 = __pyx_v_i;
        __pyx_t_66 = __pyx_v_j;
        if (__pyx_t_65 < 0) __pyx_t_65 += __pyx_bshape_0_errorsvert;
        if (__pyx_t_66 < 0) __pyx_t_66 += __pyx_bshape_1_errorsvert;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errorsvert.buf, __pyx_t_65, __pyx_bstride_0_errorsvert, __pyx_t_66, __pyx_bstride_1_errorsvert) = __pyx_t_64;
      }
    }
  }
 319: 
 320:     # horizontal pass on min
 321:     for i in range(w):
  /* "vision/alearn/marginals.pyx":321
 * 
 *     # horizontal pass on min
 *     for i in range(w):             # <<<<<<<<<<<<<<
 *         for j in range(h):
 *             errors[i, j] = errorsvert[i, j]
 */
  __pyx_t_16 = __pyx_v_w;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_16; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;
 322:         for j in range(h):
    /* "vision/alearn/marginals.pyx":322
 *     # horizontal pass on min
 *     for i in range(w):
 *         for j in range(h):             # <<<<<<<<<<<<<<
 *             errors[i, j] = errorsvert[i, j]
 *             for x in range(max(0, i - radius), min(w - 1, i + radius)):
 */
    __pyx_t_32 = __pyx_v_h;
    for (__pyx_t_33 = 0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) {
      __pyx_v_j = __pyx_t_33;
 323:             errors[i, j] = errorsvert[i, j]
      /* "vision/alearn/marginals.pyx":323
 *     for i in range(w):
 *         for j in range(h):
 *             errors[i, j] = errorsvert[i, j]             # <<<<<<<<<<<<<<
 *             for x in range(max(0, i - radius), min(w - 1, i + radius)):
 *                 errors[i, j] = min(errors[i, j], errorsvert[x, j])
 */
      __pyx_t_67 = __pyx_v_i;
      __pyx_t_68 = __pyx_v_j;
      if (__pyx_t_67 < 0) __pyx_t_67 += __pyx_bshape_0_errorsvert;
      if (__pyx_t_68 < 0) __pyx_t_68 += __pyx_bshape_1_errorsvert;
      __pyx_t_69 = __pyx_v_i;
      __pyx_t_70 = __pyx_v_j;
      if (__pyx_t_69 < 0) __pyx_t_69 += __pyx_bshape_0_errors;
      if (__pyx_t_70 < 0) __pyx_t_70 += __pyx_bshape_1_errors;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_69, __pyx_bstride_0_errors, __pyx_t_70, __pyx_bstride_1_errors) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errorsvert.buf, __pyx_t_67, __pyx_bstride_0_errorsvert, __pyx_t_68, __pyx_bstride_1_errorsvert));
 324:             for x in range(max(0, i - radius), min(w - 1, i + radius)):
      /* "vision/alearn/marginals.pyx":324
 *         for j in range(h):
 *             errors[i, j] = errorsvert[i, j]
 *             for x in range(max(0, i - radius), min(w - 1, i + radius)):             # <<<<<<<<<<<<<<
 *                 errors[i, j] = min(errors[i, j], errorsvert[x, j])
 * 
 */
      __pyx_t_71 = (__pyx_v_i + __pyx_v_radius);
      __pyx_t_56 = (__pyx_v_w - 1);
      if ((__pyx_t_71 < __pyx_t_56)) {
        __pyx_t_58 = __pyx_t_71;
      } else {
        __pyx_t_58 = __pyx_t_56;
      }
      __pyx_t_56 = __pyx_t_58;
      __pyx_t_71 = (__pyx_v_i - __pyx_v_radius);
      __pyx_t_58 = 0;
      if ((__pyx_t_71 > __pyx_t_58)) {
        __pyx_t_57 = __pyx_t_71;
      } else {
        __pyx_t_57 = __pyx_t_58;
      }
      for (__pyx_t_58 = __pyx_t_57; __pyx_t_58 < __pyx_t_56; __pyx_t_58+=1) {
        __pyx_v_x = __pyx_t_58;
 325:                 errors[i, j] = min(errors[i, j], errorsvert[x, j])
        /* "vision/alearn/marginals.pyx":325
 *             errors[i, j] = errorsvert[i, j]
 *             for x in range(max(0, i - radius), min(w - 1, i + radius)):
 *                 errors[i, j] = min(errors[i, j], errorsvert[x, j])             # <<<<<<<<<<<<<<
 * 
 *     for i in range(w):
 */
        __pyx_t_72 = __pyx_v_x;
        __pyx_t_71 = __pyx_v_j;
        if (__pyx_t_72 < 0) __pyx_t_72 += __pyx_bshape_0_errorsvert;
        if (__pyx_t_71 < 0) __pyx_t_71 += __pyx_bshape_1_errorsvert;
        __pyx_t_64 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errorsvert.buf, __pyx_t_72, __pyx_bstride_0_errorsvert, __pyx_t_71, __pyx_bstride_1_errorsvert));
        __pyx_t_73 = __pyx_v_i;
        __pyx_t_74 = __pyx_v_j;
        if (__pyx_t_73 < 0) __pyx_t_73 += __pyx_bshape_0_errors;
        if (__pyx_t_74 < 0) __pyx_t_74 += __pyx_bshape_1_errors;
        __pyx_t_60 = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_73, __pyx_bstride_0_errors, __pyx_t_74, __pyx_bstride_1_errors));
        if ((__pyx_t_64 < __pyx_t_60)) {
          __pyx_t_63 = __pyx_t_64;
        } else {
          __pyx_t_63 = __pyx_t_60;
        }
        __pyx_t_75 = __pyx_v_i;
        __pyx_t_76 = __pyx_v_j;
        if (__pyx_t_75 < 0) __pyx_t_75 += __pyx_bshape_0_errors;
        if (__pyx_t_76 < 0) __pyx_t_76 += __pyx_bshape_1_errors;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_75, __pyx_bstride_0_errors, __pyx_t_76, __pyx_bstride_1_errors) = __pyx_t_63;
      }
    }
  }
 326: 
 327:     for i in range(w):
  /* "vision/alearn/marginals.pyx":327
 *                 errors[i, j] = min(errors[i, j], errorsvert[x, j])
 * 
 *     for i in range(w):             # <<<<<<<<<<<<<<
 *         for j in range(h):
 *             matchscore = matchscores[i, j] - maxmatchscore
 */
  __pyx_t_16 = __pyx_v_w;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_16; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;
 328:         for j in range(h):
    /* "vision/alearn/marginals.pyx":328
 * 
 *     for i in range(w):
 *         for j in range(h):             # <<<<<<<<<<<<<<
 *             matchscore = matchscores[i, j] - maxmatchscore
 * 
 */
    __pyx_t_32 = __pyx_v_h;
    for (__pyx_t_33 = 0; __pyx_t_33 < __pyx_t_32; __pyx_t_33+=1) {
      __pyx_v_j = __pyx_t_33;
 329:             matchscore = matchscores[i, j] - maxmatchscore
      /* "vision/alearn/marginals.pyx":329
 *     for i in range(w):
 *         for j in range(h):
 *             matchscore = matchscores[i, j] - maxmatchscore             # <<<<<<<<<<<<<<
 * 
 *             gmargin[i, j] = matchscore
 */
      __pyx_t_77 = __pyx_v_i;
      __pyx_t_78 = __pyx_v_j;
      if (__pyx_t_77 < 0) __pyx_t_77 += __pyx_bshape_0_matchscores;
      if (__pyx_t_78 < 0) __pyx_t_78 += __pyx_bshape_1_matchscores;
      __pyx_v_matchscore = ((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_matchscores.buf, __pyx_t_77, __pyx_bstride_0_matchscores, __pyx_t_78, __pyx_bstride_1_matchscores)) - __pyx_v_maxmatchscore);
 330: 
 331:             gmargin[i, j] = matchscore
      /* "vision/alearn/marginals.pyx":331
 *             matchscore = matchscores[i, j] - maxmatchscore
 * 
 *             gmargin[i, j] = matchscore             # <<<<<<<<<<<<<<
 * 
 *             matchscore = exp(-matchscore / sigma)
 */
      __pyx_t_79 = __pyx_v_i;
      __pyx_t_80 = __pyx_v_j;
      if (__pyx_t_79 < 0) __pyx_t_79 += __pyx_bshape_0_gmargin;
      if (__pyx_t_80 < 0) __pyx_t_80 += __pyx_bshape_1_gmargin;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_gmargin.buf, __pyx_t_79, __pyx_bstride_0_gmargin, __pyx_t_80, __pyx_bstride_1_gmargin) = __pyx_v_matchscore;
 332: 
 333:             matchscore = exp(-matchscore / sigma)
      /* "vision/alearn/marginals.pyx":333
 *             gmargin[i, j] = matchscore
 * 
 *             matchscore = exp(-matchscore / sigma)             # <<<<<<<<<<<<<<
 * 
 *             localscore = matchscore * errors[i, j]
 */
      __pyx_v_matchscore = exp(((-__pyx_v_matchscore) / __pyx_v_sigma));
 334: 
 335:             localscore = matchscore * errors[i, j]
      /* "vision/alearn/marginals.pyx":335
 *             matchscore = exp(-matchscore / sigma)
 * 
 *             localscore = matchscore * errors[i, j]             # <<<<<<<<<<<<<<
 * 
 *             gprob[i, j] = matchscore
 */
      __pyx_t_81 = __pyx_v_i;
      __pyx_t_82 = __pyx_v_j;
      if (__pyx_t_81 < 0) __pyx_t_81 += __pyx_bshape_0_errors;
      if (__pyx_t_82 < 0) __pyx_t_82 += __pyx_bshape_1_errors;
      __pyx_v_localscore = (__pyx_v_matchscore * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_81, __pyx_bstride_0_errors, __pyx_t_82, __pyx_bstride_1_errors)));
 336: 
 337:             gprob[i, j] = matchscore
      /* "vision/alearn/marginals.pyx":337
 *             localscore = matchscore * errors[i, j]
 * 
 *             gprob[i, j] = matchscore             # <<<<<<<<<<<<<<
 *             greduct[i, j] = localscore
 *             gerrors[i, j] = errors[i, j]
 */
      __pyx_t_83 = __pyx_v_i;
      __pyx_t_84 = __pyx_v_j;
      if (__pyx_t_83 < 0) __pyx_t_83 += __pyx_bshape_0_gprob;
      if (__pyx_t_84 < 0) __pyx_t_84 += __pyx_bshape_1_gprob;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_gprob.buf, __pyx_t_83, __pyx_bstride_0_gprob, __pyx_t_84, __pyx_bstride_1_gprob) = __pyx_v_matchscore;
 338:             greduct[i, j] = localscore
      /* "vision/alearn/marginals.pyx":338
 * 
 *             gprob[i, j] = matchscore
 *             greduct[i, j] = localscore             # <<<<<<<<<<<<<<
 *             gerrors[i, j] = errors[i, j]
 * 
 */
      __pyx_t_85 = __pyx_v_i;
      __pyx_t_86 = __pyx_v_j;
      if (__pyx_t_85 < 0) __pyx_t_85 += __pyx_bshape_0_greduct;
      if (__pyx_t_86 < 0) __pyx_t_86 += __pyx_bshape_1_greduct;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_greduct.buf, __pyx_t_85, __pyx_bstride_0_greduct, __pyx_t_86, __pyx_bstride_1_greduct) = __pyx_v_localscore;
 339:             gerrors[i, j] = errors[i, j]
      /* "vision/alearn/marginals.pyx":339
 *             gprob[i, j] = matchscore
 *             greduct[i, j] = localscore
 *             gerrors[i, j] = errors[i, j]             # <<<<<<<<<<<<<<
 * 
 *             score += localscore
 */
      __pyx_t_87 = __pyx_v_i;
      __pyx_t_88 = __pyx_v_j;
      if (__pyx_t_87 < 0) __pyx_t_87 += __pyx_bshape_0_errors;
      if (__pyx_t_88 < 0) __pyx_t_88 += __pyx_bshape_1_errors;
      __pyx_t_89 = __pyx_v_i;
      __pyx_t_90 = __pyx_v_j;
      if (__pyx_t_89 < 0) __pyx_t_89 += __pyx_bshape_0_gerrors;
      if (__pyx_t_90 < 0) __pyx_t_90 += __pyx_bshape_1_gerrors;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_gerrors.buf, __pyx_t_89, __pyx_bstride_0_gerrors, __pyx_t_90, __pyx_bstride_1_gerrors) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_bstruct_errors.buf, __pyx_t_87, __pyx_bstride_0_errors, __pyx_t_88, __pyx_bstride_1_errors));
 340: 
 341:             score += localscore
      /* "vision/alearn/marginals.pyx":341
 *             gerrors[i, j] = errors[i, j]
 * 
 *             score += localscore             # <<<<<<<<<<<<<<
 *             normalizer += matchscore
 * 
 */
      __pyx_v_score = (__pyx_v_score + __pyx_v_localscore);
 342:             normalizer += matchscore
      /* "vision/alearn/marginals.pyx":342
 * 
 *             score += localscore
 *             normalizer += matchscore             # <<<<<<<<<<<<<<
 * 
 *     if debug:
 */
      __pyx_v_normalizer = (__pyx_v_normalizer + __pyx_v_matchscore);
    }
  }
 343: 
 344:     if debug:
  /* "vision/alearn/marginals.pyx":344
 *             normalizer += matchscore
 * 
 *     if debug:             # <<<<<<<<<<<<<<
 *         gmargin = -gmargin
 *         pylab.set_cmap("gray")
 */
  if (__pyx_v_6vision_6alearn_9marginals_debug) {
 345:         gmargin = -gmargin
    /* "vision/alearn/marginals.pyx":345
 * 
 *     if debug:
 *         gmargin = -gmargin             # <<<<<<<<<<<<<<
 *         pylab.set_cmap("gray")
 *         pylab.title("min = {0}, max = {1}".format(gmargin.min(), gmargin.max()))
 */
    __pyx_t_8 = PyNumber_Negative(((PyObject *)__pyx_v_gmargin)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_26 = ((PyArrayObject *)__pyx_t_8);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gmargin);
      __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_gmargin, (PyObject*)__pyx_t_26, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_16 < 0)) {
        PyErr_Fetch(&__pyx_t_30, &__pyx_t_29, &__pyx_t_28);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_gmargin, (PyObject*)__pyx_v_gmargin, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_30); Py_XDECREF(__pyx_t_29); Py_XDECREF(__pyx_t_28);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_30, __pyx_t_29, __pyx_t_28);
        }
      }
      __pyx_bstride_0_gmargin = __pyx_bstruct_gmargin.strides[0]; __pyx_bstride_1_gmargin = __pyx_bstruct_gmargin.strides[1];
      __pyx_bshape_0_gmargin = __pyx_bstruct_gmargin.shape[0]; __pyx_bshape_1_gmargin = __pyx_bstruct_gmargin.shape[1];
      if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_26 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_gmargin));
    __pyx_v_gmargin = ((PyArrayObject *)__pyx_t_8);
    __pyx_t_8 = 0;
 346:         pylab.set_cmap("gray")
    /* "vision/alearn/marginals.pyx":346
 *     if debug:
 *         gmargin = -gmargin
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         pylab.title("min = {0}, max = {1}".format(gmargin.min(), gmargin.max()))
 *         pylab.imshow(gmargin.transpose())
 */
    __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__set_cmap); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_k_tuple_35), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "vision/alearn/marginals.pyx":346
 *     if debug:
 *         gmargin = -gmargin
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         pylab.title("min = {0}, max = {1}".format(gmargin.min(), gmargin.max()))
 *         pylab.imshow(gmargin.transpose())
 */
  __pyx_k_tuple_35 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_35));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gray));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));
 347:         pylab.title("min = {0}, max = {1}".format(gmargin.min(), gmargin.max()))
    /* "vision/alearn/marginals.pyx":347
 *         gmargin = -gmargin
 *         pylab.set_cmap("gray")
 *         pylab.title("min = {0}, max = {1}".format(gmargin.min(), gmargin.max()))             # <<<<<<<<<<<<<<
 *         pylab.imshow(gmargin.transpose())
 *         pylab.savefig("tmp/margin{0}.png".format(frame))
 */
    __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__title); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_36), __pyx_n_s__format); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_gmargin), __pyx_n_s__min); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_11 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_gmargin), __pyx_n_s__max); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_7 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_11 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 348:         pylab.imshow(gmargin.transpose())
    /* "vision/alearn/marginals.pyx":348
 *         pylab.set_cmap("gray")
 *         pylab.title("min = {0}, max = {1}".format(gmargin.min(), gmargin.max()))
 *         pylab.imshow(gmargin.transpose())             # <<<<<<<<<<<<<<
 *         pylab.savefig("tmp/margin{0}.png".format(frame))
 *         pylab.clf()
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__imshow); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_gmargin), __pyx_n_s__transpose); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 349:         pylab.savefig("tmp/margin{0}.png".format(frame))
    /* "vision/alearn/marginals.pyx":349
 *         pylab.title("min = {0}, max = {1}".format(gmargin.min(), gmargin.max()))
 *         pylab.imshow(gmargin.transpose())
 *         pylab.savefig("tmp/margin{0}.png".format(frame))             # <<<<<<<<<<<<<<
 *         pylab.clf()
 * 
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__savefig); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_37), __pyx_n_s__format); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = PyInt_FromLong(__pyx_v_frame); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
 350:         pylab.clf()
    /* "vision/alearn/marginals.pyx":350
 *         pylab.imshow(gmargin.transpose())
 *         pylab.savefig("tmp/margin{0}.png".format(frame))
 *         pylab.clf()             # <<<<<<<<<<<<<<
 * 
 *         pylab.set_cmap("gray")
 */
    __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_8 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__clf); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
 351: 
 352:         pylab.set_cmap("gray")
    /* "vision/alearn/marginals.pyx":352
 *         pylab.clf()
 * 
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         gprob = gprob / normalizer
 *         pylab.title("min = {0}, max = {1}".format(gprob.min(), gprob.max()))
 */
    __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_8 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__set_cmap); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_38), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "vision/alearn/marginals.pyx":352
 *         pylab.clf()
 * 
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         gprob = gprob / normalizer
 *         pylab.title("min = {0}, max = {1}".format(gprob.min(), gprob.max()))
 */
  __pyx_k_tuple_38 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_38));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gray));
  PyTuple_SET_ITEM(__pyx_k_tuple_38, 0, ((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_38));
 353:         gprob = gprob / normalizer
    /* "vision/alearn/marginals.pyx":353
 * 
 *         pylab.set_cmap("gray")
 *         gprob = gprob / normalizer             # <<<<<<<<<<<<<<
 *         pylab.title("min = {0}, max = {1}".format(gprob.min(), gprob.max()))
 *         pylab.imshow(gprob.transpose())
 */
    __pyx_t_10 = PyFloat_FromDouble(__pyx_v_normalizer); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_8 = __Pyx_PyNumber_Divide(((PyObject *)__pyx_v_gprob), __pyx_t_10); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_23 = ((PyArrayObject *)__pyx_t_8);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gprob);
      __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_bstruct_gprob, (PyObject*)__pyx_t_23, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_16 < 0)) {
        PyErr_Fetch(&__pyx_t_28, &__pyx_t_29, &__pyx_t_30);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_gprob, (PyObject*)__pyx_v_gprob, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_28); Py_XDECREF(__pyx_t_29); Py_XDECREF(__pyx_t_30);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_28, __pyx_t_29, __pyx_t_30);
        }
      }
      __pyx_bstride_0_gprob = __pyx_bstruct_gprob.strides[0]; __pyx_bstride_1_gprob = __pyx_bstruct_gprob.strides[1];
      __pyx_bshape_0_gprob = __pyx_bstruct_gprob.shape[0]; __pyx_bshape_1_gprob = __pyx_bstruct_gprob.shape[1];
      if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_23 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_v_gprob));
    __pyx_v_gprob = ((PyArrayObject *)__pyx_t_8);
    __pyx_t_8 = 0;
 354:         pylab.title("min = {0}, max = {1}".format(gprob.min(), gprob.max()))
    /* "vision/alearn/marginals.pyx":354
 *         pylab.set_cmap("gray")
 *         gprob = gprob / normalizer
 *         pylab.title("min = {0}, max = {1}".format(gprob.min(), gprob.max()))             # <<<<<<<<<<<<<<
 *         pylab.imshow(gprob.transpose())
 *         pylab.savefig("tmp/prob{0}.png".format(frame))
 */
    __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_10 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__title); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_36), __pyx_n_s__format); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_gprob), __pyx_n_s__min); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_v_gprob), __pyx_n_s__max); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_11 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_11);
    __pyx_t_9 = 0;
    __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_11);
    __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
 355:         pylab.imshow(gprob.transpose())
    /* "vision/alearn/marginals.pyx":355
 *         gprob = gprob / normalizer
 *         pylab.title("min = {0}, max = {1}".format(gprob.min(), gprob.max()))
 *         pylab.imshow(gprob.transpose())             # <<<<<<<<<<<<<<
 *         pylab.savefig("tmp/prob{0}.png".format(frame))
 *         pylab.clf()
 */
    __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__imshow); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_gprob), __pyx_n_s__transpose); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_11));
    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
 356:         pylab.savefig("tmp/prob{0}.png".format(frame))
    /* "vision/alearn/marginals.pyx":356
 *         pylab.title("min = {0}, max = {1}".format(gprob.min(), gprob.max()))
 *         pylab.imshow(gprob.transpose())
 *         pylab.savefig("tmp/prob{0}.png".format(frame))             # <<<<<<<<<<<<<<
 *         pylab.clf()
 * 
 */
    __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_11 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__savefig); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_39), __pyx_n_s__format); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_7 = PyInt_FromLong(__pyx_v_frame); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 357:         pylab.clf()
    /* "vision/alearn/marginals.pyx":357
 *         pylab.imshow(gprob.transpose())
 *         pylab.savefig("tmp/prob{0}.png".format(frame))
 *         pylab.clf()             # <<<<<<<<<<<<<<
 * 
 *         pylab.set_cmap("gray")
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__clf); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 358: 
 359:         pylab.set_cmap("gray")
    /* "vision/alearn/marginals.pyx":359
 *         pylab.clf()
 * 
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         pylab.title("min = {0}, max = {1}".format(greduct.min(), greduct.max()))
 *         pylab.imshow(greduct.transpose())
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__set_cmap); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_k_tuple_40), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "vision/alearn/marginals.pyx":359
 *         pylab.clf()
 * 
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         pylab.title("min = {0}, max = {1}".format(greduct.min(), greduct.max()))
 *         pylab.imshow(greduct.transpose())
 */
  __pyx_k_tuple_40 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_40));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gray));
  PyTuple_SET_ITEM(__pyx_k_tuple_40, 0, ((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_40));
 360:         pylab.title("min = {0}, max = {1}".format(greduct.min(), greduct.max()))
    /* "vision/alearn/marginals.pyx":360
 * 
 *         pylab.set_cmap("gray")
 *         pylab.title("min = {0}, max = {1}".format(greduct.min(), greduct.max()))             # <<<<<<<<<<<<<<
 *         pylab.imshow(greduct.transpose())
 *         pylab.savefig("tmp/reduct{0}.png".format(frame))
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__title); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_36), __pyx_n_s__format); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_greduct), __pyx_n_s__min); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_v_greduct), __pyx_n_s__max); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_9 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_11));
    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_10 = 0;
    __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
    __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_11));
    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 361:         pylab.imshow(greduct.transpose())
    /* "vision/alearn/marginals.pyx":361
 *         pylab.set_cmap("gray")
 *         pylab.title("min = {0}, max = {1}".format(greduct.min(), greduct.max()))
 *         pylab.imshow(greduct.transpose())             # <<<<<<<<<<<<<<
 *         pylab.savefig("tmp/reduct{0}.png".format(frame))
 *         pylab.clf()
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__imshow); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_greduct), __pyx_n_s__transpose); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
 362:         pylab.savefig("tmp/reduct{0}.png".format(frame))
    /* "vision/alearn/marginals.pyx":362
 *         pylab.title("min = {0}, max = {1}".format(greduct.min(), greduct.max()))
 *         pylab.imshow(greduct.transpose())
 *         pylab.savefig("tmp/reduct{0}.png".format(frame))             # <<<<<<<<<<<<<<
 *         pylab.clf()
 * 
 */
    __pyx_t_8 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyObject_GetAttr(__pyx_t_8, __pyx_n_s__savefig); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_41), __pyx_n_s__format); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_11 = PyInt_FromLong(__pyx_v_frame); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_11);
    __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_Call(__pyx_t_8, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_7));
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_11);
    __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
 363:         pylab.clf()
    /* "vision/alearn/marginals.pyx":363
 *         pylab.imshow(greduct.transpose())
 *         pylab.savefig("tmp/reduct{0}.png".format(frame))
 *         pylab.clf()             # <<<<<<<<<<<<<<
 * 
 *         pylab.set_cmap("gray")
 */
    __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__clf); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
 364: 
 365:         pylab.set_cmap("gray")
    /* "vision/alearn/marginals.pyx":365
 *         pylab.clf()
 * 
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         pylab.title("min = {0}, max = {1}".format(gerrors.min(), gerrors.max()))
 *         pylab.imshow(gerrors.transpose())
 */
    __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__set_cmap); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_k_tuple_42), NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "vision/alearn/marginals.pyx":365
 *         pylab.clf()
 * 
 *         pylab.set_cmap("gray")             # <<<<<<<<<<<<<<
 *         pylab.title("min = {0}, max = {1}".format(gerrors.min(), gerrors.max()))
 *         pylab.imshow(gerrors.transpose())
 */
  __pyx_k_tuple_42 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_42));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gray));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gray));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42));
 366:         pylab.title("min = {0}, max = {1}".format(gerrors.min(), gerrors.max()))
    /* "vision/alearn/marginals.pyx":366
 * 
 *         pylab.set_cmap("gray")
 *         pylab.title("min = {0}, max = {1}".format(gerrors.min(), gerrors.max()))             # <<<<<<<<<<<<<<
 *         pylab.imshow(gerrors.transpose())
 *         pylab.savefig("tmp/errors{0}.png".format(frame))
 */
    __pyx_t_11 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_7 = PyObject_GetAttr(__pyx_t_11, __pyx_n_s__title); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_36), __pyx_n_s__format); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_gerrors), __pyx_n_s__min); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_GetAttr(((PyObject *)__pyx_v_gerrors), __pyx_n_s__max); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_8 = 0;
    __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_9));
    PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_9), NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
 367:         pylab.imshow(gerrors.transpose())
    /* "vision/alearn/marginals.pyx":367
 *         pylab.set_cmap("gray")
 *         pylab.title("min = {0}, max = {1}".format(gerrors.min(), gerrors.max()))
 *         pylab.imshow(gerrors.transpose())             # <<<<<<<<<<<<<<
 *         pylab.savefig("tmp/errors{0}.png".format(frame))
 *         pylab.clf()
 */
    __pyx_t_10 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_9 = PyObject_GetAttr(__pyx_t_10, __pyx_n_s__imshow); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyObject_GetAttr(((PyObject *)__pyx_v_gerrors), __pyx_n_s__transpose); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_7 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_9, ((PyObject *)__pyx_t_10), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 368:         pylab.savefig("tmp/errors{0}.png".format(frame))
    /* "vision/alearn/marginals.pyx":368
 *         pylab.title("min = {0}, max = {1}".format(gerrors.min(), gerrors.max()))
 *         pylab.imshow(gerrors.transpose())
 *         pylab.savefig("tmp/errors{0}.png".format(frame))             # <<<<<<<<<<<<<<
 *         pylab.clf()
 * 
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_10 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__savefig); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_43), __pyx_n_s__format); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyInt_FromLong(__pyx_v_frame); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_11));
    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
    __pyx_t_11 = PyTuple_New(1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_11));
    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_9);
    __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_t_11), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 368; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_11)); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 369:         pylab.clf()
    /* "vision/alearn/marginals.pyx":369
 *         pylab.imshow(gerrors.transpose())
 *         pylab.savefig("tmp/errors{0}.png".format(frame))
 *         pylab.clf()             # <<<<<<<<<<<<<<
 * 
 *     return score / normalizer, frame
 */
    __pyx_t_9 = __Pyx_GetName(__pyx_m, __pyx_n_s__pylab); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_11 = PyObject_GetAttr(__pyx_t_9, __pyx_n_s__clf); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_Call(__pyx_t_11, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L32;
  }
  __pyx_L32:;
 370: 
 371:     return score / normalizer, frame
  /* "vision/alearn/marginals.pyx":371
 *         pylab.clf()
 * 
 *     return score / normalizer, frame             # <<<<<<<<<<<<<<
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_9 = PyFloat_FromDouble((__pyx_v_score / __pyx_v_normalizer)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_11 = PyInt_FromLong(__pyx_v_frame); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_10));
  PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  __pyx_t_9 = 0;
  __pyx_t_11 = 0;
  __pyx_r = ((PyObject *)__pyx_t_10);
  __pyx_t_10 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_backwrt);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_errorsvert);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_forwrt);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_matchscores);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_errors);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gprob);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_forwloce);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_costrt);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_backwe);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_forwe);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gerrors);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_greduct);
    __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gmargin);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("vision.alearn.marginals.scoremarginals", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_backwrt);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_errorsvert);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_forwrt);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_matchscores);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_errors);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gprob);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_forwloce);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_costrt);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_backwe);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_forwe);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gerrors);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_greduct);
  __Pyx_SafeReleaseBuffer(&__pyx_bstruct_gmargin);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_forw);
  __Pyx_XDECREF(__pyx_v_backw);
  __Pyx_XDECREF(__pyx_v_forwerr);
  __Pyx_XDECREF(__pyx_v_backwerr);
  __Pyx_XDECREF(__pyx_v_costs);
  __Pyx_XDECREF(__pyx_v_dim);
  __Pyx_XDECREF(__pyx_v_skip);
  __Pyx_XDECREF((PyObject *)__pyx_v_forwrt);
  __Pyx_XDECREF((PyObject *)__pyx_v_backwrt);
  __Pyx_XDECREF((PyObject *)__pyx_v_costrt);
  __Pyx_XDECREF((PyObject *)__pyx_v_forwe);
  __Pyx_XDECREF((PyObject *)__pyx_v_backwe);
  __Pyx_XDECREF((PyObject *)__pyx_v_forwloce);
  __Pyx_XDECREF((PyObject *)__pyx_v_gprob);
  __Pyx_XDECREF((PyObject *)__pyx_v_greduct);
  __Pyx_XDECREF((PyObject *)__pyx_v_gerrors);
  __Pyx_XDECREF((PyObject *)__pyx_v_gmargin);
  __Pyx_XDECREF((PyObject *)__pyx_v_matchscores);
  __Pyx_XDECREF((PyObject *)__pyx_v_errors);
  __Pyx_XDECREF((PyObject *)__pyx_v_errorsvert);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 372: