Esempio n. 1
0
def outfacing(lock, receiver, ttsque=None, finder=finder):
    cv2.namedWindow('visuals')
    processor = faceprocessor()
    extractor = modelInferance()
    processor.setSource(cv2.VideoCapture(0))
    processor.setFinder(finder().nextFaces)
    faceDict = FaceDictionary()
    datawindow = window()
    dnn = model()
    dnn.load_previous()
    generator = datagenerator()
    clf, revmap = load_classifier(lock)
    cacher = feature_cacher()
    kill = False
    cacheFlag = False
    label = None
    cv2.namedWindow('visual')
    ix = 0
    while cv2.waitKey(10) < 0 and not kill:
        temp = processor.getFaces()
        if receiver and receiver.poll(0.001):
            signal = receiver.recv()
            print(signal)
            if signal.find('label:') >= 0:
                label = signal[signal.find(':') + 1:]
                cacheFlag = True
            if signal == 'STOPCACHE':
                cacheFlag = False
            if signal == 'KILL':
                kill = True
            if signal == 'Done Thinking':
                clf, revmap = load_classifier(lock)
                print('HOT SWAPPED CLASSIFIER')
        if temp is None:
            continue
        frame, fbbs, wfaces = temp
        feats = extractor.getFeatures(wfaces)
        #faceDict.update(fbbs,feats)
        #index,fbbs,feats = faceDict.getobjs()
        index = np.ones(len(fbbs))
        clss, score, tmap = handledata(dnn, cacher, generator, cacheFlag,
                                       label, feats, wfaces, datawindow)
        if tmap is not None:
            revmap = tmap
        if score is not None:
            isUnknown = score < 8.0
        else:
            isUnknown = False

        sendmesg(isUnknown, 'What are you doing here? Relinquish thine name. ',
                 ttsque)

        ix += 1

        visualize(frame, fbbs, wfaces, clss, revmap, isUnknown, index)
        # print(clss)
    extractor.kill()
    return 1
Esempio n. 2
0
def ROS_Facing(lock):

    processor = faceprocessor()
    extractor = modelInferance()
    faceDict = FaceDictionary()
    datawindow = IdWindows()
    dnn = model()
    dnn.load_previous()
    generator = datagenerator()
    clf, revmap = load_classifier(lock)
    cacher = feature_cacher()
    opts = {'kill': False, 'cacheFlag': False, 'label': None}

    def destroy():
        extractor.kill()

    def callback(data, options={}):
        bbs, img = data
        temp = processor.get_cb_faces(img, bbs)
        if temp == None:
            return
        frame, fbbs, wfaces = temp
        feats = extractor.getFeatures(wfaces)
        faceDict.update(fbbs, feats)
        index, fbbs, feats = faceDict.getobjs()
        if 'label' in options and options['label'] is not None:
            opts['label'] = options['label']
        if 'store' in options:
            opts['cacheFlag'] = options['store']

        clss, score, tmap = handledata(dnn, cacher, generator,
                                       opts['cacheFlag'], opts['label'], feats,
                                       wfaces, datawindow, index)

        if 'save' in options and options['save'] is not None:
            options['save'] = None
            dnn.save(filename=options['save'])

        if 'load' in options and options['load'] is not None:
            options['load'] = None
            dnn.load_previous(filename=options['load'])

        clasmap = ''
        if tmap is not None:
            clasmap = tmap
        else:
            clasmap = revmap
        isUnknown = {
            k: v
            for k, v in zip(index, np.zeros((1, len(index)), dtype=bool))
        }
        if len(isUnknown.keys()) == 0:
            isUnknown = [False]
        for id in index:
            if id in score:
                isUnknown[id] = score[id] < 8.0
            else:
                isUnknown[id] = False
        return visualize(frame, fbbs, wfaces, clss, clasmap, isUnknown, index)

    return callback, destroy
Esempio n. 3
0
# coding: utf-8

import numpy as np
from tensorflowclassifier import model
mymodel = model()
from datagen import datagenerator
dg = datagenerator()
mymodel.load_previous
mymodel.load_previous()
dg.load_sectioned_features()
mymodel.input_data(dg.testingfeats[0], dg.testinglbls[0])
dg.testingfeats
mymodel.input_data(dg.testingfeats[0], dg.testinglbls[0])
mymodel.input_data(dg.trainingfeats[0], dg.traininglbls[0])
dg.traininglbls[0]
mymodel.input_data(dg.trainingfeats[2], dg.traininglbls[2])
dg.traininglbls[2]
p = mymodel.pred()
p
np.sum(p.argmax() == 2) / p.shape[0]
p
p.argmax()
p.argmax(axis=1)
mymodel.input_data(dg.trainingfeats[3], dg.traininglbls[3])
p = mymodel.pred()
p
p.argmax(axis=1)
p.argmax(axis=1) == 3
np.sum(p.argmax(axis=1) == 3) / p.shape[0]
p.argmax(axis=1)
p.argsort()[-2:]