def OpenLabelImg(self): """ Opens labelimg. """ # Define current datasets directory to annotate dataSet = self.autoAnnotateDialogue.dataSetsComboBox.currentText() imgDir = os.path.join(config.datasets, dataSet) modelName = "" modelDir = "" errorMsg = None # Set variables try: if self.multiClassCheckBox: modelName = self.autoAnnotateDialogue.annotatorComboBox.currentText( ) modelDir = config.snapshots else: modelName = config.classesCSV modelDir = "" except Exception as e: print("Could not get classes path. Reason: " + str(e)) #DEBUG # Set classes file path mapPath, mapFileFound = general_error.GetMapPath(modelName, modelDir) if mapFileFound: errorMsg = general.OpenLabelImg(imgDir, mapPath) if errorMsg is not None: errorMessage = "Could not open labelImg. Reason: " + errorMsg self.autoAnnotateDialogue.textEdit.append(errorMessage)
def RunAnnotationButton(self): """ Runs when the RunAnnotationButton is clicked. """ # Set generate XML variable self.generateXML = True # If the multiclass option is set if self.multiClassCheckBox: # Set model directory self.modelDir = config.snapshots # Get currently selected model name self.selectedModel = self.autoAnnotateDialogue.annotatorComboBox.currentText( ) # Set map path mapPath, mapFileFound = general_error.GetMapPath(config.classesCSV, "") if mapFileFound: self.mapPath = mapPath # Set model directory self.modelDir = config.snapshots else: # Set model directory self.modelDir = config.pretrainedModels # Set single class annotator model as default model self.selectedModel = "single_class_annotator.h5" # Set map path mapPath, mapFileFound = general_error.GetMapPath( self.selectedModel, self.modelDir) if mapFileFound: self.mapPath = mapPath # Create classes CSV file error, errorMsg = general.CreateClassString(self.selectedModel, config.pretrainedModels, self.annotateClassesSet) if error: errorMessage = "There was an error with creating CSV file: " + errorMsg self.autoAnnotateDialogue.textEdit.append(errorMessage) # Set self.cancelPreview value self.cancelPreview = False # Set first preview image variable for messaging self.firstPreviewImage = True # Chosen dataset dataSet = self.autoAnnotateDialogue.dataSetsComboBox.currentText() self.testImagesPath = os.path.join(config.datasets, dataSet) # Set image count enoughImages, imageCount, errorMessage = general_image.EnoughImages( self.testImagesPath, 0) if errorMessage is not None: self.autoAnnotateDialogue.textEdit.append(errorMessage) self.previewImagesNum = imageCount # Set progress bar max value self.inferenceProgressBarMaxValue = self.previewImagesNum # Reset progress bar self.autoAnnotateDialogue.progressBar.setValue(0) # Set progress bar ui_general.SetProgressBar(self, self.autoAnnotateDialogue) # Start preview images thread ui_general.StartPreviewThread(self, self.autoAnnotateDialogue) # Disable widgets while processing images StartToggleAaWidgets(self)
testImage = "test/test_images/1.jpg" testModelName = "test_model" testModelDir = "test" testClassFile = "test_model.csv" testString = "Test string." print("Testing general_error.py\n") # Test general_error.FileExists fileExists, errorMsg = general_error.FileExists(testImage) assert fileExists assert errorMsg is None print("general_error.FileExists passed") # Test general_error.GetMapPath mapPath, mapFilePath = general_error.GetMapPath(testModelName, testModelDir) assert mapPath == os.path.join(testModelDir, testClassFile) assert mapFilePath print("general_error.GetMapPath passed") # Test general_error.StringNotEmpty notEmpty = general_error.StringNotEmpty(testString) assert True print("general_error.StringNotEmpty passed") # Test general_error.CheckCSV csvExist, error, errorMsg = general_error.CheckCSV() assert csvExist assert error is False assert errorMsg is None print("general_error.CheckCSV passed")
def RunInferenceButton(self): """ Run inference on selected model. """ # Set self.cancelPreview value self.cancelPreview = False # Set first preview image variable for messaging self.firstPreviewImage = True # Set model name ui_general.SetModel(self, self.runInferenceDialogue) # Ensure name is not empty modelNotEmpty = general_error.StringNotEmpty(self.selectedModel) # Ensure test images dir has been selected imagesDirNotEmpty = general_error.StringNotEmpty(self.testImagesPath) # Ensure image count is less than image dir image count. enoughImages, imageCount, errorMessage = general_image.EnoughImages( self.testImagesPath, self.previewImagesNum) if errorMessage is not None: self.runInferenceDialogue.textEdit.append(errorMessage) if enoughImages is False: self.previewImagesNum = imageCount # Update preview images number ui_general.SetPreviewImagesNum(self, self.runInferenceDialogue) # Set progress bar max value self.inferenceProgressBarMaxValue = self.previewImagesNum # Set model directory self.modelDir = config.pretrainedModels # Set map name mapPath, mapFileFound = general_error.GetMapPath(self.selectedModel, config.pretrainedModels) if mapFileFound: self.mapPath = mapPath # Reset progress bar self.runInferenceDialogue.progressBar.setValue(0) # Set progress bar ui_general.SetProgressBar(self, self.runInferenceDialogue) # Create thread to process images if modelNotEmpty and imagesDirNotEmpty and mapFileFound: ui_general.StartPreviewThread(self, self.runInferenceDialogue) # Disable widgets while processing images StartToggleRiWidgets(self) # Update dialogue self.runInferenceDialogue.textEdit.append("Commencing inference.") else: if modelNotEmpty is False: QtWidgets.QMessageBox.information(self.runInferenceDialogue, "No model found", "Please select a model first.", QtWidgets.QMessageBox.Ok) if imagesDirNotEmpty is False: QtWidgets.QMessageBox.information( self.runInferenceDialogue, "No image directory selected", "Please select a test images directory first.", QtWidgets.QMessageBox.Ok) if mapFileFound is False: QtWidgets.QMessageBox.information( self.runInferenceDialogue, "No map file found", "The model you have selected does not have a map file. Please select a different model.", QtWidgets.QMessageBox.Ok)