Пример #1
0
from __future__ import print_function, division
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile,
 printDBG) = __common__.init(__name__, '[classifier]', DEBUG=False)
# Science
import numpy as np
# HotSpotter
from hotspotter import report_results2 as rr2


def get_gt_cases(hs):
    valid_cxs = hs.get_valid_cxs()
    cx_list = [cx for cx in valid_cxs if len(hs.get_other_indexed_cxs(cx)) > 0]
    return cx_list


def get_labeled_descriptors(allres, orgtype_='false'):
    qcxs = allres[orgtype_].qcxs
    cxs = allres[orgtype_].cxs
    match_list = zip(qcxs, cxs)
    aggdesc1, aggdesc2 = rr2.get_matching_descriptors(allres, match_list)
    return aggdesc1, aggdesc2


def train_classifier(hs):
    cx_list = get_gt_cases(hs)
    allres = rr2.get_allres(hs, cx_list)
    neg_eg = get_labeled_descriptors(allres, 'false')
    pos_eg = get_labeled_descriptors(allres, 'true')

    # Cast to a datatype we can manipulate
Пример #2
0
from __future__ import print_function, division
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile,
 printDBG) = __common__.init(__name__, '[encounter]', DEBUG=False)
# Python
from itertools import izip
# Science
import networkx as netx
import numpy as np
from scipy.cluster.hierarchy import fclusterdata
# HotSpotter
from hotspotter import match_chips3 as mc3
from hscom import fileio as io
from hscom import helpers as util
from hsviz import draw_func2 as df2


def compute_encounters(hs, seconds_thresh=15):
    '''
    clusters encounters togethers (by time, not space)
    An encounter is a meeting, localized in time and space between a camera and
    a group of animals.  Animals are identified within each encounter.
    '''
    if not 'seconds_thresh' in vars():
        seconds_thresh = 3

    # For each image
    gx_list = hs.get_valid_gxs()

    # TODO: Get image GPS location
    #gps_info_list = hs.gx2_exif(gx_list, tag='GPSInfo')
Пример #3
0
from __future__ import division, print_function
from hscom import __common__

(print, print_, print_on, print_off, rrr, profile) = __common__.init(__name__, "[ds]")
# Standard
from itertools import izip, chain

# Scientific
import numpy as np

# HotSpotter
from hscom import helpers
from hscom.Printable import DynStruct

ID_DTYPE = np.int32  # id datatype
X_DTYPE = np.int32  # indeX datatype

DEBUG = False  # Debug flag

if DEBUG:

    def printDBG(msg):
        print("[DS.DBG] " + msg)


else:

    def printDBG(msg):
        pass

Пример #4
0
#!/usr/env python
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile, printDBG) =\
__common__.init(__name__, '[rr2]', DEBUG=False)
# Matplotlib
import matplotlib
matplotlib.use('Qt4Agg')
# Python
import os
import sys
import textwrap
import fnmatch
import warnings
from itertools import izip
from os.path import join, exists
# Scientific imports
import numpy as np
# Hotspotter imports
from hscom import fileio as io
from hscom import helpers
from hscom.Printable import DynStruct
from hsviz import draw_func2 as df2
from hsviz import viz
import load_data2 as ld2
import spatial_verification2 as sv2
#import match_chips3 as mc3
#import datetime
#import subprocess

REPORT_MATRIX = True
Пример #5
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[dbinfo]')
# Python
import os
import sys
from os.path import isdir, islink, isfile, join, exists
from collections import OrderedDict
# Science
import numpy as np
from PIL import Image
# Hotspotter
import load_data2 as ld2
from hscom import helpers


def dir_size(path):
    if sys.platform == 'win32':
        pass
    else:
        import commands
        size = commands.getoutput('du -sh ' + path).split()[0]
    return size


def is_dir2(path):
    return isdir(path) and not islink(path)


def is_link2(path):
Пример #6
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[front]')
# Python
import sys
# Qt
from PyQt4 import QtGui, QtCore
from PyQt4.Qt import (QAbstractItemView, pyqtSignal, Qt)
# HotSpotter
from _frontend.MainSkel import Ui_mainSkel
import guitools
from guitools import slot_
from guitools import frontblocking as blocking
from hscom import tools

#=================
# Globals
#=================

IS_INIT = False
NOSTEAL_OVERRIDE = False  # Hard disable switch for stream stealer

#=================
# Decorators / Helpers
#=================


def clicked(func):
    def clicked_wrapper(front, item, *args, **kwargs):
        if front.isItemEditable(item):
Пример #7
0
from os.path import join, expanduser, split, exists
import numpy as np
import xml.dom.minidom as minidom
import sys
import matplotlib.image as image
import shutil

### from Hotspotter
from hscom import helpers
from hscom import argparse2
from hscom import params
from hscom import fileio as io
from hscom import __common__
from hotspotter import HotSpotterAPI
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[helpers]')

HOME = expanduser('~')
GLOBAL_CACHE_DIR = join(HOME, '.hotspotter/global_cache')
helpers.ensuredir(GLOBAL_CACHE_DIR)

#%%
# =============================================================================
#  Initialization (User needs to modify the below contens )
# =============================================================================
### New database path
dpath = 'C:\\Users\\95316\\code1\\Snow leopard'
###Database name
new_db = 'left_diff_cats'
### Full path: dapth + new_db
Пример #8
0
'hotspotter.algos contains algorithm poltpori'
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[algos]')
# Python
from itertools import izip
from os.path import join
import os
import sys
import textwrap
# Matplotlib
#import matplotlib.pyplot as plt
# Scientific
import pyflann
#import sklearn.decomposition
#import sklearn.preprocessing
#import sklearn
import numpy as np
import scipy.sparse as spsparse
# Hotspotter
from hscom import fileio as io
from hscom import helpers


DIST_LIST = ['L1', 'L2']


def compute_distances(hist1, hist2, dist_list=DIST_LIST):
    return {type_: globals()[type_](hist1, hist2) for type_ in dist_list}
Пример #9
0
from __future__ import division, print_function
from os.path import join, expanduser,split,exists
from os import makedirs 
import numpy as np
### from Hotspotter
from hscom import helpers
from hscom import fileio as io
from hscom import __common__
from hscom import argparse2
from hscom import params
from hotspotter import HotSpotterAPI
from hsviz import draw_func2 as df2
from hsviz import viz

(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[helpers]')

HOME = expanduser('~')
GLOBAL_CACHE_DIR = join(HOME, '.hotspotter/global_cache')
helpers.ensuredir(GLOBAL_CACHE_DIR)

Flag_save = 1
#%%
# =============================================================================
#  Initialization (User needs to modify the below contens )
# =============================================================================

### New database path
dpath = 'C:\\Users\\95316\\code1\\Snow leopard'
###Database name
new_db = 'left_diff_cats'
Пример #10
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[mc3]')
# Python
import re
# HotSpotter
from hscom import helpers
import DataStructures as ds
import matching_functions as mf


@profile
def ensure_nn_index(hs, qdat, dcxs):
    # NNIndexes depend on the data cxs AND feature / chip configs
    feat_uid = qdat.cfg._feat_cfg.get_uid()
    dcxs_uid = helpers.hashstr_arr(dcxs, 'dcxs') + feat_uid
    if not dcxs_uid in qdat._dcxs2_index:
        # Make sure the features are all computed first
        print('[mc3] qdat._data_index[dcxs_uid]... cache miss')
        print('[mc3] dcxs_ is not in qdat cache')
        print('[mc3] hashstr(dcxs_) = %r' % dcxs_uid)
        print('[mc3] REFRESHING FEATURES')
        hs.refresh_features(dcxs)
        # Compute the FLANN Index
        data_index = ds.NNIndex(hs, dcxs)
        qdat._dcxs2_index[dcxs_uid] = data_index
    else:
        print('[mc3] qdat._data_index[dcxs_uid]... cache hit')
    qdat._data_index = qdat._dcxs2_index[dcxs_uid]
Пример #11
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile, printDBG) = \
    __common__.init(__name__, '[allres-viz]', DEBUG=False)
from os.path import join
import numpy as np
from hscom import helpers
from hscom import helpers as util
import draw_func2 as df2
import os
# Global variables
BROWSE = True
DUMP = False
FIGNUM = 1


def plot_rank_stem(allres, orgres_type='true'):
    print('[viz] plotting rank stem')
    # Visualize rankings with the stem plot
    hs = allres.hs
    title = orgres_type + 'rankings stem plot\n' + allres.title_suffix
    orgres = allres.__dict__[orgres_type]
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    x_data = orgres.qcxs
    y_data = orgres.ranks
    df2.draw_stems(x_data, y_data)
    slice_num = int(np.ceil(np.log10(len(orgres.qcxs))))
    df2.set_xticks(hs.test_sample_cx[::slice_num])
    df2.set_xlabel('query chip indeX (qcx)')
    df2.set_ylabel('groundtruth chip ranks')
    #df2.set_yticks(list(seen_ranks))
Пример #12
0
#exec(open('__init__.py').read())
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[extract]')
# Science
import cv2
import numpy as np
from numpy import sqrt
# Hotspotter
import draw_func2 as df2


def rrr():
    import imp
    import sys
    print('[extract] Reloading: ' + __name__)
    imp.reload(sys.modules[__name__])


def svd(M):
    flags = cv2.SVD_FULL_UV
    S, U, V = cv2.SVDecomp(M, flags=flags)
    S = S.flatten()
    return U, S, V


def draw_warped_keypoint_patch(rchip, kp, **kwargs):
    return draw_keypoint_patch(rchip, kp, warped=True, **kwargs)

Пример #13
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile, printDBG) = __common__.init(__name__, '[front]', DEBUG=False)
# Python
import sys
# Qt
from PyQt4 import QtGui, QtCore
from PyQt4.Qt import (QAbstractItemView, pyqtSignal, Qt)
# HotSpotter
from _frontend.MainSkel import Ui_mainSkel
import guitools
from guitools import slot_
from guitools import frontblocking as blocking
from hscom import tools

#=================
# Globals
#=================

IS_INIT = False
NOSTEAL_OVERRIDE = False  # Hard disable switch for stream stealer


#=================
# Decorators / Helpers
#=================

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
Пример #14
0
#exec(open('__init__.py').read())
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[extract]')
# Science
import cv2
import numpy as np
from numpy import sqrt
# Hotspotter
import draw_func2 as df2


def rrr():
    import imp
    import sys
    print('[extract] Reloading: ' + __name__)
    imp.reload(sys.modules[__name__])


def svd(M):
    flags = cv2.SVD_FULL_UV
    S, U, V = cv2.SVDecomp(M, flags=flags)
    S = S.flatten()
    return U, S, V


def draw_warped_keypoint_patch(rchip, kp, **kwargs):
    return draw_keypoint_patch(rchip, kp, warped=True, **kwargs)

Пример #15
0
'hotspotter.algos contains algorithm poltpori'
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[algos]')
# Python
from itertools import izip
from os.path import join
import os
import sys
import textwrap
# Matplotlib
#import matplotlib.pyplot as plt
# Scientific
from hstpl.extern_feat import pyflann
#import sklearn.decomposition
#import sklearn.preprocessing
#import sklearn
import numpy as np
import scipy.sparse as spsparse
# Hotspotter
from hscom import fileio as io
from hscom import helpers

DIST_LIST = ['L1', 'L2']


def compute_distances(hist1, hist2, dist_list=DIST_LIST):
    return {type_: globals()[type_](hist1, hist2) for type_ in dist_list}

Пример #16
0
from __future__ import print_function, division
# Standard
#from itertools import izip
#from ctypes.util import find_library
from os.path import realpath, dirname
import ctypes_interface
import ctypes as C
import collections
# Scientific
import numpy as np
# Hotspotter
from hscom import __common__
print, print_, print_on, print_off, rrr, profile, printDBG =\
    __common__.init(__name__, module_prefix='[hes]', DEBUG=False, initmpl=False)

#============================
# hesaff ctypes interface
#============================

# numpy dtypes
kpts_dtype = np.float32
desc_dtype = np.uint8
# ctypes
FLAGS_RW = 'aligned, c_contiguous, writeable'
obj_t = C.c_void_p
kpts_t = np.ctypeslib.ndpointer(dtype=kpts_dtype, ndim=2, flags=FLAGS_RW)
desc_t = np.ctypeslib.ndpointer(dtype=desc_dtype, ndim=2, flags=FLAGS_RW)
str_t = C.c_char_p
int_t = C.c_int
float_t = C.c_float
Пример #17
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[sv2]')
# Science
import numpy as np
import numpy.linalg as linalg
import scipy.sparse as sparse
import scipy.sparse.linalg as sparse_linalg
# Standard
# skimage.transform
# http://stackoverflow.com/questions/11462781/fast-2d-rigid-body-transformations-in-numpy-scipy
# skimage.transform.fast_homography(im, H)

SV_DTYPE = np.float64


def printDBG(msg):
    pass
    #print(msg)


@profile
def compute_homog(x1_mn, y1_mn, x2_mn, y2_mn):
    '''Generate 6 degrees of freedom homography transformation
    Computes homography from normalized (0 to 1) point correspondences
    from 2 --> 1 '''
    #printDBG('[sv2] compute_homog')
    num_pts = len(x1_mn)
    Mbynine = np.zeros((2 * num_pts, 9), dtype=SV_DTYPE)
    for ix in xrange(num_pts):  # Loop over inliers
Пример #18
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[mc3]')
# Python
import re
# HotSpotter
from hscom import helpers
import DataStructures as ds
import matching_functions as mf


@profile
def ensure_nn_index(hs, qdat, dcxs):
    # NNIndexes depend on the data cxs AND feature / chip configs
    feat_uid = qdat.cfg._feat_cfg.get_uid()
    dcxs_uid = helpers.hashstr_arr(dcxs, 'dcxs') + feat_uid
    if not dcxs_uid in qdat._dcxs2_index:
        # Make sure the features are all computed first
        print('[mc3] qdat._data_index[dcxs_uid]... cache miss')
        print('[mc3] dcxs_ is not in qdat cache')
        print('[mc3] hashstr(dcxs_) = %r' % dcxs_uid)
        print('[mc3] REFRESHING FEATURES')
        hs.refresh_features(dcxs)
        # Compute the FLANN Index
        data_index = ds.NNIndex(hs, dcxs)
        qdat._dcxs2_index[dcxs_uid] = data_index
    else:
        print('[mc3] qdat._data_index[dcxs_uid]... cache hit')
    qdat._data_index = qdat._dcxs2_index[dcxs_uid]
Пример #19
0
from __future__ import print_function, division
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[scripts]')
# Python
from os.path import dirname, join, splitext
import shutil
from itertools import izip
# Science
import numpy as np
from scipy.cluster.hierarchy import fclusterdata
# HotSpotter
from hscom import fileio as io
from hscom import helpers
from hotspotter import load_data2 as ld2

#from dbgimport import *  # NOQA


def extract_encounter(hs, eid):
    work_dir = dirname(hs.dirs.db_dir)
    newdb_name = hs.get_db_name() + '_encounter_%s' % (eid)
    new_dbdir = join(work_dir, newdb_name)
    gx_list = np.where(np.array(hs.tables.gx2_eid) == eid)[0]
    if len(gx_list) == 0:
        raise Exception('no images to export')
    export_subdb_locals = export_subdatabase(hs, gx_list, new_dbdir)
    return locals()


def export_subdatabase(hs, gx_list, new_dbdir):
Пример #20
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[training]')
import numpy as np
from hscom import helpers
from hotspotter import chip_compute2 as cc2
from os.path import join


def get_training_output_dir(hs):
    output_dir = join(hs.dirs.computed_dir, 'training_examples')
    return output_dir


def vdg(hs):
    output_dir = get_training_output_dir(hs)
    helpers.vd(output_dir)


def generate_detector_training_data(hs, uniform_size=(512, 256)):
    print('')
    print('===================')
    print('Generating training data')
    lazy = helpers.get_flag('--lazy', True)
    output_dir = get_training_output_dir(hs)

    batch_extract_kwargs = {
        'lazy': lazy,
        'num_procs': hs.args.num_procs,
        'force_gray': False,
Пример #21
0
from __future__ import division, print_function
from hscom import __common__
print, print_, print_on, print_off, rrr, profile, printDBG =\
    __common__.init(__name__, '[cov]', DEBUG=False)
# Standard
from itertools import izip
from itertools import product as iprod
import math
# Science
import cv2
import numpy as np
# HotSpotter
from hscom import helpers as util
import matching_functions as mf

SCALE_FACTOR_DEFAULT = .05
METHOD_DEFAULT = 0


def score_chipmatch_coverage(hs, qcx, chipmatch, qreq, method=0):
    prescore_method = 'csum'
    nShortlist = 100
    dcxs_ = set(qreq._dcxs)
    (cx2_fm, cx2_fs, cx2_fk) = chipmatch
    cx2_prescore = mf.score_chipmatch(hs, qcx, chipmatch, prescore_method, qreq)
    topx2_cx = cx2_prescore.argsort()[::-1]  # Only allow indexed cxs to be in the top results
    topx2_cx = [cx for cx in iter(topx2_cx) if cx in dcxs_]
    nRerank = min(len(topx2_cx), nShortlist)
    cx2_score = [0 for _ in xrange(len(cx2_fm))]
    mark_progress, end_progress = util.progress_func(nRerank, flush_after=10,
                                                     lbl='[cov] Compute coverage')
Пример #22
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile, printDBG)\
    = __common__.init(__name__, '[inter]', DEBUG=False)
# Scientific
import numpy as np
# Hotspotter
import draw_func2 as df2
import viz
from hstpl import mask_creator


# RCOS TODO: We should change the fnum, pnum figure layout into one managed by
# gridspec.

#==========================
# HELPERS
#==========================

def nearest_point(x, y, pts):
    dists = (pts.T[0] - x) ** 2 + (pts.T[1] - y) ** 2
    fx = dists.argmin()
    mindist = dists[fx]
    other_fx = np.where(mindist == dists)[0]
    if len(other_fx > 0):
        np.random.shuffle(other_fx)
        fx = other_fx[0]
    return fx, mindist


def detect_keypress(fig):
Пример #23
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[guitools]')
# Python
from os.path import split
import sys
#import warnings
# Science
import numpy as np
# Qt
import PyQt4
from PyQt4 import QtCore, QtGui
from PyQt4.Qt import Qt
# HotSpotter
from hscom import fileio as io
from hscom import helpers
from hsviz import draw_func2 as df2

IS_INIT = False
DISABLE_NODRAW = False
DEBUG = False

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s


def configure_matplotlib():
    import multiprocessing
Пример #24
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[vr2]')
# Python
from itertools import izip
# Scientific
import pandas as pd
import numpy as np
from numpy.linalg import svd
#from numba import autojit
# HotSpotter
from hscom import helpers


def score_chipmatch_csum(chipmatch):
    (_, cx2_fs, _) = chipmatch
    cx2_score = np.array([np.sum(fs) for fs in cx2_fs])
    return cx2_score


def score_chipmatch_nsum(hs, qcx, chipmatch, qdat):
    raise NotImplementedError('nsum')


def score_chipmatch_nunique(hs, qcx, chipmatch, qdat):
    raise NotImplementedError('nunique')


def enforce_one_name(hs, cx2_score, chipmatch=None, cx2_chipscore=None):
    'this is a hack to make the same name only show up once in the top ranked list'
Пример #25
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[back]')
# Python
from os.path import split, exists, join
# Qt
from PyQt4 import QtCore
from PyQt4.Qt import pyqtSignal
# Science
import numpy as np
# Hotspotter
import guifront
import guitools
from guitools import drawing, slot_
from guitools import backblocking as blocking
from hscom import helpers
from hscom import fileio as io
from hsviz import draw_func2 as df2
from hsviz import viz
from hsviz import interact
from hotspotter import HotSpotterAPI

FNUMS = dict(image=1, chip=2, res=3, inspect=4, special=5, name=6)
viz.register_FNUMS(FNUMS)


# Helper functions (should probably be moved into HotSpotter API)


def select_next_unannotated(back):
Пример #26
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[extern_feat]')
# Standard
import os
import sys
from os.path import dirname, realpath, join
# Scientific
import numpy as np

OLD_HESAFF = False or '--oldhesaff' in sys.argv
if '--newhesaff' in sys.argv:
    OLD_HESAFF = False


def reload_module():
    import imp
    import sys
    imp.reload(sys.modules[__name__])

EXE_EXT = {'win32': '.exe', 'darwin': '.mac', 'linux2': '.ln'}[sys.platform]

if not '__file__' in vars():
    __file__ = os.path.realpath('extern_feat.py')
EXE_PATH = realpath(dirname(__file__))
if not os.path.exists(EXE_PATH):
    EXE_PATH = realpath('tpl/extern_feat')
if not os.path.exists(EXE_PATH):
    EXE_PATH = realpath('hotspotter/tpl/extern_feat')
Пример #27
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[convert]')
import sys
from os.path import join, relpath, normpath, exists
import collections
import os
import parse
# Science
from PIL import Image
import numpy as np
# Hotspotter
from hscom import helpers
import load_data2 as ld2
import db_info

# BUGS: TODO:
# Orientation within chip


def try_autoconvert(db_dir):
    if db_info.has_v2_gt(db_dir):
        raise NotImplementedError('hotspotter v2 conversion')
    if db_info.has_v1_gt(db_dir):
        raise NotImplementedError('hotspotter v1 conversion')
    if db_info.has_ss_gt(db_dir):
        raise NotImplementedError('stripe spotter conversion')
    if db_info.has_partial_gt(db_dir):
        raise NotImplementedError('partial database recovery')
    return False
Пример #28
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile,
 printDBG) = __common__.init(__name__, '[dev_api]', DEBUG=False)
import dev_stats
import dev_consistency
import dev_reload
from hscom.Printable import DynStruct
from hscom import helpers as util


class DebugAPI(DynStruct):
    def __init__(dbg, hs):
        super(DebugAPI, dbg).__init__(child_exclude_list=['hs'])
        dbg.hs = hs
        for key, val in util.module_functions(dev_consistency):
            printDBG('[devapi] augmenting: ' + str(val))
            dbg.__dict__[key] = val

    def dbstats(dbg):
        return dev_stats.dbstats(dbg.hs)

    def reload(dbg):
        _reload()


def augment_api(hs):
    dbg = DebugAPI(hs)

    hs.dbg = dbg
    return hs
Пример #29
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile,
 printDBG) = __common__.init(__name__, '[cfgbank]', DEBUG=False)
# Python

vsmany_2 = {
    'query_type': ['vsmany'],
    'checks': [1024],  # , 8192],
    'K': [5],  # 5, 10],
    'Knorm': [1],  # 2, 3],
    'Krecip': [0],  # , 5, 10],
    'roidist_weight': [0],  # 1,]
    'recip_weight': [0],  # 1,]
    'bursty_weight': [0],  # 1,]
    'ratio_weight': [0, 1],  # 1,]
    'lnbnn_weight': [0, 1],  # 1,]
    'lnrat_weight': [0, 1],  # 1,]
    'roidist_thresh': [None],  # .5,]
    'recip_thresh': [0],  # 0
    'bursty_thresh': [None],  #
    'ratio_thresh': [None],  # 1.2, 1.6
    'lnbnn_thresh': [None],  #
    'lnrat_thresh': [None],  #
    'nShortlist': [50],
    'sv_on': [True],  # True, False],
    'score_method': ['csum'],
    'max_alts': [1000],
}

vsone_1 = {
Пример #30
0
#!/usr/bin/env python
#exec(open('__init__.py').read())
#exec(open('_research/dev.py').read())
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile, printDBG) = __common__.init(__name__, '[dev]', DEBUG=False)
# Matplotlib
import matplotlib
matplotlib.use('Qt4Agg')
# Standard
import textwrap
import sys
from os.path import join
import multiprocessing
# Scientific
import numpy as np
#import cv2
# HotSpotter
#from hotspotter import spatial_verification2 as sv2
from hotspotter import DataStructures as ds
from hotspotter import match_chips3 as mc3
from hotspotter import matching_functions as mf
from hotspotter import report_results2 as rr2
from hotspotter import voting_rules2 as vr2
from hscom import helpers
from hscom import latex_formater as pytex
from hsviz import draw_func2 as df2
from hsviz import viz

Пример #31
0
'This module should handle all things elliptical'
from __future__ import print_function, division
# Python
from itertools import izip
# Scientific
from numpy import array, zeros, ones
from numpy.core.umath_tests import matrix_multiply
from scipy.signal import argrelextrema
import cv2
import numpy as np
import scipy as sp  # NOQA
# Hotspotter
from hscom import __common__
print, print_, print_on, print_off, rrr, profile, printDBG =\
    __common__.init(__name__, module_prefix='[ell]', DEBUG=False, initmpl=False)


def test_data():
    import test_pyhesaff
    test_data = test_pyhesaff.load_test_data()
    kpts = test_data['kpts']
    exec(open('ellipse.py').read())
    return locals()


@profile
def adaptive_scale(img_fpath, kpts, nScales=4, low=-.5, high=.5, nSamples=16):
    imgBGR = cv2.imread(img_fpath, flags=cv2.CV_LOAD_IMAGE_COLOR)

    nKp = len(kpts)
    dtype_ = kpts.dtype
Пример #32
0
from __future__ import division, print_function
from hscom import __common__
(print, print_,
 print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[convert]')
import sys
from os.path import join, relpath, normpath, exists
import collections
import os
import parse
# Science
from PIL import Image
import numpy as np
# Hotspotter
from hscom import helpers
import load_data2 as ld2
import db_info


# BUGS: TODO:
# Orientation within chip

def try_autoconvert(db_dir):
    if db_info.has_v2_gt(db_dir):
        raise NotImplementedError('hotspotter v2 conversion')
    if db_info.has_v1_gt(db_dir):
        raise NotImplementedError('hotspotter v1 conversion')
    if db_info.has_ss_gt(db_dir):
        raise NotImplementedError('stripe spotter conversion')
    if db_info.has_partial_gt(db_dir):
        raise NotImplementedError('partial database recovery')
Пример #33
0
'''
Module: load_data
    Loads the paths and table information from which all other data is computed.
    This is the first script run in the loading pipeline.
'''
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile,
 printDBG) = __common__.init(__name__, '[ld3]', DEBUG=False)
# Standard
from os.path import join, exists, splitext
import os
import re
import shutil
import sys
# Science
import numpy as np
from PIL import Image
# Hotspotter
import DataStructures as ds
from hscom import helpers
from hscom import helpers as util
from hscom import tools
import db_info

#========================================
# GLOBALS
#========================================

VERBOSE_LOAD_DATA = True
VERBOSE_DETERMINE_VERSION = False
Пример #34
0
from __future__ import division, print_function
from hscom import __common__
print, print_, print_on, print_off, rrr, profile, printDBG =\
    __common__.init(__name__, '[nnfilt]', DEBUG=False)
import numpy as np
from numpy import array
from itertools import izip

eps = 1E-8


def LNRAT_fn(vdist, ndist):
    return np.log(np.divide(ndist, vdist + eps) + 1)


def RATIO_fn(vdist, ndist):
    return np.divide(ndist, vdist + eps)


def LNBNN_fn(vdist, ndist):
    return (ndist - vdist) #  / 1000.0


# normweight_fn = LNBNN_fn
''''
ndist = array([[0, 1, 2], [3, 4, 5], [3, 4, 5], [3, 4, 5],  [9, 7, 6] ])
vdist = array([[3, 2, 1, 5], [3, 2, 5, 6], [3, 4, 5, 3], [3, 4, 5, 8],  [9, 7, 6, 3] ])
vdist1 = vdist[:,0:1]
vdist2 = vdist[:,0:2]
vdist3 = vdist[:,0:3]
vdist4 = vdist[:,0:4]
Пример #35
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[dev_consist]')
# Standard
from os.path import relpath
# Science
import numpy as np
# Hotspotter
from hscom import fileio as io
from hscom import helpers as util


#----------------------
# Debug Consistency Checks
def check_keypoint_consistency(hs):
    cx2_cid = hs.tables.cx2_cid
    cx2_kpts = hs.feats.cx2_kpts
    bad_cxs = [cx for cx, kpts in enumerate(cx2_kpts) if kpts is None]
    passed = True
    if len(bad_cxs) > 0:
        print('[dev_consist] cx2_kpts has %d None positions:' % len(bad_cxs))
        print('[dev_consist] bad_cxs = %r' % bad_cxs)
        passed = False
    if len(cx2_kpts) != len(cx2_cid):
        print('[dev_consist] len(cx2_kpts) != len(cx2_cid): %r != %r' %
              (len(cx2_kpts), len(cx2_cid)))
        passed = False
    if passed:
        print('[dev_consist] cx2_kpts is OK')
Пример #36
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile, printDBG) = \
    __common__.init(__name__, '[viz]', DEBUG=False)
import matplotlib
matplotlib.use('Qt4Agg')
#import re
import warnings
# Scientific
import numpy as np
# Hotspotter
import draw_func2 as df2
import extract_patch
from hscom import fileio as io
from hscom import helpers

#from interaction import interact_keypoints, interact_chipres, interact_chip # NOQA


FNUMS = dict(image=1, chip=2, res=3, inspect=4, special=5, name=6)

IN_IMAGE_OVERRIDE = helpers.get_arg('--in-image-override', type_=bool, default=None)
SHOW_QUERY_OVERRIDE = helpers.get_arg('--show-query-override', type_=bool, default=None)
NO_LABEL_OVERRIDE = helpers.get_arg('--no-label-override', type_=bool, default=None)


@profile
def draw():
    df2.adjust_subplots_safe()
    df2.draw()
Пример #37
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile, printDBG) = \
    __common__.init(__name__, '[viz]', DEBUG=False)
import matplotlib
matplotlib.use('Qt4Agg')
#import re
import warnings
# Scientific
import numpy as np
# Hotspotter
import draw_func2 as df2
import extract_patch
from hscom import fileio as io
from hscom import helpers

#from interaction import interact_keypoints, interact_chipres, interact_chip # NOQA

FNUMS = dict(image=1, chip=2, res=3, inspect=4, special=5, name=6)

IN_IMAGE_OVERRIDE = helpers.get_arg('--in-image-override',
                                    type_=bool,
                                    default=None)
SHOW_QUERY_OVERRIDE = helpers.get_arg('--show-query-override',
                                      type_=bool,
                                      default=None)
NO_LABEL_OVERRIDE = helpers.get_arg('--no-label-override',
                                    type_=bool,
                                    default=None)

Пример #38
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[back]')
# Python
from os.path import split, exists, join
# Qt
from PyQt4 import QtCore
from PyQt4.Qt import pyqtSignal
# Science
import numpy as np
# Hotspotter
import guifront
import guitools
from guitools import drawing, slot_
from guitools import backblocking as blocking
from hscom import helpers
from hscom import fileio as io
from hsviz import draw_func2 as df2
from hsviz import viz
from hsviz import interact
from hotspotter import HotSpotterAPI
import os

FNUMS = dict(image=1, chip=2, res=3, inspect=4, special=5, name=6)
viz.register_FNUMS(FNUMS)

# Helper functions (should probably be moved into HotSpotter API)


def select_next_unannotated(back):
Пример #39
0
#!/usr/env python
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr, profile, printDBG) =\
__common__.init(__name__, '[rr2]', DEBUG=False)
# Matplotlib
import matplotlib
matplotlib.use('Qt4Agg')
# Python
import os
import sys
import textwrap
import fnmatch
import warnings
from itertools import izip
from os.path import join, exists
# Scientific imports
import numpy as np
# Hotspotter imports
from hscom import fileio as io
from hscom import helpers
from hscom.Printable import DynStruct
from hsviz import draw_func2 as df2
from hsviz import viz
import load_data2 as ld2
import spatial_verification2 as sv2
#import match_chips3 as mc3
#import datetime
#import subprocess

REPORT_MATRIX  = True
Пример #40
0
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off, rrr,
 profile) = __common__.init(__name__, '[extern_feat]')
# Standard
import os
import sys
from os.path import dirname, realpath, join, expanduser
# Scientific
import numpy as np
import pdb

OLD_HESAFF = False or '--oldhesaff' in sys.argv
if '--newhesaff' in sys.argv:
    OLD_HESAFF = False


def reload_module():
    import imp
    import sys
    imp.reload(sys.modules[__name__])


EXE_EXT = {'win32': '.exe', 'darwin': '.mac', 'linux2': '.ln'}[sys.platform]

if not '__file__' in vars():
    __file__ = os.path.realpath('extern_feat.py')
EXE_PATH = realpath(dirname(__file__))
if not os.path.exists(EXE_PATH):
    EXE_PATH = realpath('tpl/extern_feat')
if not os.path.exists(EXE_PATH):
Пример #41
0
#from __init__ import *
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[seg]')
import numpy as np
from hscom import helpers
import cv2
import algos
from hscom import fileio as io

DEBUG_SEGM = False


def printDBG(msg):
    if DEBUG_SEGM:
        print(msg)
    pass


def im(img, fnum=0):
    from hsviz import draw_func2 as df2
    df2.imshow(img, fnum=fnum)
    df2.update()


def resize_img_and_roi(img_fpath, roi_, new_size=None, sqrt_area=400.0):
    printDBG('[segm] imread(%r) ' % img_fpath)
    full_img = io.imread(img_fpath)
    (full_h, full_w) = full_img.shape[:2]                 # Image Shape
    printDBG('[segm] full_img.shape=%r' % (full_img.shape,))
Пример #42
0
''' Computes feature representations '''
from __future__ import division, print_function
from hscom import __common__
(print, print_, print_on, print_off,
 rrr, profile) = __common__.init(__name__, '[fc2]')
# scientific
import numpy as np
# python
from os.path import join
# hotspotter
from hscom import helpers
from hscom import fileio as io
from hscom.Parallelize import parallel_compute
import extern_feat


def whiten_features(desc_list):
    import algos
    print('[fc2] * Whitening features')
    ax2_desc = np.vstack(desc_list)
    ax2_desc_white = algos.scale_to_byte(algos.whiten(ax2_desc))
    index = 0
    offset = 0
    for cx in xrange(len(desc_list)):
        old_desc = desc_list[cx]
        print ('[fc2] * ' + helpers.info(old_desc, 'old_desc'))
        offset = len(old_desc)
        new_desc = ax2_desc_white[index:(index + offset)]
        desc_list[cx] = new_desc
        index += offset