def convert_predictions_to_uncertainties( input_path, parsed_export_args ): """ Read exported pixel predictions and calculate/export the uncertainties. input_path: The path to the prediction output file. If hdf5, must include the internal dataset name. parsed_export_args: The already-parsed cmd-line arguments generated from a DataExportApplet-compatible ArgumentParser. """ graph = Graph() opReader = OpInputDataReader(graph=graph) opReader.WorkingDirectory.setValue( os.getcwd() ) opReader.FilePath.setValue(input_path) opUncertainty = OpEnsembleMargin( graph=graph ) opUncertainty.Input.connect( opReader.Output ) opExport = OpFormattedDataExport( graph=graph ) opExport.Input.connect( opUncertainty.Output ) # Apply command-line arguments. DataExportApplet._configure_operator_with_parsed_args(parsed_export_args, opExport) last_progress = [-1] def print_progress(progress_percent): if progress_percent != last_progress[0]: last_progress[0] = progress_percent sys.stdout.write( " {}".format(progress_percent) ) print "Exporting results to : {}".format( opExport.ExportPath.value ) sys.stdout.write("Progress:") opExport.progressSignal.subscribe(print_progress) # Begin export opExport.run_export() sys.stdout.write("\n") print "DONE."
def _configure_operator_with_parsed_args(cls, parsed_args, opTrackingDataExport): """ Helper function for headless workflows. Configures the given export operator according to the settings provided in ``parsed_args``, and depending on the chosen export source it also configures the parent operator opDataExport :param parsed_args: Must be an ``argparse.Namespace`` as returned by :py:meth:`parse_known_cmdline_args()`. """ if parsed_args.export_source is not None: opTrackingDataExport.SelectedExportSource.setValue(parsed_args.export_source) if parsed_args.export_source == OpTrackingBaseDataExport.PluginOnlyName: opTrackingDataExport.SelectedPlugin.setValue(parsed_args.export_plugin) # if a plugin was selected, the only thing we need is the export name if parsed_args.output_filename_format: if hasattr(opTrackingDataExport, 'WorkingDirectory'): # By default, most workflows consider the project directory to be the 'working directory' # for transforming relative paths (e.g. export locations) into absolute locations. # A user would probably expect paths to be relative to his cwd when he launches # ilastik from the command line. opTrackingDataExport.WorkingDirectory.disconnect() opTrackingDataExport.WorkingDirectory.setValue(os.getcwd()) opTrackingDataExport.OutputFilenameFormat.setValue(parsed_args.output_filename_format) return # We don't want to configure the super operator so we quit now! else: # set some value to the SelectedPlugin slot so that it is ready opTrackingDataExport.SelectedPlugin.setValue("None") # configure super operator DataExportApplet._configure_operator_with_parsed_args(parsed_args, opTrackingDataExport)
def convert_predictions_to_segmentation(input_paths, parsed_export_args): """ Read exported pixel predictions and calculate/export the segmentation. input_path: The path to the prediction output file. If hdf5, must include the internal dataset name. parsed_export_args: The already-parsed cmd-line arguments generated from a DataExportApplet-compatible ArgumentParser. """ graph = Graph() opReader = OpInputDataReader(graph=graph) opReader.WorkingDirectory.setValue(os.getcwd()) opArgmaxChannel = OpArgmaxChannel(graph=graph) opArgmaxChannel.Input.connect(opReader.Output) opExport = OpFormattedDataExport(graph=graph) opExport.Input.connect(opArgmaxChannel.Output) # Apply command-line arguments. DataExportApplet._configure_operator_with_parsed_args( parsed_export_args, opExport) last_progress = [-1] def print_progress(progress_percent): if progress_percent != last_progress[0]: last_progress[0] = progress_percent sys.stdout.write(" {}".format(progress_percent)) opExport.progressSignal.subscribe(print_progress) for input_path in input_paths: opReader.FilePath.setValue(input_path) input_pathcomp = PathComponents(input_path) opExport.OutputFilenameFormat.setValue(str( input_pathcomp.externalPath)) output_path = opExport.ExportPath.value output_pathcomp = PathComponents(output_path) output_pathcomp.filenameBase += "_Segmentation" opExport.OutputFilenameFormat.setValue( str(output_pathcomp.externalPath)) print("Exporting results to : {}".format(opExport.ExportPath.value)) sys.stdout.write("Progress:") # Begin export opExport.run_export() sys.stdout.write("\n") print("DONE.")
def _configure_operator_with_parsed_args(cls, parsed_args, opTrackingDataExport): """ Helper function for headless workflows. Configures the given export operator according to the settings provided in ``parsed_args``, and depending on the chosen export source it also configures the parent operator opDataExport :param parsed_args: Must be an ``argparse.Namespace`` as returned by :py:meth:`parse_known_cmdline_args()`. """ if parsed_args.export_source is not None: opTrackingDataExport.SelectedExportSource.setValue( parsed_args.export_source) if parsed_args.export_source == OpTrackingBaseDataExport.PluginOnlyName: opTrackingDataExport.SelectedPlugin.setValue( parsed_args.export_plugin) if parsed_args.export_plugin == "Fiji-MaMuT": if opTrackingDataExport.AdditionalPluginArguments.ready(): additional_plugin_args = opTrackingDataExport.AdditionalPluginArguments.value else: additional_plugin_args = {} additional_plugin_args[ "bdvFilepath"] = parsed_args.big_data_viewer_xml_file opTrackingDataExport.AdditionalPluginArguments.setValue( additional_plugin_args) # if a plugin was selected, the only thing we need is the export name if parsed_args.output_filename_format: if hasattr(opTrackingDataExport, "WorkingDirectory"): # By default, most workflows consider the project directory to be the 'working directory' # for transforming relative paths (e.g. export locations) into absolute locations. # A user would probably expect paths to be relative to his cwd when he launches # ilastik from the command line. opTrackingDataExport.WorkingDirectory.disconnect() opTrackingDataExport.WorkingDirectory.setValue( os.getcwd()) opTrackingDataExport.OutputFilenameFormat.setValue( parsed_args.output_filename_format) return # We don't want to configure the super operator so we quit now! else: # set some value to the SelectedPlugin slot so that it is ready opTrackingDataExport.SelectedPlugin.setValue("None") # configure super operator DataExportApplet._configure_operator_with_parsed_args( parsed_args, opTrackingDataExport)
def convert_predictions_to_segmentation( input_paths, parsed_export_args ): """ Read exported pixel predictions and calculate/export the segmentation. input_path: The path to the prediction output file. If hdf5, must include the internal dataset name. parsed_export_args: The already-parsed cmd-line arguments generated from a DataExportApplet-compatible ArgumentParser. """ graph = Graph() opReader = OpInputDataReader(graph=graph) opReader.WorkingDirectory.setValue( os.getcwd() ) opArgmaxChannel = OpArgmaxChannel( graph=graph ) opArgmaxChannel.Input.connect( opReader.Output ) opExport = OpFormattedDataExport( graph=graph ) opExport.Input.connect( opArgmaxChannel.Output ) # Apply command-line arguments. DataExportApplet._configure_operator_with_parsed_args(parsed_export_args, opExport) last_progress = [-1] def print_progress(progress_percent): if progress_percent != last_progress[0]: last_progress[0] = progress_percent sys.stdout.write( " {}".format(progress_percent) ) opExport.progressSignal.subscribe(print_progress) for input_path in input_paths: opReader.FilePath.setValue(input_path) input_pathcomp = PathComponents(input_path) opExport.OutputFilenameFormat.setValue(str(input_pathcomp.externalPath)) output_path = opExport.ExportPath.value output_pathcomp = PathComponents( output_path ) output_pathcomp.filenameBase += "_Segmentation" opExport.OutputFilenameFormat.setValue(str(output_pathcomp.externalPath)) print "Exporting results to : {}".format( opExport.ExportPath.value ) sys.stdout.write("Progress:") # Begin export opExport.run_export() sys.stdout.write("\n") print "DONE."