def __init__(self, shell, headless, workflow_cmdline_args, project_creation_args, *args, **kwargs): graph = kwargs.pop("graph") if "graph" in kwargs else Graph() super().__init__(shell, headless, workflow_cmdline_args, project_creation_args, graph=graph, *args, **kwargs) self.stored_object_classifier = None # Parse workflow-specific command-line args parser = argparse.ArgumentParser() parser.add_argument( "--fillmissing", help="use 'fill missing' applet with chosen detection method", choices=["classic", "svm", "none"], default="none", ) parser.add_argument("--nobatch", help="do not append batch applets", action="store_true", default=False) parsed_creation_args, unused_args = parser.parse_known_args( project_creation_args) self.fillMissing = parsed_creation_args.fillmissing parsed_args, unused_args = parser.parse_known_args( workflow_cmdline_args) if parsed_args.fillmissing != "none" and parsed_creation_args.fillmissing != parsed_args.fillmissing: logger.error( "Ignoring --fillmissing cmdline arg. Can't specify a different fillmissing setting after the project has already been created." ) self.batch = not parsed_args.nobatch self._applets = [] self.createInputApplets() if self.fillMissing != "none": self.fillMissingSlicesApplet = FillMissingSlicesApplet( self, "Fill Missing Slices", "Fill Missing Slices", self.fillMissing) self._applets.append(self.fillMissingSlicesApplet) # our main applets self.objectExtractionApplet = ObjectExtractionApplet( workflow=self, name="Object Feature Selection") self.objectClassificationApplet = ObjectClassificationApplet( workflow=self) self._tableExporter = TableExporter( self.objectClassificationApplet.topLevelOperator) self.dataExportApplet = ObjectClassificationDataExportApplet( self, "Object Information Export", table_exporter=self._tableExporter) # Customization hooks self.dataExportApplet.prepare_for_entire_export = self.prepare_for_entire_export self.dataExportApplet.post_process_entire_export = self.post_process_entire_export opDataExport = self.dataExportApplet.topLevelOperator opDataExport.WorkingDirectory.connect( self.dataSelectionApplet.topLevelOperator.WorkingDirectory) opDataExport.SelectionNames.setValue( self.ExportNames.asDisplayNameList()) self._batch_export_args = None self._batch_input_args = None self._export_args = None self.batchProcessingApplet = None self._applets.append(self.objectExtractionApplet) self._applets.append(self.objectClassificationApplet) self._applets.append(self.dataExportApplet) if self.batch: self.batchProcessingApplet = BatchProcessingApplet( self, "Batch Processing", self.dataSelectionApplet, self.dataExportApplet) self._applets.append(self.batchProcessingApplet) if unused_args: exportsArgParser, _ = self.exportsArgParser self._export_args, unused_args = exportsArgParser.parse_known_args( unused_args) # We parse the export setting args first. All remaining args are considered input files by the input applet. self._batch_export_args, unused_args = self.dataExportApplet.parse_known_cmdline_args( unused_args) self._batch_input_args, unused_args = self.batchProcessingApplet.parse_known_cmdline_args( unused_args) # For backwards compatibility, translate these special args into the standard syntax self._batch_input_args.export_source = self._export_args.export_source self.blockwiseObjectClassificationApplet = BlockwiseObjectClassificationApplet( self, "Blockwise Object Classification", "Blockwise Object Classification") self._applets.append(self.blockwiseObjectClassificationApplet) if unused_args: logger.warning("Unused command-line args: {}".format(unused_args))
def __init__(self, shell, headless, workflow_cmdline_args, project_creation_args, *args, **kwargs): graph = kwargs['graph'] if 'graph' in kwargs else Graph() if 'graph' in kwargs: del kwargs['graph'] super(ObjectClassificationWorkflow, self).__init__(shell, headless, workflow_cmdline_args, project_creation_args, graph=graph, *args, **kwargs) self.stored_pixel_classifier = None self.stored_object_classifier = None # Parse workflow-specific command-line args parser = argparse.ArgumentParser() parser.add_argument( '--fillmissing', help="use 'fill missing' applet with chosen detection method", choices=['classic', 'svm', 'none'], default='none') parser.add_argument('--filter', help="pixel feature filter implementation.", choices=['Original', 'Refactored', 'Interpolated'], default='Original') parser.add_argument('--nobatch', help="do not append batch applets", action='store_true', default=False) parsed_creation_args, unused_args = parser.parse_known_args( project_creation_args) self.fillMissing = parsed_creation_args.fillmissing self.filter_implementation = parsed_creation_args.filter parsed_args, unused_args = parser.parse_known_args( workflow_cmdline_args) if parsed_args.fillmissing != 'none' and parsed_creation_args.fillmissing != parsed_args.fillmissing: logger.error( "Ignoring --fillmissing cmdline arg. Can't specify a different fillmissing setting after the project has already been created." ) if parsed_args.filter != 'Original' and parsed_creation_args.filter != parsed_args.filter: logger.error( "Ignoring --filter cmdline arg. Can't specify a different filter setting after the project has already been created." ) self.batch = not parsed_args.nobatch self._applets = [] self.pcApplet = None self.projectMetadataApplet = ProjectMetadataApplet() self._applets.append(self.projectMetadataApplet) self.setupInputs() if self.fillMissing != 'none': self.fillMissingSlicesApplet = FillMissingSlicesApplet( self, "Fill Missing Slices", "Fill Missing Slices", self.fillMissing) self._applets.append(self.fillMissingSlicesApplet) if isinstance(self, ObjectClassificationWorkflowPixel): self.input_types = 'raw' elif isinstance(self, ObjectClassificationWorkflowBinary): self.input_types = 'raw+binary' elif isinstance(self, ObjectClassificationWorkflowPrediction): self.input_types = 'raw+pmaps' # our main applets self.objectExtractionApplet = ObjectExtractionApplet( workflow=self, name="Object Feature Selection") self.objectClassificationApplet = ObjectClassificationApplet( workflow=self) self.dataExportApplet = ObjectClassificationDataExportApplet( self, "Object Information Export") self.dataExportApplet.set_exporting_operator( self.objectClassificationApplet.topLevelOperator) # Customization hooks self.dataExportApplet.prepare_for_entire_export = self.prepare_for_entire_export #self.dataExportApplet.prepare_lane_for_export = self.prepare_lane_for_export self.dataExportApplet.post_process_lane_export = self.post_process_lane_export self.dataExportApplet.post_process_entire_export = self.post_process_entire_export opDataExport = self.dataExportApplet.topLevelOperator opDataExport.WorkingDirectory.connect( self.dataSelectionApplet.topLevelOperator.WorkingDirectory) # See EXPORT_SELECTION_PREDICTIONS and EXPORT_SELECTION_PROBABILITIES, above export_selection_names = [ 'Object Predictions', 'Object Probabilities', 'Blockwise Object Predictions', 'Blockwise Object Probabilities' ] if self.input_types == 'raw': # Re-configure to add the pixel probabilities option # See EXPORT_SELECTION_PIXEL_PROBABILITIES, above export_selection_names.append('Pixel Probabilities') opDataExport.SelectionNames.setValue(export_selection_names) self._batch_export_args = None self._batch_input_args = None self._export_args = None self.batchProcessingApplet = None if self.batch: self.batchProcessingApplet = BatchProcessingApplet( self, "Batch Processing", self.dataSelectionApplet, self.dataExportApplet) if unused_args: # Additional export args (specific to the object classification workflow) export_arg_parser = argparse.ArgumentParser() export_arg_parser.add_argument( "--table_filename", help= "The location to export the object feature/prediction CSV file.", required=False) export_arg_parser.add_argument( "--export_object_prediction_img", action="store_true") export_arg_parser.add_argument( "--export_object_probability_img", action="store_true") export_arg_parser.add_argument( "--export_pixel_probability_img", action="store_true") # TODO: Support this, too, someday? #export_arg_parser.add_argument( "--export_object_label_img", action="store_true" ) self._export_args, unused_args = export_arg_parser.parse_known_args( unused_args) if self.input_types != 'raw' and self._export_args.export_pixel_probability_img: raise RuntimeError("Invalid command-line argument: \n"\ "--export_pixel_probability_img' can only be used with the combined "\ "'Pixel Classification + Object Classification' workflow.") if sum([ self._export_args.export_object_prediction_img, self._export_args.export_object_probability_img, self._export_args.export_pixel_probability_img ]) > 1: raise RuntimeError( "Invalid command-line arguments: Only one type classification output can be exported at a time." ) # We parse the export setting args first. All remaining args are considered input files by the input applet. self._batch_export_args, unused_args = self.dataExportApplet.parse_known_cmdline_args( unused_args) self._batch_input_args, unused_args = self.batchProcessingApplet.parse_known_cmdline_args( unused_args) # For backwards compatibility, translate these special args into the standard syntax if self._export_args.export_object_prediction_img: self._batch_input_args.export_source = "Object Predictions" if self._export_args.export_object_probability_img: self._batch_input_args.export_source = "Object Probabilities" if self._export_args.export_pixel_probability_img: self._batch_input_args.export_source = "Pixel Probabilities" self.blockwiseObjectClassificationApplet = BlockwiseObjectClassificationApplet( self, "Blockwise Object Classification", "Blockwise Object Classification") self._applets.append(self.objectExtractionApplet) self._applets.append(self.objectClassificationApplet) self._applets.append(self.dataExportApplet) if self.batchProcessingApplet: self._applets.append(self.batchProcessingApplet) self._applets.append(self.blockwiseObjectClassificationApplet) if unused_args: logger.warn("Unused command-line args: {}".format(unused_args))