-
Notifications
You must be signed in to change notification settings - Fork 1
/
GUILayer2.py
1641 lines (1436 loc) · 73.7 KB
/
GUILayer2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
__author__ = 'Anochjhn Iruthayam'
import sys
from PyQt4 import QtCore, QtGui
from BatWindow import Ui_BatWindow
import EventExtraction, os, getFunctions, time
import h5py, re
import ClassifierThirdStage, ClassifierSecondStage, HDF5Handler, cv2, ClassifierFirstStage, ClassifierConnected
import numpy as np
def toTime(timePixel):
imageLength = 5000.0
return (1000.0/imageLength)*timePixel
def tokFreq(freqPixel):
imageWidth = 1025.0
return (250.0/imageWidth)*(imageWidth-freqPixel)
class GenerateSpecThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def setup(self,SoundFileList, SearchDirectory, SaveDirectory, channel, SampleRate):
self.SearchDirectory = SearchDirectory
self.SaveDirectory = SaveDirectory
self.channel = channel
self.SampleRate = SampleRate
self.SoundFileList = SoundFileList
def __del__(self):
self.wait()
def run(self):
for soundfile in self.SoundFileList:
EventExtraction.createSpectrogram(soundfile, self.SearchDirectory, self.SaveDirectory, self.channel, self.SampleRate)
self.emit(QtCore.SIGNAL("progGenSpec()"))
class AnalyzeThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def setup(self,OutputDirectory, sampleList, recordedAt, projectName, InputDirectory):
self.OutputDirectory = OutputDirectory
self.sampleList = sampleList
self.recordedAt = recordedAt
self.projectName = projectName
self.InputDirectory = InputDirectory
def __del__(self):
self.wait()
def run(self):
for eventFile in self.sampleList:
EventExtraction.findEvent(self.OutputDirectory, eventFile, self.recordedAt, self.projectName, self.InputDirectory)
self.emit(QtCore.SIGNAL("analyzeSpec()"))
class ClassifierThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def setup(self, classifier, databasePath, iteration, learningrate, momentum, toFile):
self.classifier = classifier
self.databasePath = databasePath
self.iteration = iteration
self.learningrate = learningrate
self.momentum = momentum
self.toFile = toFile
def __del__(self):
self.wait()
def run(self):
self.emit(QtCore.SIGNAL("clasProg()"))
self.classifier.initClasissifer(self.databasePath)
self.emit(QtCore.SIGNAL("train()"))
self.classifier.goClassifer(self.iteration, self.learningrate, self.momentum, self.toFile)
class ClassifierRunThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def setup(self, function, databasePath):
self.function = function
self.databasePath = databasePath
def __del__(self):
self.wait()
def run(self):
self.emit(QtCore.SIGNAL("clasProg()"))
self.function.initClasissifer(self.databasePath)
self.emit(QtCore.SIGNAL("classRun()"))
ConfusionMatrix = self.function.runClassifier()
#ConfusionMatrix = self.function.ConfusionMatrix
self.emit(QtCore.SIGNAL("output(PyQt_PyObject)"), ConfusionMatrix)
class ClassifierConnectedRunThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def setup(self, function, databasePath):
self.function = function
self.databasePath = databasePath
def __del__(self):
self.wait()
def run(self):
self.emit(QtCore.SIGNAL("clasProg()"))
self.function.initClasissifer(self.databasePath)
self.emit(QtCore.SIGNAL("classFirst()"))
self.function.runFirstStageClassifier()
self.emit(QtCore.SIGNAL("classSecond()"))
self.function.runSecondStageClassifier()
self.emit(QtCore.SIGNAL("classThird()"))
self.function.runThirdStageClassifier()
ConfusionMatrix = self.function.ConfusionMatrix
self.emit(QtCore.SIGNAL("output(PyQt_PyObject)"), np.array(ConfusionMatrix))
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_BatWindow()
self.ui.setupUi(self)
self.ui.frame_BatButtons.hide()
self.pathEventList = []
self.threadPool = []
self.setFullScreen = 0
### FIXES WINDOWS TASKBAR HANDLER, WHICH SHOWS THE CORRECT ICON ###
import ctypes
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
QtCore.QObject.connect(self.ui.pushButton_SetInputDirectory, QtCore.SIGNAL("clicked()"), self.setInputDirectory)
QtCore.QObject.connect(self.ui.pushButton_SetOutputDirectory, QtCore.SIGNAL("clicked()"), self.setOutputDirectory)
QtCore.QObject.connect(self.ui.button_start, QtCore.SIGNAL("clicked()"), self.run_analyser)
QtCore.QObject.connect(self.ui.pushButton_createSpectrogram, QtCore.SIGNAL("clicked()"), self.create_spectrogram)
QtCore.QObject.connect(self.ui.button_loaddatabase, QtCore.SIGNAL("clicked()"), self.file_dialog)
QtCore.QObject.connect(self.ui.button_EptesicusSerotinus, QtCore.SIGNAL("clicked()"), self.getValueEptesicusSerotinus)
QtCore.QObject.connect(self.ui.button_PipistrellusPygmaeus, QtCore.SIGNAL("clicked()"), self.getValuePipistrellusPygmaeus)
QtCore.QObject.connect(self.ui.button_MyotisDaubentonii, QtCore.SIGNAL("clicked()"), self.getValueMyotisDaubentonii)
QtCore.QObject.connect(self.ui.button_MyotisDasycneme, QtCore.SIGNAL("clicked()"), self.getValueMyotisDasycneme)
QtCore.QObject.connect(self.ui.button_pipistrellusNathusii, QtCore.SIGNAL("clicked()"), self.getValuePipistrellusNathusii)
QtCore.QObject.connect(self.ui.button_NyctalusNoctula, QtCore.SIGNAL("clicked()"), self.getValueNyctalusNoctula)
QtCore.QObject.connect(self.ui.button_noise, QtCore.SIGNAL("clicked()"), self.getValueNoise)
QtCore.QObject.connect(self.ui.button_OtherSpecies, QtCore.SIGNAL("clicked()"), self.getValueOtherSpecies)
QtCore.QObject.connect(self.ui.button_SomethingElse, QtCore.SIGNAL("clicked()"), self.getValueSomethingElse)
QtCore.QObject.connect(self.ui.checkBox_scaledZoom, QtCore.SIGNAL("clicked()"), self.ScaledZoom)
QtCore.QObject.connect(self.ui.button_ShowFullSpectrogram, QtCore.SIGNAL("pressed()"), self.ShowFullSpectrogramPressed)
QtCore.QObject.connect(self.ui.button_ShowFullSpectrogram, QtCore.SIGNAL("released()"), self.resetRelease)
QtCore.QObject.connect(self.ui.button_ShowMarkedSpectrogram, QtCore.SIGNAL("pressed()"), self.ShowMarkedSpectrogramPressed)
QtCore.QObject.connect(self.ui.button_ShowMarkedSpectrogram, QtCore.SIGNAL("released()"), self.resetRelease)
QtCore.QObject.connect(self.ui.button_undo, QtCore.SIGNAL("clicked()"), self.undoLastEvent)
QtCore.QObject.connect(self.ui.button_save, QtCore.SIGNAL("clicked()"), self.saveCurrentProgress)
QtCore.QObject.connect(self.ui.button_loaddatabase_browser, QtCore.SIGNAL("clicked()"), self.countSpecies)
QtCore.QObject.connect(self.ui.button_browser_Next, QtCore.SIGNAL("clicked()"), self.buttonNextHandler)
QtCore.QObject.connect(self.ui.button_browser_previous, QtCore.SIGNAL("clicked()"), self.buttonPreviousHandler)
QtCore.QObject.connect(self.ui.comboBox_SelectSpecies, QtCore.SIGNAL("activated(QString)"), self.browserComboxSelectSpeciesHandler)
#Connect train classifier buttons
QtCore.QObject.connect(self.ui.button_classifierFirstStage_train, QtCore.SIGNAL("clicked()"), self.trainFirstStageClassifier)
QtCore.QObject.connect(self.ui.button_classifierSecondStage_train, QtCore.SIGNAL("clicked()"), self.trainSecondStageClassifier)
QtCore.QObject.connect(self.ui.button_classifierThirdStage_train, QtCore.SIGNAL("clicked()"), self.trainThirdStageClassifier)
#Connect run classifier buttons
QtCore.QObject.connect(self.ui.button_classifierFirstStage_run, QtCore.SIGNAL("clicked()"), self.runFirstStageClassifier)
QtCore.QObject.connect(self.ui.button_classifierSecondStage_run, QtCore.SIGNAL("clicked()"), self.runSecondStageClassifier)
QtCore.QObject.connect(self.ui.button_classifierThirdStage_run, QtCore.SIGNAL("clicked()"), self.runThirdStageClassifier)
QtCore.QObject.connect(self.ui.button_classiferConnected_run, QtCore.SIGNAL("clicked()"), self.runConnectedClassifiers)
QtCore.QObject.connect(self.ui.button_classifier_database, QtCore.SIGNAL("clicked()"), self.file_dialog_classifier)
QtCore.QObject.connect(self.ui.button_loaddatabaseReconstruct, QtCore.SIGNAL("clicked()"), self.file_dialog2)
QtCore.QObject.connect(self.ui.pushButton_SetOutputDirectory_Reconstruct, QtCore.SIGNAL("clicked()"), self.setOutputDirectory)
QtCore.QObject.connect(self.ui.button_Recontructor, QtCore.SIGNAL("clicked()"), self.imageRecontructor)
self.ui.progressBar_classifier.hide()
### GENERATE SPECTROGRAM THREAD ###
self.specGenThread = GenerateSpecThread()
self.connect(self.specGenThread, QtCore.SIGNAL("started()"), self.update_SpecProgStarted)
self.connect(self.specGenThread, QtCore.SIGNAL("finished()"), self.update_SpecProgFinished)
self.connect(self.specGenThread, QtCore.SIGNAL("progGenSpec()"), self.update_SpecProg)
#### ANALYZE THREAD ###
self.analyzeThread = AnalyzeThread()
self.connect(self.analyzeThread, QtCore.SIGNAL("started()"), self.update_analyzeProgStarted)
self.connect(self.analyzeThread, QtCore.SIGNAL("finished()"), self.update_analyzeProgFinished)
self.connect(self.analyzeThread, QtCore.SIGNAL("analyzeSpec()"), self.update_analyzeProg)
### CLASSIFIER THREAD ###
self.classifierThread = ClassifierThread()
self.connect(self.classifierThread, QtCore.SIGNAL("started()"), self.update_disableAllButtons)
self.connect(self.classifierThread, QtCore.SIGNAL("finished()"), self.update_classifierProgFinished)
self.connect(self.classifierThread, QtCore.SIGNAL("clasProg()"), self.update_classifierProgStarted)
self.connect(self.classifierThread, QtCore.SIGNAL("train()"), self.update_classfierInfo)
### CLASSIFIER RUN THREAD ###
self.classifierRunThreadFSC = ClassifierRunThread()
self.connect(self.classifierRunThreadFSC, QtCore.SIGNAL("finished()"), self.update_classifierRunProg)
self.connect(self.classifierRunThreadFSC, QtCore.SIGNAL("started()"), self.update_disableAllButtons)
self.connect(self.classifierRunThreadFSC, QtCore.SIGNAL("clasProg()"), self.update_classifierProgStarted)
self.connect(self.classifierRunThreadFSC, QtCore.SIGNAL("classRun()"), self.update_classfierRunInfo)
self.connect(self.classifierRunThreadFSC, QtCore.SIGNAL("output(PyQt_PyObject)"), self.tableConfusionMatrixHandlerFSC)
self.classifierRunThreadSSC = ClassifierRunThread()
self.connect(self.classifierRunThreadSSC, QtCore.SIGNAL("finished()"), self.update_classifierRunProg)
self.connect(self.classifierRunThreadSSC, QtCore.SIGNAL("started()"), self.update_disableAllButtons)
self.connect(self.classifierRunThreadSSC, QtCore.SIGNAL("clasProg()"), self.update_classifierProgStarted)
self.connect(self.classifierRunThreadSSC, QtCore.SIGNAL("classRun()"), self.update_classfierRunInfo)
self.connect(self.classifierRunThreadSSC, QtCore.SIGNAL("output(PyQt_PyObject)"), self.tableConfusionMatrixHandlerSSC)
self.classifierRunThreadTSC = ClassifierRunThread()
self.connect(self.classifierRunThreadTSC, QtCore.SIGNAL("finished()"), self.update_classifierRunProg)
self.connect(self.classifierRunThreadTSC, QtCore.SIGNAL("started()"), self.update_disableAllButtons)
self.connect(self.classifierRunThreadTSC, QtCore.SIGNAL("clasProg()"), self.update_classifierProgStarted)
self.connect(self.classifierRunThreadTSC, QtCore.SIGNAL("classRun()"), self.update_classfierRunInfo)
self.connect(self.classifierRunThreadTSC, QtCore.SIGNAL("output(PyQt_PyObject)"), self.tableConfusionMatrixHandlerTSC)
self.classifierConnectedRunThread = ClassifierConnectedRunThread()
self.connect(self.classifierConnectedRunThread, QtCore.SIGNAL("finished()"), self.update_classifierRunProg)
self.connect(self.classifierConnectedRunThread, QtCore.SIGNAL("started()"), self.update_disableAllButtons)
self.connect(self.classifierConnectedRunThread, QtCore.SIGNAL("clasProg()"), self.update_classifierProgStarted)
self.connect(self.classifierConnectedRunThread, QtCore.SIGNAL("classFirst()"), self.update_first)
self.connect(self.classifierConnectedRunThread, QtCore.SIGNAL("classSecond()"), self.update_second)
self.connect(self.classifierConnectedRunThread, QtCore.SIGNAL("classThird()"), self.update_third)
self.connect(self.classifierConnectedRunThread, QtCore.SIGNAL("output(PyQt_PyObject)"), self.tableConfusionMatrixHandlerTSC)
#QtCore.QObject.connect(self.ui.progressBar)
self.HDFFile = h5py
self.EventSize = 0
self.currentEvent = 0
self.previousEvent = 0
self.ProcessCount = 0
self.MultiCount = 0
self.SpecProgressCount = 0
self.analyzeProgessCount = 0
self.day = []
self.month = []
self.year = []
self.file = []
self.pathcorr = []
self.eventno = []
self.SoundFileList = []
self.OutputDirectory = "C:\Users\Anoch\Documents\PreOutput"#"/home/anoch/Documents/BatSamplesOutput"
self.InputDirectory = "C:\Users\Anoch\Documents\PreInput"#"/home/anoch/Documents/BatSamplesInput"
self.DatabasePath = "C:\Users\Anoch\Documents\BatOutput\BatData.hdf5"#"/home/anoch/Documents/BatOutput/BatData.hdf5"
self.ui.label_classifier_databaseDirectory.setText(self.DatabasePath)
self.ui.label_outputDirectory.setText(self.OutputDirectory)
self.ui.label_inputDirectory.setText(self.InputDirectory)
self.third_stage_classifier = ClassifierThirdStage.Classifier()
self.second_stage_classifier = ClassifierSecondStage.Classifier()
self.first_stage_classifier = ClassifierFirstStage.BinaryClassifier()
self.second_stage_classifier = ClassifierSecondStage.Classifier()
self.third_stage_classifier = ClassifierThirdStage.Classifier()
self.first_stage_classifier_run = ClassifierFirstStage.BinaryClassifier()
self.second_stage_classifier_run = ClassifierSecondStage.Classifier()
self.third_stage_classifier_run = ClassifierThirdStage.Classifier()
self.connected_classifier_run = ClassifierConnected.ClassifierConnected()
self.ui.button_OtherSpecies.hide()
if self.ui.checkBox_scaledZoom.isChecked():
self.ZoomInParameter = 1
else:
self.ZoomInParameter = 0
def labelBat(self, ID):
data = self.HDFFile[str(self.pathcorr[self.currentEvent])]
data.attrs['BatID'] = ID
if self.scanForNextEvent():
self.updateEventInfomation()
def labelCall(self, ID):
data = self.HDFFile[str(self.pathcorr[self.currentEvent])]
data.attrs['Call Type'] = ID
if self.scanForNextEvent():
self.updateEventInfomation()
def getValueEptesicusSerotinus(self):
self.labelBat(1)
def getValuePipistrellusPygmaeus(self):
self.labelBat(2)
def getValueMyotisDaubentonii(self):
self.labelBat(3)
def getValueMyotisDasycneme(self):
self.labelBat(4)
def getValuePipistrellusNathusii(self):
self.labelBat(5)
def getValueNyctalusNoctula(self):
self.labelBat(6)
def getValueOtherSpecies(self):
self.labelBat(7)
def getValueNoise(self):
self.labelBat(8)
def getValueSomethingElse(self):
self.labelBat(9)
def getValueEptesicusSerotinusMulti(self):
self.labelBat(10)
def getValuePipistrellusPygmaeusMulti(self):
self.labelBat(11)
def getValueMyotisDaubentoniiMulti(self):
self.labelBat(12)
def getValueMyotisDasycnemeMulti(self):
self.labelBat(13)
def getValuePipistrellusNathusiiMulti(self):
self.labelBat(14)
def getValueNyctalusNoctulaMulti(self):
self.labelBat(15)
def getCallEcholocation(self):
self.labelCall(1)
def getCallSocialCall(self):
self.labelCall(2)
def getCallForaging(self):
self.labelCall(3)
def getCallEcholocationSocialCall(self):
self.labelCall(4)
def getCallSomethingElse(self):
self.labelCall(5)
def saveCurrentProgress(self):
self.HDFFile.flush()
def saveEventPath(self,name):
self.pathEventList.append(name)
def undoLastEvent(self):
if not self.currentEvent == 0:
self.currentEvent = self.previousEvent
self.updateEventInfomation()
def ShowFullSpectrogramPressed(self):
FullSpecImg = self.OutputDirectory + "/Spectrogram/" + self.file[self.currentEvent] + ".png"
eventImage = QtGui.QPixmap(FullSpecImg)
scaledEventImage = eventImage.scaled(self.ui.label_imageshow.size(), QtCore.Qt.KeepAspectRatio)
self.ui.label_imageshow.setPixmap(scaledEventImage)
#if self.ZoomInParameter == 1:
# scaledEventImage = eventImage.scaled(self.ui.label_imageshow.size(), QtCore.Qt.KeepAspectRatio)
# self.ui.label_imageshow.setPixmap(scaledEventImage)
#else:
# self.ui.label_imageshow.setPixmap(eventImage)
def ShowMarkedSpectrogramPressed(self):
MarkedSpecImg = self.OutputDirectory + "/SpectrogramMarked/" + self.file[self.currentEvent] + "/SpectrogramAllMarked.png"
eventImage = QtGui.QPixmap(MarkedSpecImg)
scaledEventImage = eventImage.scaled(self.ui.label_imageshow.size(), QtCore.Qt.KeepAspectRatio)
self.ui.label_imageshow.setPixmap(scaledEventImage)
#if self.ZoomInParameter == 1:
# scaledEventImage = eventImage.scaled(self.ui.label_imageshow.size(), QtCore.Qt.KeepAspectRatio)
# self.ui.label_imageshow.setPixmap(scaledEventImage)
#else:
# self.ui.label_imageshow.setPixmap(eventImage)
def resetRelease(self):
self.updateEventInfomation()
def ScaledZoom(self):
if self.ui.checkBox_scaledZoom.isChecked():
self.ZoomInParameter = 1
self.updateEventInfomation()
else:
self.ZoomInParameter = 0
self.updateEventInfomation()
# Overload function
def keyPressEvent(self, QKeyEvent):
# if this batbuttons are visible, means we have loaded the data
if type(QKeyEvent) == QtGui.QKeyEvent:
if QKeyEvent.key() == 16777216: # Esc button
if self.setFullScreen == 0:
self.showFullScreen()
self.setFullScreen = 1
else:
self.showNormal()
self.setFullScreen = 0
if self.ui.tabWidget.currentIndex() == 1:
#print QKeyEvent.key()
#Check if the label species tab is open
if self.ui.frame_BatButtons.isVisible():
# following numbers are ASCII for 1, 2, 3, 4, 5, 6 and 7
######SINGLE CALL KEY BINDINGS##########
if QKeyEvent.key() == 49: # 1
self.getValueEptesicusSerotinus()
if QKeyEvent.key() == 50: # 2
self.getValuePipistrellusPygmaeus()
if QKeyEvent.key() == 51: # 3
self.getValueMyotisDaubentonii()
if QKeyEvent.key() == 52: # 4
self.getValueMyotisDasycneme()
if QKeyEvent.key() == 53: # 5
self.getValuePipistrellusNathusii()
if QKeyEvent.key() == 54: # 6
self.getValueNyctalusNoctula()
if QKeyEvent.key() == 55: # 7
self.getValueOtherSpecies()
if QKeyEvent.key() == 56: # 8
self.getValueNoise()
if QKeyEvent.key() == 57: # 9
self.getValueSomethingElse()
######MULTI CALLS KEY BINDINGS##########
if QKeyEvent.key() == 81: # q
self.getValueEptesicusSerotinusMulti()
if QKeyEvent.key() == 87: # w
self.getValuePipistrellusPygmaeusMulti()
if QKeyEvent.key() == 69: # e
self.getValueMyotisDaubentoniiMulti()
if QKeyEvent.key() == 82: # r
self.getValueMyotisDasycnemeMulti()
if QKeyEvent.key() == 84: # t
self.getValuePipistrellusNathusiiMulti()
if QKeyEvent.key() == 89: # y
self.getValueNyctalusNoctulaMulti()
####OTHER OPTIONS KEY BINDINGS#############
if QKeyEvent.key() == 90: # z
if self.ui.checkBox_scaledZoom.isChecked():
self.ui.checkBox_scaledZoom.setChecked(False)
self.ScaledZoom()
else:
self.ui.checkBox_scaledZoom.setChecked(True)
self.ScaledZoom()
if QKeyEvent.key() == 83: # s
self.ShowFullSpectrogramPressed()
if QKeyEvent.key() == 77: # m
self.ShowMarkedSpectrogramPressed()
if QKeyEvent.key() == 85:
self.undoLastEvent()
# Check if lavel action tab is open
if self.ui.tabWidget.currentIndex() == 2:
if QKeyEvent.key() == 49:
self.getCallEcholocation()
if QKeyEvent.key() == 50:
self.getCallSocialCall()
if QKeyEvent.key() == 51:
self.getCallForaging()
if QKeyEvent.key() == 52:
self.getCallEcholocationSocialCall()
if QKeyEvent.key() == 53:
self.getCallSomethingElse()
# Overload function
def keyReleaseEvent(self, QKeyEvent):
if self.ui.tabWidget.currentIndex() == 1:
if self.ui.frame_BatButtons.isVisible():
if type(QKeyEvent) == QtGui.QKeyEvent:
if QKeyEvent.key() == 83:
self.resetRelease()
if QKeyEvent.key() == 77:
self.resetRelease()
def imageRecontructor(self):
if self.ui.tabWidget.currentIndex() == 3:
day, month, year, file, eventno, pathcorr = self.getHDFInformationRecontructImage(self.pathEventList, 1)
max = len(pathcorr)
for i in range(0, max):
Imgdata = self.HDFFile[pathcorr[i]]
image = HDF5Handler.imageRecontructFromHDF5(Imgdata)
cv2.imwrite(self.OutputDirectory + "/Spectrogram/" + file[i] + ".png", image)
def update_classifierProgStarted(self):
self.ui.textEdit_classifier_overview.setText("Initilazing database")
self.ui.progressBar_classifier.show()
def update_classifierProgFinished(self):
self.ui.button_classifier_database.setEnabled(True)
self.ui.button_classiferConnected_run.setEnabled(True)
self.ui.button_classifierFirstStage_train.setEnabled(True)
self.ui.button_classifierFirstStage_run.setEnabled(True)
self.ui.button_classifierSecondStage_train.setEnabled(True)
self.ui.button_classifierSecondStage_run.setEnabled(True)
self.ui.button_classifierThirdStage_train.setEnabled(True)
self.ui.button_classifierThirdStage_run.setEnabled(True)
self.ui.textEdit_classifier_overview.setText("Training network... Done")
self.ui.progressBar_classifier.hide()
def update_classifierRunProg(self):
self.ui.button_classifier_database.setEnabled(True)
self.ui.button_classiferConnected_run.setEnabled(True)
self.ui.button_classifierFirstStage_train.setEnabled(True)
self.ui.button_classifierFirstStage_run.setEnabled(True)
self.ui.button_classifierSecondStage_train.setEnabled(True)
self.ui.button_classifierSecondStage_run.setEnabled(True)
self.ui.button_classifierThirdStage_train.setEnabled(True)
self.ui.button_classifierThirdStage_run.setEnabled(True)
self.ui.textEdit_classifier_overview.setText("Done!")
self.ui.progressBar_classifier.hide()
def update_classfierInfo(self):
self.ui.textEdit_classifier_overview.setText("Training network...")
def update_classfierRunInfo(self):
self.ui.textEdit_classifier_overview.setText("Running network...")
def update_first(self):
self.ui.textEdit_classifier_overview.setText("Running first stage network...")
def update_second(self):
self.ui.textEdit_classifier_overview.setText("Running second stage network...")
def update_third(self):
self.ui.textEdit_classifier_overview.setText("Running third stage network...")
def update_disableAllButtons(self):
self.ui.button_classifier_database.setEnabled(False)
self.ui.button_classiferConnected_run.setEnabled(False)
self.ui.button_classifierFirstStage_train.setEnabled(False)
self.ui.button_classifierFirstStage_run.setEnabled(False)
self.ui.button_classifierSecondStage_train.setEnabled(False)
self.ui.button_classifierSecondStage_run.setEnabled(False)
self.ui.button_classifierThirdStage_train.setEnabled(False)
self.ui.button_classifierThirdStage_run.setEnabled(False)
def trainFirstStageClassifier(self):
self.classifierThread.setup(self.first_stage_classifier, self.DatabasePath, 0, 0.001,0.01, False)
self.classifierThread.start()
#self.first_stage_classifier.initClasissifer(self.DatabasePath)
#self.ui.textEdit_classifier_overview.setText("Training network...")
#self.first_stage_classifier.goClassifer(0, 0.001, 0.1, False)
#self.ui.textEdit_classifier_overview.setText("Training network... Done")
## Testing Purpose ##
"""
learningRate = [0.001, 0.001, 0.001, 0.01, 0.01, 0.01, 0.1, 0.1, 0.1]
momentum = [0.001, 0.01, 0.1, 0.001, 0.01, 0.1, 0.001, 0.01, 0.1]
for setting in range (0, len(learningRate)):
for i in range (0, 5):
self.first_stage_classifier.goClassifer(i, learningRate[setting], momentum[setting], True)
"""
def trainSecondStageClassifier(self):
self.classifierThread.setup(self.second_stage_classifier, self.DatabasePath, 0,0.001,0.001,False)
self.classifierThread.start()
#self.ui.textEdit_classifier_overview.setText("Initilazing database")
#self.second_stage_classifier.initClasissifer(self.DatabasePath)
#self.ui.textEdit_classifier_overview.setText("Training network...")
#self.second_stage_classifier.goClassifer(0,0.001,0.001,False)
#self.ui.textEdit_classifier_overview.setText("Training network... Done")
"""
learningRate = [0.001, 0.001, 0.001, 0.01, 0.01, 0.01, 0.1, 0.1, 0.1]
momentum = [0.001, 0.01, 0.1, 0.001, 0.01, 0.1, 0.001, 0.01, 0.1]
for setting in range (0, len(learningRate)):
for i in range(0,5):
self.second_stage_classifier.goClassifer(i, learningRate[setting], momentum[setting], True)
"""
def trainThirdStageClassifier(self):
self.classifierThread.setup(self.third_stage_classifier, self.DatabasePath, 0, 0.001, 0.010, False)
self.classifierThread.start()
#self.ui.textEdit_classifier_overview.setText("Initilazing database")
#self.third_stage_classifier.initClasissifer(self.DatabasePath)
#self.ui.textEdit_classifier_overview.setText("Training network...")
#self.third_stage_classifier.goClassifer(0, 0.001, 0.010, False)
#self.ui.textEdit_classifier_overview.setText("Training network... Done")
"""
learningRate = [0.001, 0.001, 0.001, 0.01, 0.01, 0.01, 0.1, 0.1, 0.1]
momentum = [0.001, 0.01, 0.1, 0.001, 0.01, 0.1, 0.001, 0.01, 0.1]
for setting in range (0, len(learningRate)):
for i in range(0,5):
self.third_stage_classifier.goClassifer(i, learningRate[setting], momentum[setting], True)
"""
def runFirstStageClassifier(self):
#self.ui.textEdit_classifier_overview.setText("Initilazing database")
#self.first_stage_classifier_run.initClasissifer(self.DatabasePath)
self.classifierRunThreadFSC.setup(self.first_stage_classifier_run, self.DatabasePath)
self.classifierRunThreadFSC.start()
#self.classifierRunThread.wait()
#ConfusionMatrix = self.first_stage_classifier_run.runClassifier()
#self.tableConfusionMatrixHandlerFSC(ConfusionMatrix)
def runSecondStageClassifier(self):
self.classifierRunThreadSSC.setup(self.second_stage_classifier_run, self.DatabasePath)
self.classifierRunThreadSSC.start()
#self.second_stage_classifier_run.initClasissifer(self.DatabasePath)
#ConfusionMatrix, BatTarget = self.second_stage_classifier_run.runClassifier()
#cursor = QtGui.QTextCursor(self.ui.textEdit_classifier_overview.document())
#cursor.insertText("Confusion Matrix\n" + str(ConfusionMatrix) + "\nTarget\n" + str(BatTarget))
#self.tableConfusionMatrixHandlerSSC(ConfusionMatrix)
def runThirdStageClassifier(self):
self.classifierRunThreadTSC.setup(self.third_stage_classifier_run, self.DatabasePath)
self.classifierRunThreadTSC.start()
#ConfusionMatrix, BatTarget = self.third_stage_classifier_run.runClassifier()
#cursor = QtGui.QTextCursor(self.ui.textEdit_classifier_overview.document())
#cursor.insertText("Confusion Matrix\n" + str(ConfusionMatrix) + "\nTarget\n" + str(BatTarget))
#self.tableConfusionMatrixHandlerTSC(ConfusionMatrix)
def runConnectedClassifiers(self):
self.classifierConnectedRunThread.setup(self.connected_classifier_run, self.DatabasePath)
self.classifierConnectedRunThread.start()
#self.connected_classifier_run.initClasissifer(self.DatabasePath)
#ConfusionMatrix, BatTarget = self.connected_classifier_run.runClassifiers()
#cursor = QtGui.QTextCursor(self.ui.textEdit_classifier_overview.document())
#cursor.insertText("Confusion Matrix\n" + str(ConfusionMatrix) + "\nTarget\n" + str(BatTarget))
#ConfusionMatrix = np.zeros((7,7))
#ConfusionMatrix = np.array(ConfusionMatrix, dtype=np.int64)
#count = 0
#for row in range(0,7):
# for colomn in range(0,7):
# ConfusionMatrix[row][colomn] = count
# count += 1
#self.tableConfusionMatrixHandlerTSC(ConfusionMatrix)
def tableConfusionMatrixHandlerTSC(self, ConfusionMatrix):
# SET UP Labels for the table
self.ui.tableWidget_ConfusionMatrix.clear()
font = QtGui.QFont()
font.setBold(True)
font.setItalic(True)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("EpSe")
self.ui.tableWidget_ConfusionMatrix.setItem(2,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("EpSe")
self.ui.tableWidget_ConfusionMatrix.setItem(1,2,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("PiPy")
self.ui.tableWidget_ConfusionMatrix.setItem(3,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("PiPy")
self.ui.tableWidget_ConfusionMatrix.setItem(1,3,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("MyDau")
self.ui.tableWidget_ConfusionMatrix.setItem(4,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("MyDau")
self.ui.tableWidget_ConfusionMatrix.setItem(1,4,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("PiNa")
self.ui.tableWidget_ConfusionMatrix.setItem(5,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("PiNa")
self.ui.tableWidget_ConfusionMatrix.setItem(1,5,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("NyNo")
self.ui.tableWidget_ConfusionMatrix.setItem(6,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("NyNo")
self.ui.tableWidget_ConfusionMatrix.setItem(1,6,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Noise")
self.ui.tableWidget_ConfusionMatrix.setItem(7,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Noise")
self.ui.tableWidget_ConfusionMatrix.setItem(1,7,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("SeEl")
self.ui.tableWidget_ConfusionMatrix.setItem(8,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("SeEl")
self.ui.tableWidget_ConfusionMatrix.setItem(1,8,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Target")
self.ui.tableWidget_ConfusionMatrix.setItem(1,9,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("BL [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,10,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("CCR [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,11,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Prec [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,12,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Reca [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,13,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Out")
self.ui.tableWidget_ConfusionMatrix.setItem(0,6,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("True")
self.ui.tableWidget_ConfusionMatrix.setItem(4,0,data)
stringMatrix = str(ConfusionMatrix)
print stringMatrix
target = [0,0,0,0,0,0,0]
RowMatrix = [0]
for row in range(0,7):
for colomn in range(0,7):
## WORK AROUND FOR BUG IN MILTIDIMENSION ARRAY
RowMatrix[0] = ConfusionMatrix[row]
target[row] += ConfusionMatrix[row][colomn]
data = QtGui.QTableWidgetItem(str(ConfusionMatrix[row][colomn]))
self.ui.tableWidget_ConfusionMatrix.setItem(row+2,colomn+2,data)
data = QtGui.QTableWidgetItem(str(target[row]))
self.ui.tableWidget_ConfusionMatrix.setItem(row+2,colomn+3,data)
largestIndex = np.argmax(target)
maxValue = target[largestIndex]
sumTarget = sum(target)
baseline = (float(maxValue)/float(sumTarget))*100
data = QtGui.QTableWidgetItem(str("%.2f" % baseline))
self.ui.tableWidget_ConfusionMatrix.setItem(2,10,data)
diagonalSum = 0
for diag in range(0,7):
diagonalSum += ConfusionMatrix[diag][diag]
CCR = (float(diagonalSum)/float(sumTarget))*100
data = QtGui.QTableWidgetItem(str("%.2f" % CCR))
self.ui.tableWidget_ConfusionMatrix.setItem(2,11,data)
classifierTarget = [0,0,0,0,0,0,0]
precision = [0,0,0,0,0,0,0]
for colomn in range(0,7):
for row in range(0,7):
classifierTarget[colomn] += ConfusionMatrix[row][colomn]
precision = (float(ConfusionMatrix[colomn][colomn])/float(classifierTarget[colomn]))*100
data = QtGui.QTableWidgetItem(str("%.2f" % precision))
self.ui.tableWidget_ConfusionMatrix.setItem(colomn+2,12,data)
for diag in range(0,7):
recall = (float(ConfusionMatrix[diag][diag])/target[diag])*100
data = QtGui.QTableWidgetItem(str("%.2f" % recall))
self.ui.tableWidget_ConfusionMatrix.setItem(diag+2,13,data)
def tableConfusionMatrixHandlerSSC(self, ConfusionMatrix):
# SET UP Labels for the table
self.ui.tableWidget_ConfusionMatrix.clear()
font = QtGui.QFont()
font.setBold(True)
font.setItalic(True)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Noise")
self.ui.tableWidget_ConfusionMatrix.setItem(2,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Noise")
self.ui.tableWidget_ConfusionMatrix.setItem(1,2,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Single")
self.ui.tableWidget_ConfusionMatrix.setItem(3,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Single")
self.ui.tableWidget_ConfusionMatrix.setItem(1,3,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Multi")
self.ui.tableWidget_ConfusionMatrix.setItem(4,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Multi")
self.ui.tableWidget_ConfusionMatrix.setItem(1,4,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("SoEl")
self.ui.tableWidget_ConfusionMatrix.setItem(5,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("SoEl")
self.ui.tableWidget_ConfusionMatrix.setItem(1,5,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Target")
self.ui.tableWidget_ConfusionMatrix.setItem(1,6,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("BL [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,7,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("CCR [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,8,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Prec [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,9,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Reca [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,10,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Out")
self.ui.tableWidget_ConfusionMatrix.setItem(0,6,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("True")
self.ui.tableWidget_ConfusionMatrix.setItem(4,0,data)
target = [0,0,0,0]
dimension = len(target)
for row in range(0,dimension):
for colomn in range(0,dimension):
target[row] += ConfusionMatrix[row][colomn]
data = QtGui.QTableWidgetItem(str(ConfusionMatrix[row][colomn]))
self.ui.tableWidget_ConfusionMatrix.setItem(row+2,colomn+2,data)
data = QtGui.QTableWidgetItem(str(target[row]))
self.ui.tableWidget_ConfusionMatrix.setItem(row+2,colomn+3,data)
# BASELINE
largestIndex = np.argmax(target)
maxValue = target[largestIndex]
sumTarget = sum(target)
baseline = (float(maxValue)/float(sumTarget))*100
data = QtGui.QTableWidgetItem(str("%.2f" % baseline))
self.ui.tableWidget_ConfusionMatrix.setItem(2,7,data)
# CCR
diagonalSum = 0
for diag in range(0,dimension):
diagonalSum += ConfusionMatrix[diag][diag]
CCR = (float(diagonalSum)/float(sumTarget))*100
data = QtGui.QTableWidgetItem(str("%.2f" % CCR))
self.ui.tableWidget_ConfusionMatrix.setItem(2,8,data)
classifierTarget = [0,0,0,0]
for colomn in range(0,dimension):
for row in range(0,dimension):
classifierTarget[colomn] += ConfusionMatrix[row][colomn]
precision = (float(ConfusionMatrix[colomn][colomn])/float(classifierTarget[colomn]))*100
data = QtGui.QTableWidgetItem(str("%.2f" % precision))
self.ui.tableWidget_ConfusionMatrix.setItem(colomn+2,9,data)
for diag in range(0,dimension):
recall = (float(ConfusionMatrix[diag][diag])/target[diag])*100
data = QtGui.QTableWidgetItem(str("%.2f" % recall))
self.ui.tableWidget_ConfusionMatrix.setItem(diag+2,10,data)
def tableConfusionMatrixHandlerFSC(self, ConfusionMatrix):
# SET UP Labels for the table
self.ui.tableWidget_ConfusionMatrix.clear()
font = QtGui.QFont()
font.setBold(True)
font.setItalic(True)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Bat")
self.ui.tableWidget_ConfusionMatrix.setItem(2,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Bat")
self.ui.tableWidget_ConfusionMatrix.setItem(1,2,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Noise")
self.ui.tableWidget_ConfusionMatrix.setItem(3,1,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Noise")
self.ui.tableWidget_ConfusionMatrix.setItem(1,3,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Target")
self.ui.tableWidget_ConfusionMatrix.setItem(1,4,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("BL [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,5,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("CCR [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,6,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Prec [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,7,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Reca [%]")
self.ui.tableWidget_ConfusionMatrix.setItem(1,8,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("Out")
self.ui.tableWidget_ConfusionMatrix.setItem(0,5,data)
data = QtGui.QTableWidgetItem()
data.setFont(font)
data.setText("True")
self.ui.tableWidget_ConfusionMatrix.setItem(2,0,data)
target = [0,0]
dimension = len(target)
for row in range(0,dimension):
for colomn in range(0,dimension):
target[row] += ConfusionMatrix[row][colomn]
data = QtGui.QTableWidgetItem(str(ConfusionMatrix[row][colomn]))
self.ui.tableWidget_ConfusionMatrix.setItem(row+2,colomn+2,data)
data = QtGui.QTableWidgetItem(str(target[row]))
self.ui.tableWidget_ConfusionMatrix.setItem(row+2,colomn+3,data)
# BASELINE
largestIndex = np.argmax(target)
maxValue = target[largestIndex]
sumTarget = sum(target)
baseline = (float(maxValue)/float(sumTarget))*100
data = QtGui.QTableWidgetItem(str("%.2f" % baseline))
self.ui.tableWidget_ConfusionMatrix.setItem(2,5,data)
# CCR
diagonalSum = 0
for diag in range(0,dimension):
diagonalSum += ConfusionMatrix[diag][diag]
CCR = (float(diagonalSum)/float(sumTarget))*100
data = QtGui.QTableWidgetItem(str("%.2f" % CCR))
self.ui.tableWidget_ConfusionMatrix.setItem(2,6,data)
classifierTarget = [0,0]
for colomn in range(0,dimension):
for row in range(0,dimension):
classifierTarget[colomn] += ConfusionMatrix[row][colomn]
precision = (float(ConfusionMatrix[colomn][colomn])/float(classifierTarget[colomn]))*100
data = QtGui.QTableWidgetItem(str("%.2f" % precision))
self.ui.tableWidget_ConfusionMatrix.setItem(colomn+2,7,data)
for diag in range(0,dimension):
recall = (float(ConfusionMatrix[diag][diag])/target[diag])*100
data = QtGui.QTableWidgetItem(str("%.2f" % recall))
self.ui.tableWidget_ConfusionMatrix.setItem(diag+2,8,data)
def file_dialog_classifier(self):
filepath = QtGui.QFileDialog.getOpenFileName(self,"Open HDF5 File",'', "HDF5 Files (*.hdf5 *.h5)")
from os.path import isfile
if isfile(filepath):
filename = filepath
self.DatabasePath = str(filename)
self.ui.label_classifier_databaseDirectory.setText(filename)
#self.HDFFile = h5py.File(str(filepath))
#self.HDFFile.visit(self.saveEventPath)
else:
self.ui.label_classifier_databaseDirectory.setText("None selected")
def getHDFInformationRecontructImage(self, paths, imgType):