def sort_images(self): if self.folder is None or self.sort_path is None: error = QErrorMessage() error.setWindowTitle('Error') error.showMessage('One or more paths have not been set') error.exec_() elif os.path.isfile(self.model): self.progress.setValue(0) self.identifier.set_params(self.face_model, '128D', self.jitters, self.upsample) self.identifier.set_folder(self.folder) image_list = self.identifier.get_image_list() image_list.sort() results = list() if self.detect_objects is True: self.status.setText('Filtering images...') utils = IU() image_list = utils.detect_objects(image_list, bar=self.progress, classes=self.classes, conf=self.confidence) if self.sort_state is True: increment = float(100.00 / float(len(image_list))) self.progress.setValue(0) done = 0 self.status.setText('Sorting images...') for image in image_list: result = self.identifier.predict(image_path=image, threshold=self.threshold) if result is True: results.append(image) done += increment self.progress.setValue(done) self.progress.setValue(100) else: results = image_list if not os.path.exists(self.sort_path): os.makedirs(self.sort_path) self.progress.setValue(0) done = 0 self.status.setText('Copying results to folder...') increment = float(len(results) / 100.0) for image in results: copy(image, self.sort_path) done += increment self.progress.setValue(done) self.progress.setValue(100) self.status.setText('Done!') else: error = QErrorMessage() error.setWindowTitle('Error') error.showMessage("There was an error. That's all we know.") error.exec_()
def sort_images(self): if self.folder is None or self.sort_path is None: error = QErrorMessage() error.showMessage('One or more paths have not been set') error.exec_() elif os.path.isfile(self.model): if os.path.isfile('models/training_data.clf'): with open('models/training_data.clf', 'rb') as file: data = pickle.load(file) if 512 in data[0].shape and self.encoding_model == '128D': error = QErrorMessage() error.showMessage( 'The training data is 512D but model is 128D; they are incompatible' ) error.exec_() elif 128 in data[0].shape and self.encoding_model == '512D': error = QErrorMessage() error.showMessage( 'The training data is 128D but model is 512D; they are incompatible' ) error.exec_() else: self.progress.setValue(0) self.identifier.set_params(self.face_model, self.encoding_model, self.jitters, self.upsample) self.identifier.set_folder(self.folder) image_list = self.identifier.get_image_list() image_list.sort() results = list() if self.detect_objects is True: self.status.setText('Filtering images...') utils = IU() image_list = utils.detect_objects(image_list, bar=self.progress, classes=self.classes, conf=self.confidence) if self.sort_state is True: increment = float(100.00 / float(len(image_list))) self.progress.setValue(0) done = 0 self.status.setText('Sorting images...') for image in image_list: result = self.identifier.predict( image_path=image, threshold=self.threshold) if self.algorithm == 'Euclidean Distance': if result is True: results.append(image) elif self.algorithm == 'k-Nearest Neighbors': for name, loc in result: if name.lower() == 'search_face': results.append(image) break elif self.algorithm == 'Support Vector Machine(SVM)': if result is True: results.append(image) done += increment self.progress.setValue(done) self.progress.setValue(100) else: results = image_list if not os.path.exists(self.sort_path): os.makedirs(self.sort_path) self.progress.setValue(0) done = 0 self.status.setText('Copying results to folder...') increment = float(len(results) / 100.0) for image in results: copy(image, self.sort_path) done += increment self.progress.setValue(done) self.progress.setValue(100) self.status.setText('Done!') else: error = QErrorMessage() error.showMessage("There was an error. That's all we know.") error.exec_()