Exemplo n.º 1
0
    def createNewFDVT(self):
        fn = QtGui.QFileDialog.getOpenFileName(self, "Select FDVT", '.',
                                               '*.csv')
        anno = A.Annotation()
        anno.loadFromFile(fn[0])
        # filterTuples = anno.extractAllFilterTuples()

        annotationSelector = SD.AnnotationSelector()
        annotationSelector.setAnnotationFile(fn[0])
        OD.OverlayDialogWidgetBase.getUserInput(self, annotationSelector)

        # annotationFilters = AS.AnnotationSelecter.getAnnotationSelection(self,
        #                                                                  anno)

        annotationSelection = annotationSelector.getUserSelection()
        annotationFilters = []
        colors = []
        for a, b, c in annotationSelection:
            annotationFilters += [A.AnnotationFilter(None, [a], [b])]
            colors += [c]

        filteredAnno = anno.filterFrameListMultiple(annotationFilters,
                                                    exactMatch=False)

        import tempfile
        tmpDir = tempfile.mkdtemp()

        fdvt = FDV.FrameDataVisualizationTreeBehaviour(tmpDir)
        fdvt.importAnnotation(filteredAnno, annoFilters=annotationFilters)

        self.addFDVT(fdvt, colors)

        print annotationFilters
    def classify(self):
        """
        Applies the classifier on all data
        :return:
        """
        print("classifying!")
        if len(self.videoListRel) == 1:
            progressSteps = VE.videoExplorer.retrieveVideoLength(
                self.rel2absFile(self.videoListRel[0]), 100000)
            self.fdvt = FDV.FrameDataVisualizationTreeBehaviour(
                os.path.join(self.rootFolder, 'viz', 'color-diff'))
            self.fdvt.meta['singleFileMode'] = True
        else:
            progressSteps = len(self.videoListRel)
            self.fdvt = FDV.FrameDataVisualizationTreeBehaviour(
                os.path.join(self.rootFolder, 'viz', 'color-diff'))
            self.fdvt.meta['singleFileMode'] = False

        self.setStatus("classifying...", progressSteps)

        filters = []

        # filt = A.AnnotationFilter(annotators=["simpleFlyShowCase"],
        #                           behaviours=['negative'],
        #                           vials=self.annotationFilters[0].vials)
        # self.fdvt.addNewClass(filt)
        # filters += [filt]

        for af in self.annotationFilters:
            filt = A.AnnotationFilter(annotators=["SimpleHistogramPlugin"],
                                      behaviours=af.behaviours,
                                      vials=af.vials)
            self.fdvt.addNewClass(filt)
            filters += [filt]

        for i, videoPathRel in enumerate(self.videoListRel):
            feat = np.hstack(
                (np.load(self.generateColorFeatureSavePath(videoPathRel)),
                 np.load(self.generatediffImgFeatureSavePath(videoPathRel))))
            dv = []  # deltaVector
            for k in range(0, feat.shape[0], 100):
                f = feat[k:k + 100]
                prediction = self.classifier.predict(f)
                for i, p in enumerate(prediction):
                    # p-1 because tehre is no negative class!!!
                    dv += [
                        self.fdvt.getDeltaValue(videoPathRel, k + i,
                                                filters[int(p - 1)])
                    ]

                if len(self.videoListRel) == 1:
                    self.incrementStatus(100)

            self.fdvt.insertDeltaVector(dv)

            if len(self.videoListRel) > 1:
                self.incrementStatus()

        self.fdvt.save()
Exemplo n.º 3
0
    def addAnnotation(self, annotation, key, addAllAtOnce=True):
        """
        adds an annotation to a scene
        """
        cfg.log.info("beginning")
        if self.vialNo is None:
            filt = Annotation.AnnotationFilter([0], self.annotator, 
                                                        self.behaviourName)
        else:
            filt = Annotation.AnnotationFilter(self.vialNo, self.annotator, 
                                                        self.behaviourName)

        self.annotationDict[key] = annotation.filterFrameList(filt, exactMatch=False)

        cfg.log.info("end")
        
        return
Exemplo n.º 4
0
    def prepareAnnotationFilters(self):
        self.annotations = []
        self.annotations += [[\
                Annotation.AnnotationFilter([self.vial],["peter"],["falling"]),
                Annotation.AnnotationFilter([self.vial],["peter"],["dropping"])\
                            ]]

        self.annotations += [[\
               Annotation.AnnotationFilter([self.vial],["peter"],["struggling"])
                             ]]

        self.annoIdces = []
        for i in range(len(self.annotations)):
            self.annoIdces += [[]]
            for filt in self.annotations[i]:
                print filt
                self.annoIdces[i] += [
                    self.queryFDVT.getAnnotationFilterCode(filt)
                ]

        self.annoIdces.insert(0, [0])
Exemplo n.º 5
0
    def classify(self):
        """
        Applies the classifier on all data
        :return:
        """
        print("classifying!")

        self.setStatus("classifying..", len(self.posListRel))

        filters = []
        self.fdvt = FDV.FrameDataVisualizationTreeBehaviour()
        self.fdvt.meta['singleFileMode'] = False

        filt = A.AnnotationFilter(annotators=["simpleFlyShowCase"],
                                  behaviours=['negative'],
                                  vials=self.annotationFilters[0].vials)
        self.fdvt.addNewClass(filt)
        filters += [filt]

        for af in self.annotationFilters:
            filt = A.AnnotationFilter(annotators=["simpleFlyShowCase"],
                                      behaviours=af.behaviours,
                                      vials=af.vials)
            self.fdvt.addNewClass(filt)
            filters += [filt]


        for i, posPath in enumerate(self.posListRel):
            feat = np.load(self.generateFeatureSavePath(posPath))
            predictions = self.classifier.predict(feat)
            dv = []                 # deltaVector
            for k, p in enumerate(predictions):
                dv += [self.fdvt.getDeltaValue(posPath, k, filters[int(p)])]

            self.fdvt.insertDeltaVector(dv)
            self.incrementStatus()

        self.fdvt.save("/media/peter/Seagate Backup Plus Drive/tmp/stackFdvt.npy")
    def setAnnotation(self, anno):
        self.anno = anno
        self.filterTuples = anno.extractAllFilterTuples()

        self.AnnotationFilterCheckboxes = []
        for af in self.filterTuples:
            alw = AnnotationFilterCheckbox()
            annoFilter = A.AnnotationFilter(vials=None,
                                            annotators=[af[0]],
                                            behaviours=[af[1]])
            alw.setAnnotationFilter(annoFilter)
            self.AnnotationFilterCheckboxes += [alw]

            self.annotationLayout.addWidget(alw)
    def classify(self):
        """
        Applies the classifier on all data
        :return:
        """
        print("classifying!")
        if len(self.videoListRel) == 1:
            progressSteps = VE.videoExplorer.retrieveVideoLength(
                self.rel2absFile(self.videoListRel[0]), 100000)
            # self.fdvt = FDV.FrameDataVisualizationTreeBehaviour()
            # self.fdvt.meta['singleFileMode'] = True
        else:
            progressSteps = len(self.videoListRel)
            # self.fdvt = FDV.FrameDataVisualizationTreeBehaviour()
            # self.fdvt.meta['singleFileMode'] = False

        self.setStatus("classifying...", progressSteps)

        filters = []

        # filt = A.AnnotationFilter(annotators=["simpleFlyShowCase"],
        #                           behaviours=['negative'],
        #                           vials=self.annotationFilters[0].vials)
        # self.fdvt.addNewClass(filt)
        # filters += [filt]

        clfy_res = []

        for af in self.annotationFilters:
            filt = A.AnnotationFilter(annotators=["SimpleHistogramPlugin"],
                                      behaviours=af.behaviours,
                                      vials=af.vials)
            # self.fdvt.addNewClass(filt)
            filters += [filt]

            clfy_res += [{'frames': [], 'meta': {}}]

        for i, videoPathRel in enumerate(self.videoListRel):
            feat = np.load(self.generateFeatureSavePath(videoPathRel))
            dv = []  # deltaVector
            for k in range(0, feat.shape[0], 100):
                f = feat[k:k + 100]
                prediction = self.classifier.predict(f)
                for j, p in enumerate(prediction):
                    # p-1 because tehre is no negative class!!!
                    # dv += [self.fdvt.getDeltaValue(videoPathRel, k + j,
                    #                            filters[int(p-1)])]

                    # UPDATE ANNOTATIONS
                    clfy_res[p]['frames'] += [k + j]
                    clfy_res[p]['meta'][k + j] = {
                        "confidence": 1,
                        "boundingBox": [None, None, None, None]
                    }

                if len(self.videoListRel) == 1:
                    self.incrementStatus(100)

            # SAVE RESULT IN ANNOTATIONS
            resAnno = A.Annotation(frameNo=feat.shape[0])
            for i, af in enumerate(self.annotationFilters):
                annotator = af.annotators[0]
                label = af.behaviours[0]

                if clfy_res[i]['frames']:
                    resAnno.addAnnotation(vial=None,
                                          frames=clfy_res[i]['frames'],
                                          annotator='SimpleHistogramPlugin',
                                          behaviour=label,
                                          metadata=clfy_res[i]['meta'])

            # self.fdvt.insertDeltaVector(dv)

            resAnno.saveToFile(
                self.generateFeatureSavePath(videoPathRel) + 'hist.csv')

            if len(self.videoListRel) > 1:
                self.incrementStatus()