def testBasic3DcStackFromGlobString(self, empty_project_file): """Test if stacked 2d 3-channel files are loaded correctly""" # For some reason vigra saves 2D+c data compressed in gifs, so skip! for fileName, nickname in zip(self.imgFileNameGlobs2Dc, self.imgFileNameGlobs2DcNicknames): reader = OperatorWrapper(OpDataSelection, graph=Graph(), operator_kwargs={"forceAxisOrder": False}) reader.WorkingDirectory.setValue( str(Path(empty_project_file.filename).parent)) reader.Dataset.setValues( [FilesystemDatasetInfo(filePath=fileName, sequence_axis="z")]) # Read the test files using the data selection operator and verify the contents imgData3Dc = reader.Image[0][...].wait() # Check the file name output assert reader.ImageName[0].value == nickname # Check raw images assert imgData3Dc.shape == self.imgData3Dc.shape, ( imgData3Dc.shape, self.imgData3Dc.shape) # skip this if image was saved compressed: if any(x in fileName.lower() for x in self.compressedExtensions + [".gif"]): print("Skipping raw comparison for compressed data: {}".format( fileName)) continue numpy.testing.assert_array_equal(imgData3Dc, self.imgData3Dc)
def testBasic3DstacksFromFileList(self, empty_project_file): for ext, fileNames in list(self.imgFileLists2D.items()): fileNameString = os.path.pathsep.join(fileNames) reader = OperatorWrapper(OpDataSelection, graph=Graph(), operator_kwargs={"forceAxisOrder": False}) reader.WorkingDirectory.setValue( str(Path(empty_project_file.filename).parent)) reader.Dataset.setValues([ FilesystemDatasetInfo(filePath=fileNameString, sequence_axis="z") ]) # Read the test files using the data selection operator and verify the contents imgData3D = reader.Image[0][...].wait() # Check raw images assert imgData3D.shape == self.imgData3D.shape, ( imgData3D.shape, self.imgData3D.shape) # skip this if image was saved compressed: if any( x.strip(".") in ext.lower() for x in self.compressedExtensions): print("Skipping raw comparison for compressed data: {}".format( ext)) continue numpy.testing.assert_array_equal(imgData3D, self.imgData3D)
def test3DProjectLocalData(self, serializer, empty_project_file): empty_project_file.create_group("DataSelection") empty_project_file["DataSelection"].create_group("local_data") empty_project_file["DataSelection/local_data"].create_dataset( "dataset1", data=self.imgData3Dc) reader = OperatorWrapper(OpDataSelection, graph=Graph(), operator_kwargs={"forceAxisOrder": False}) reader.WorkingDirectory.setValue( str(Path(empty_project_file.filename).parent)) info = ProjectInternalDatasetInfo( inner_path="DataSelection/local_data/dataset1", project_file=empty_project_file) reader.Dataset.setValues([info]) projectInternalData = reader.Image[0][...].wait() assert projectInternalData.shape == self.imgData3Dc.shape, ( projectInternalData.shape, self.imgData3Dc.shape) assert (projectInternalData == self.imgData3Dc).all() for fileName in self.generatedImages3Dc: inner_path = serializer.importStackAsLocalDataset([fileName]) info = ProjectInternalDatasetInfo(project_file=empty_project_file, inner_path=inner_path) reader.Dataset.setValues([info]) projectInternalData = reader.Image[0][...].wait() assert projectInternalData.shape == self.imgData3Dc.shape, ( projectInternalData.shape, self.imgData3Dc.shape, ) assert (projectInternalData == self.imgData3Dc).all()
def testBasic3Dc(self): """Test if 2d 3-channel files are loaded correctly""" # For some reason vigra saves 2D+c data compressed in gifs, so skip! for fileName, nickname in zip(self.imgFileNames3Dc, self.imgFileNames3DcNicknames): graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={"forceAxisOrder": False}) reader.ProjectFile.setValue(self.projectFile) reader.WorkingDirectory.setValue(os.getcwd()) reader.ProjectDataGroup.setValue("DataSelection/local_data") reader.Dataset.setValues( [FilesystemDatasetInfo(filePath=fileName)]) # Read the test files using the data selection operator and verify the contents imgData3Dc = reader.Image[0][...].wait() # Check the file name output assert reader.ImageName[0].value == nickname # Check raw images assert imgData3Dc.shape == self.imgData3Dc.shape, ( imgData3Dc.shape, self.imgData3Dc.shape) # skip this if image was saved compressed: numpy.testing.assert_array_equal(imgData3Dc, self.imgData3Dc)
def __init__(self, *args, **kwargs): super(OpTrainVectorwiseClassifierBlocked, self).__init__(*args, **kwargs) self.progressSignal = OrderedSignal() self._opFeatureMatrixCaches = OperatorWrapper( OpFeatureMatrixCache, parent=self ) self._opFeatureMatrixCaches.LabelImage.connect( self.Labels ) self._opFeatureMatrixCaches.FeatureImage.connect( self.Images ) self._opConcatenateFeatureMatrices = OpConcatenateFeatureMatrices( parent=self ) self._opConcatenateFeatureMatrices.FeatureMatrices.connect( self._opFeatureMatrixCaches.LabelAndFeatureMatrix ) self._opConcatenateFeatureMatrices.ProgressSignals.connect( self._opFeatureMatrixCaches.ProgressSignal ) self._opTrainFromFeatures = OpTrainClassifierFromFeatureVectors( parent=self ) self._opTrainFromFeatures.ClassifierFactory.connect( self.ClassifierFactory ) self._opTrainFromFeatures.LabelAndFeatureMatrix.connect( self._opConcatenateFeatureMatrices.ConcatenatedOutput ) self._opTrainFromFeatures.MaxLabel.connect( self.MaxLabel ) self.Classifier.connect( self._opTrainFromFeatures.Classifier ) # Progress reporting def _handleFeatureProgress( progress ): self.progressSignal( 0.8*progress ) self._opConcatenateFeatureMatrices.progressSignal.subscribe( _handleFeatureProgress ) def _handleTrainingComplete(): self.progressSignal( 100.0 ) self._opTrainFromFeatures.trainingCompleteSignal.subscribe( _handleTrainingComplete )
def testNonReady(self): n = self.vol.shape[2] op = OpMultiArrayStacker(graph=self.g) op.AxisFlag.setValue("z") op.AxisIndex.setValue(0) providers = [OpNonReady(graph=self.g), OpNonReady(graph=self.g)] provider = OperatorWrapper(OpArrayPiper, graph=self.g) provider.Input.resize(n) vol = self.vol op.Images.resize(n) for i in range(n): provider.Input[i].setValue(vol[..., i]) providers[i].Input.connect(provider.Output[i]) op.Images[i].connect(providers[i].Output) req = op.Output[...] req.notify_failed( lambda *args: None ) # Replace the default handler: dont' show a traceback out = req.wait() with self.assertRaises(InputSlot.SlotNotReadyError): providers[0].screwWithOutput() req = op.Output[...] req.notify_failed( lambda *args: None ) # Replace the default handler: dont' show a traceback out = req.wait()
def testBasic2Dc(self): """Test if 2d 3-channel files are loaded correctly""" # For some reason vigra saves 2D+c data compressed in gifs, so skip! self.compressedExtensions.append(".gif") for fileName in self.imgFileNames2Dc: graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={"forceAxisOrder": False}) reader.ProjectFile.setValue(self.projectFile) reader.WorkingDirectory.setValue(os.getcwd()) info = FilesystemDatasetInfo(filePath=fileName) reader.Dataset.setValues([info]) # Read the test files using the data selection operator and verify the contents imgData2Dc = reader.Image[0][...].wait() # Check the file name output assert reader.ImageName[0].value == self.create_nickname(fileName) # Check raw images assert imgData2Dc.shape == self.imgData2Dc.shape, ( imgData2Dc.shape, self.imgData2Dc.shape) # skip this if image was saved compressed: if any(x in fileName.lower() for x in self.compressedExtensions): print("Skipping raw comparison for compressed data: {}".format( fileName)) continue numpy.testing.assert_array_equal(imgData2Dc, self.imgData2Dc)
def testProjectLocalData(self, serializer, empty_project_file): for fileName in self.generatedImages2Dc: # For some reason vigra saves 2D+c data compressed in gifs, so skip! if Path(fileName).suffix in self.compressedExtensions + [".gif"]: continue graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph, operator_kwargs={"forceAxisOrder": False}) reader.ProjectFile.setValue(empty_project_file) reader.WorkingDirectory.setValue( str(Path(empty_project_file.filename).parent)) # From project inner_path = serializer.importStackAsLocalDataset([fileName]) info = ProjectInternalDatasetInfo(project_file=empty_project_file, inner_path=inner_path) reader.Dataset.setValues([info]) projectInternalData = reader.Image[0][...].wait() assert projectInternalData.shape == self.imgData2Dc.shape, ( projectInternalData.shape, self.imgData2Dc.shape, ) assert (projectInternalData == self.imgData2Dc).all()
def testBasic3Dc(self): """Test if 2d 3-channel files are loaded correctly""" # For some reason vigra saves 2D+c data compressed in gifs, so skip! for fileName in self.imgFileNames3Dc: graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph) reader.ProjectFile.setValue(self.projectFile) reader.WorkingDirectory.setValue(os.getcwd()) reader.ProjectDataGroup.setValue('DataSelection/local_data') info = DatasetInfo() # Will be read from the filesystem since the data won't be found in the project file. info.location = DatasetInfo.Location.ProjectInternal info.filePath = fileName info.internalPath = "" info.invertColors = False info.convertToGrayscale = False reader.Dataset.setValues([info]) # Read the test files using the data selection operator and verify the contents imgData3Dc = reader.Image[0][...].wait() # Check the file name output assert reader.ImageName[0].value == fileName # Check raw images assert imgData3Dc.shape == self.imgData3Dc.shape # skip this if image was saved compressed: numpy.testing.assert_array_equal(imgData3Dc, self.imgData3Dc)
def testProjectLocalData(self): graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph) reader.ProjectFile.setValue(self.projectFile) reader.WorkingDirectory.setValue(os.getcwd()) reader.ProjectDataGroup.setValue('DataSelection/local_data') # Create a list of dataset infos . . . datasetInfos = [] # From project info = DatasetInfo() info.location = DatasetInfo.Location.ProjectInternal info.filePath = "This string should be ignored..." info._datasetId = 'dataset1' # (Cheating a bit here...) info.invertColors = False info.convertToGrayscale = False datasetInfos.append(info) reader.Dataset.setValues(datasetInfos) projectInternalData = reader.Image[0][...].wait() assert projectInternalData.shape == self.imgData3Dc.shape assert (projectInternalData == self.imgData3Dc).all()
def testBasic2D(self): """Test if plane 2d files are loaded correctly""" for fileName in self.imgFileNames2D: graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph) reader.ProjectFile.setValue(self.projectFile) reader.WorkingDirectory.setValue(os.getcwd()) reader.ProjectDataGroup.setValue('DataSelection/local_data') info = DatasetInfo() # Will be read from the filesystem since the data won't be found in the project file. info.location = DatasetInfo.Location.ProjectInternal info.filePath = fileName info.internalPath = "" info.invertColors = False info.convertToGrayscale = False reader.Dataset.setValues([info]) # Read the test files using the data selection operator and verify the contents imgData2D = reader.Image[0][...].wait() # Check the file name output assert reader.ImageName[0].value == fileName # Check raw images assert imgData2D.shape == self.imgData2D.shape # skip this if image was saved compressed: if any(x in fileName.lower() for x in self.compressedExtensions): print("Skipping raw comparison for compressed data: {}".format( fileName)) continue numpy.testing.assert_array_equal(imgData2D, self.imgData2D)
def testBasic3DWrongAxes(self): """Test if 3D file with intentionally wrong axes is rejected """ for fileName in self.imgFileNames3D: graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph) reader.ProjectFile.setValue(self.projectFile) reader.WorkingDirectory.setValue(os.getcwd()) reader.ProjectDataGroup.setValue('DataSelection/local_data') info = DatasetInfo() # Will be read from the filesystem since the data won't be found in the project file. info.location = DatasetInfo.Location.ProjectInternal info.filePath = fileName info.internalPath = "" info.invertColors = False info.convertToGrayscale = False info.axistags = vigra.defaultAxistags('tzyc') try: reader.Dataset.setValues([info]) assert False, "Should have thrown an exception!" except DatasetConstraintError: pass except: assert False, "Should have thrown a DatasetConstraintError!"
def test_fullWrapping(self): """ Test basic wrapping functionality (all slots are promoted) """ wrapped = OperatorWrapper(OpSimple, graph=self.graph) assert type(wrapped.InputA) == InputSlot assert type(wrapped.InputB) == InputSlot assert type(wrapped.Output) == OutputSlot assert wrapped.InputA.level == 1 assert wrapped.InputB.level == 1 assert wrapped.Output.level == 1 assert len(wrapped.InputA) == 0 assert len(wrapped.InputB) == 0 assert len(wrapped.Output) == 0 wrapped.InputA.resize(2) assert len(wrapped.InputB) == 2 assert len(wrapped.Output) == 2 a = numpy.array([[1, 2], [3, 4]]) b = numpy.array([2]) wrapped.InputA[0].setValue(a) wrapped.InputB[0].setValue(b) wrapped.InputA[1].setValue(2 * a) wrapped.InputB[1].setValue(3 * b) result0 = wrapped.Output[0][0:2, 0:2].wait() result1 = wrapped.Output[1][0:2, 0:2].wait() assert (result0 == a * b[0]).all() assert (result1 == 2 * a * 3 * b[0]).all()
def test_partialWrapping(self): """ By default, OperatorWrapper promotes all slots. This function tests what happens when only a subset of the inputs are promoted. """ wrapped = OperatorWrapper(OpSimple, graph=self.graph, promotedSlotNames=set(['InputA'])) assert type(wrapped.InputA) == InputSlot assert type(wrapped.InputB) == InputSlot assert type(wrapped.Output) == OutputSlot assert wrapped.InputA.level == 1 # Promoted because it was listed in the constructor call assert wrapped.InputB.level == 0 # NOT promoted assert wrapped.Output.level == 1 # Promoted because it's an output assert len(wrapped.InputA) == 0 assert len(wrapped.InputB) == 0 assert len(wrapped.Output) == 0 wrapped.InputA.resize(2) assert len(wrapped.InputB) == 0 # Not promoted assert len(wrapped.Output) == 2 a = numpy.array([[1, 2], [3, 4]]) b = numpy.array([2]) wrapped.InputA[0].setValue(a) wrapped.InputB.setValue(b) wrapped.InputA[1].setValue(2 * a) result0 = wrapped.Output[0][0:2, 0:2].wait() result1 = wrapped.Output[1][0:2, 0:2].wait() assert (result0 == a * b[0]).all() assert (result1 == 2 * a * b[0]).all()
def testBasic3DstacksFromFileList(self): for ext, fileNames in self.imgFileLists2D.items(): fileNameString = os.path.pathsep.join(fileNames) graph = lazyflow.graph.Graph() reader = OperatorWrapper(OpDataSelection, graph=graph) reader.ProjectFile.setValue(self.projectFile) reader.WorkingDirectory.setValue(os.getcwd()) reader.ProjectDataGroup.setValue('DataSelection/local_data') info = DatasetInfo(filepath=fileNameString) # Will be read from the filesystem since the data won't be found in the project file. info.location = DatasetInfo.Location.ProjectInternal info.internalPath = "" info.invertColors = False info.convertToGrayscale = False reader.Dataset.setValues([info]) # Read the test files using the data selection operator and verify the contents imgData3D = reader.Image[0][...].wait() # Check raw images assert imgData3D.shape == self.imgData3D.shape # skip this if image was saved compressed: if any( x.strip('.') in ext.lower() for x in self.compressedExtensions): print("Skipping raw comparison for compressed data: {}".format( ext)) continue numpy.testing.assert_array_equal(imgData3D, self.imgData3D)
def setupOutputs(self): # Create internal operators if self.DatasetRoles.value != self._roles: self._roles = self.DatasetRoles.value # Clean up the old operators self.ImageGroup.disconnect() self.Image.disconnect() self.Image1.disconnect() self.Image2.disconnect() self._NonTransposedImageGroup.disconnect() if self._opDatasets is not None: self._opDatasets.cleanUp() self._opDatasets = OperatorWrapper( OpDataSelection, parent=self, operator_kwargs={'forceAxisOrder': self._forceAxisOrder}, broadcastingSlotNames=[ 'ProjectFile', 'ProjectDataGroup', 'WorkingDirectory' ]) self.ImageGroup.connect(self._opDatasets.Image) self._NonTransposedImageGroup.connect( self._opDatasets._NonTransposedImage) self._opDatasets.Dataset.connect(self.DatasetGroup) self._opDatasets.ProjectFile.connect(self.ProjectFile) self._opDatasets.ProjectDataGroup.connect(self.ProjectDataGroup) self._opDatasets.WorkingDirectory.connect(self.WorkingDirectory) for role_index, opDataSelection in enumerate(self._opDatasets): opDataSelection.RoleName.setValue(self._roles[role_index]) if len(self._opDatasets.Image) > 0: self.Image.connect(self._opDatasets.Image[0]) if len(self._opDatasets.Image) >= 2: self.Image1.connect(self._opDatasets.Image[1]) else: self.Image1.disconnect() self.Image1.meta.NOTREADY = True if len(self._opDatasets.Image) >= 3: self.Image2.connect(self._opDatasets.Image[2]) else: self.Image2.disconnect() self.Image2.meta.NOTREADY = True self.ImageName.connect(self._opDatasets.ImageName[0]) self.AllowLabels.connect(self._opDatasets.AllowLabels[0]) else: self.Image.disconnect() self.Image1.disconnect() self.Image2.disconnect() self.ImageName.disconnect() self.AllowLabels.disconnect() self.Image.meta.NOTREADY = True self.Image1.meta.NOTREADY = True self.Image2.meta.NOTREADY = True self.ImageName.meta.NOTREADY = True self.AllowLabels.meta.NOTREADY = True
def test_setValues(self): wrappedCopier = OperatorWrapper( OpCopyInput, graph=self.graph ) values = ["Subslot One", "Subslot Two"] wrappedCopier.Input.setValues( values ) assert wrappedCopier.Output[0].value == values[0] assert wrappedCopier.Output[1].value == values[1]
def test(self): g = Graph() array1 = numpy.zeros((1, 1), dtype=float) array2 = numpy.ones((2, 2), dtype=float) array3 = numpy.zeros((3, 3), dtype=float) array4 = numpy.zeros((4, 4), dtype=float) array5 = numpy.zeros((5, 5), dtype=float) array6 = numpy.zeros((6, 6), dtype=float) array2[0, 0] = 0.123 array6[0, 0] = 0.456 opIn0Provider = OperatorWrapper(OpArrayPiper, graph=g) # We will provide 2 lists to concatenate # The first is provided by a separate operator which we set up in advance opIn0Provider.Input.resize(3) opIn0Provider.Input[0].setValue(array1) opIn0Provider.Input[1].setValue(array2) opIn0Provider.Input[2].setValue(array3) op = OpMultiInputConcatenater(graph=g) op.Inputs.resize(2) # Two lists to concatenate # Connect the first list op.Inputs[0].connect(opIn0Provider.Output) # Set up the second list directly via setValue() (no external operator) op.Inputs[1].resize(3) op.Inputs[1][0].setValue(array4) op.Inputs[1][1].setValue(array5) op.Inputs[1][2].setValue(array6) # print op.Inputs[0][0].meta # print op.Inputs[0][1].meta # print op.Inputs[0][2].meta # print op.Output[0].meta # print op.Output[1].meta # print op.Output[2].meta assert len(op.Output) == 6 assert op.Output[0].meta.shape == array1.shape assert op.Output[5].meta.shape == array6.shape assert numpy.all(op.Output[1][...].wait() == array2[...]) assert numpy.all(op.Output[5][...].wait() == array6[...]) op.Inputs[0].removeSlot(1, 2) # print len(op.Output) assert len(op.Output) == 5 assert op.Output[0].meta.shape == array1.shape assert op.Output[4].meta.shape == array6.shape assert numpy.all(op.Output[1][...].wait() == array3[...]) assert numpy.all(op.Output[4][...].wait() == array6[...])
def __init__(self, carvingGraphFile, *args, **kwargs): super(OpCarvingTopLevel, self).__init__(*args, **kwargs) # Convert data to 5d before giving it to the real operators op5 = OperatorWrapper( Op5ifyer, parent=self, graph=self.graph ) op5.input.connect( self.RawData ) self.opLabeling = OpLabeling(graph=self.graph, parent=self) self.opCarving = OperatorWrapper( OpCarving, operator_args=[carvingGraphFile], graph=self.graph, parent=self ) self.opLabeling.InputImages.connect( op5.output ) self.opCarving.RawData.connect( op5.output ) self.opCarving.WriteSeeds.connect(self.opLabeling.LabelInputs) #for each imageindex, keep track of a set of object names that have changed since #the last serialization of this object to disk self._dirtyObjects = defaultdict(set)
def setup_method(self, method): self.g = graph.Graph() self.op1 = OpWithMultiInputs(graph=self.g) self.op2 = OpWithMultiInputs(graph=self.g) self.wrappedOp = OperatorWrapper(OpA, graph=self.g) self.wrappedOp.Input1.connect(self.op1.Input) self.wrappedOp.Input2.connect(self.op2.Input)
def __init__(self, *args, **kwargs): super(OpWrappedVigraLabelVolume, self).__init__(*args, **kwargs) self._innerOperator = OperatorWrapper(OpVigraLabelVolume, parent=self) self._innerOperator.Input.connect(self.Input) self._innerOperator.BackgroundValue.connect( self.BackgroundValue) self.Output.connect(self._innerOperator.Output)
def __init__(self, graph): super(LayerViewerApplet, self).__init__("layer Viewer") self._topLevelOperator = OperatorWrapper(OpLayerViewer, graph=graph, promotedSlotNames=set( ['RawInput'])) self._preferencesManager = None self._serializableItems = [] self._gui = None
def testWrapped(self): """ Make sure the MulitArraySlicer2 functions as expected, even when wrapped with an OperatorWrapper. """ # Note: This test creates its own opSlicer and opProvider. # ( Doesn't use the ones created in self.setUp() ) # Data is tagged by channel opProvider = OperatorWrapper( OpArrayPiper, graph=self.graph ) opSlicer = OperatorWrapper( OpMultiArraySlicer2, graph=self.graph ) opSlicer.AxisFlag.setValue('c') opSlicer.Input.connect(opProvider.Output) data = numpy.indices((10,10,10,3))[3] data = data.view(vigra.VigraArray) data.axistags = vigra.defaultAxistags('xyzc') opProvider.Input.resize(2) opProvider.Input[0].setValue(data) opProvider.Input[1].setValue(2*data) assert len(opSlicer.Slices) == len(opProvider.Output) assert len(opSlicer.Slices[0]) == 3 assert len(opSlicer.Slices[1]) == 3 for i, slot in enumerate(opSlicer.Slices[0]): assert slot.meta.shape == (10,10,10,1) assert (slot[...].wait() == i).all() for i, slot in enumerate(opSlicer.Slices[1]): assert slot.meta.shape == (10,10,10,1) assert (slot[...].wait() == 2*i).all() opSlicer.SliceIndexes.setValue([1,2]) assert len(opSlicer.Slices[0]) == 2 assert len(opSlicer.Slices[1]) == 2 for i, slot in enumerate(opSlicer.Slices[0]): assert slot.meta.shape == (10,10,10,1) assert (slot[...].wait() == i+1).all() for i, slot in enumerate(opSlicer.Slices[1]): assert slot.meta.shape == (10,10,10,1) assert (slot[...].wait() == 2*(i+1)).all()
def opLabelArray(): raw_data = numpy.zeros((256, 256, 256, 1), dtype=numpy.uint32) opLabelArrays = OperatorWrapper(OpCompressedUserLabelArray, graph=Graph()) opLabelArrays.Input.resize(1) opLabelArrays.Input[0].meta.axistags = vigra.AxisTags("zyxc") opLabelArrays.Input[0].setValue(raw_data) opLabelArrays.shape.setValue(raw_data.shape) opLabelArrays.eraser.setValue(255) opLabelArrays.deleteLabel.setValue(-1) opLabelArrays.blockShape.setValue((64, 64, 64, 1)) return opLabelArrays
def test_real_data_source(self): reader = OperatorWrapper(OpDataSelection, graph=Graph(), operator_kwargs={"forceAxisOrder": False}) reader.WorkingDirectory.setValue(os.getcwd()) reader.Dataset.setValues([FilesystemDatasetInfo(filePath=self.testRawDataFileName)]) # Read the test file using the data selection operator and verify the contents imgData = reader.Image[0][...].wait() assert imgData.shape == self.imgData.shape numpy.testing.assert_array_equal(imgData, self.imgData)
def __init__( self, graph, guiName, projectFileGroupName ): super(VigraWatershedViewerApplet, self).__init__(guiName) # Wrap the top-level operator, since the GUI supports multiple images self._topLevelOperator = OperatorWrapper( OpVigraWatershedViewer, graph=graph, promotedSlotNames=['RawImage', 'InputImage', 'OverrideLabels'] ) self._gui = None # Created on first access self._serializableItems = []
def _initBatchWorkflow(self): """ Connect the batch-mode top-level operators to the training workflow and to eachother. """ # Access applet operators from the training workflow opTrainingFeatures = self.featureSelectionApplet.topLevelOperator opClassify = self.pcApplet.topLevelOperator # Access the batch operators opBatchInputs = self.batchInputApplet.topLevelOperator opBatchResults = self.batchResultsApplet.topLevelOperator ## Create additional batch workflow operators opBatchFeatures = OperatorWrapper( OpFeatureSelection, operator_kwargs={'filter_implementation':'Original'}, parent=self, promotedSlotNames=['InputImage'] ) opBatchPredictor = OperatorWrapper(OpAutocontextBatch, parent=self, promotedSlotNames=['FeatureImage']) ## Connect Operators ## # Provide dataset paths from data selection applet to the batch export applet via an attribute selector opBatchResults.DatasetPath.connect( opBatchInputs.ImageName ) # Connect (clone) the feature operator inputs from # the interactive workflow's features operator (which gets them from the GUI) opBatchFeatures.Scales.connect( opTrainingFeatures.Scales ) opBatchFeatures.FeatureIds.connect( opTrainingFeatures.FeatureIds ) opBatchFeatures.SelectionMatrix.connect( opTrainingFeatures.SelectionMatrix ) # Classifier and LabelsCount are provided by the interactive workflow opBatchPredictor.Classifiers.connect( opClassify.Classifiers ) opBatchPredictor.MaxLabelValue.connect( opClassify.MaxLabelValue ) # Sync autocontext contant opBatchPredictor.AutocontextIterations.connect( opClassify.AutocontextIterations ) # Connect Image pathway: # Input Image -> Features Op -> Prediction Op -> Export opBatchFeatures.InputImage.connect( opBatchInputs.Image ) opBatchPredictor.FeatureImage.connect( opBatchFeatures.OutputImage ) opBatchResults.ImageToExport.connect( opBatchPredictor.PredictionProbabilities )
def __init__(self, graph, guiName, projectFileGroupName): super(ThresholdMaskingApplet, self).__init__(guiName) # Wrap the top-level operator, since the GUI supports multiple images self._topLevelOperator = OperatorWrapper( OpThresholdMasking, graph=graph, promotedSlotNames=['InputImage']) self._gui = None self._serializableItems = [ ThresholdMaskingSerializer(self._topLevelOperator, projectFileGroupName) ]
def test_input_output_resize(self): exMulti = OpExplicitMulti(graph=self.graph) wrappedSimple = OperatorWrapper( OpSimple, graph=self.graph ) assert len(wrappedSimple.InputA) == 0 wrappedSimple.InputA.connect( exMulti.Output ) assert len(wrappedSimple.InputA) == 0 exMulti.Output.resize( 1 ) assert len(wrappedSimple.InputA) == 1 assert len(wrappedSimple.InputB) == 1 assert len(wrappedSimple.Output) == 1
def test_load_single_file_with_glob(self): reader = OperatorWrapper(OpDataSelection, graph=Graph(), operator_kwargs={"forceAxisOrder": False}) reader.WorkingDirectory.setValue(os.getcwd()) reader.Dataset.setValues([FilesystemDatasetInfo(filePath=self.glob_string, sequence_axis="t")]) # Read the test files using the data selection operator and verify the contents imgData = reader.Image[0][...].wait() # Check raw images assert imgData.shape == self.imgData3Dct.shape, (imgData.shape, self.imgData3Dct.shape) numpy.testing.assert_array_equal(imgData, self.imgData3Dct)
def __init__(self): # Create a graph to be shared by all operators graph = Graph() super(PixelClassificationWorkflow, self).__init__( graph=graph ) self._applets = [] ###################### # Interactive workflow ###################### ## Create applets self.projectMetadataApplet = ProjectMetadataApplet() self.dataSelectionApplet = DataSelectionApplet(self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False) self.featureSelectionApplet = FeatureSelectionApplet(self, "Feature Selection", "FeatureSelections") self.pcApplet = PixelClassificationApplet(self, "PixelClassification") ## Access applet operators opData = self.dataSelectionApplet.topLevelOperator opTrainingFeatures = self.featureSelectionApplet.topLevelOperator opClassify = self.pcApplet.topLevelOperator ## Connect operators ## # Input Image -> Feature Op # and -> Classification Op (for display) opTrainingFeatures.InputImage.connect( opData.Image ) opClassify.InputImages.connect( opData.Image ) # Feature Images -> Classification Op (for training, prediction) opClassify.FeatureImages.connect( opTrainingFeatures.OutputImage ) opClassify.CachedFeatureImages.connect( opTrainingFeatures.CachedOutputImage ) # Training flags -> Classification Op (for GUI restrictions) opClassify.LabelsAllowedFlags.connect( opData.AllowLabels ) ###################### # Batch workflow ###################### ## Create applets self.batchInputApplet = DataSelectionApplet(self, "Batch Inputs", "BatchDataSelection", supportIlastik05Import=False, batchDataGui=True) self.batchResultsApplet = BatchIoApplet(self, "Batch Results") ## Access applet operators opBatchInputs = self.batchInputApplet.topLevelOperator opBatchInputs.name = 'opBatchInputs' opBatchResults = self.batchResultsApplet.topLevelOperator ## Create additional batch workflow operators opBatchFeatures = OperatorWrapper( OpFeatureSelection, graph=graph, parent=self, promotedSlotNames=['InputImage'] ) opBatchFeatures.name = "opBatchFeatures" opBatchPredictor = OperatorWrapper( OpPredictRandomForest, graph=graph, parent=self, promotedSlotNames=['Image']) opBatchPredictor.name = "opBatchPredictor" opSelectBatchDatasetPath = OperatorWrapper( OpAttributeSelector, graph=graph, parent=self ) ## Connect Operators ## # Provide dataset paths from data selection applet to the batch export applet via an attribute selector opSelectBatchDatasetPath.InputObject.connect( opBatchInputs.Dataset ) opSelectBatchDatasetPath.AttributeName.setValue( 'filePath' ) opBatchResults.DatasetPath.connect( opSelectBatchDatasetPath.Result ) # Connect (clone) the feature operator inputs from # the interactive workflow's features operator (which gets them from the GUI) opBatchFeatures.Scales.connect( opTrainingFeatures.Scales ) opBatchFeatures.FeatureIds.connect( opTrainingFeatures.FeatureIds ) opBatchFeatures.SelectionMatrix.connect( opTrainingFeatures.SelectionMatrix ) # Classifier and LabelsCount are provided by the interactive workflow opBatchPredictor.Classifier.connect( opClassify.Classifier ) opBatchPredictor.LabelsCount.connect( opClassify.MaxLabelValue ) # Connect Image pathway: # Input Image -> Features Op -> Prediction Op -> Export opBatchFeatures.InputImage.connect( opBatchInputs.Image ) opBatchPredictor.Image.connect( opBatchFeatures.OutputImage ) opBatchResults.ImageToExport.connect( opBatchPredictor.PMaps ) self._applets.append(self.projectMetadataApplet) self._applets.append(self.dataSelectionApplet) self._applets.append(self.featureSelectionApplet) self._applets.append(self.pcApplet) self._applets.append(self.batchInputApplet) self._applets.append(self.batchResultsApplet) # The shell needs a slot from which he can read the list of image names to switch between. # Use an OpAttributeSelector to create a slot containing just the filename from the OpDataSelection's DatasetInfo slot. opSelectFilename = OperatorWrapper( OpAttributeSelector, graph=graph, parent=self ) opSelectFilename.InputObject.connect( opData.Dataset ) opSelectFilename.AttributeName.setValue( 'filePath' ) self._imageNameListSlot = opSelectFilename.Result
def setupOutputs(self): expectedShape = self.Inputs[0].meta.shape for slot in self.Inputs: assert slot.meta.shape == expectedShape, "Can't add images of different shapes!" self.Output.meta.assignFrom(self.Inputs[0].meta) def execute(self, slot, subindex, roi, result): result[...] = numpy.zeros(result.shape) for slot in self.Inputs: result[...] += slot.get(roi).wait() return result from lazyflow.operators import OpArrayPiper from lazyflow.graph import OperatorWrapper opGenericMultiOut = OperatorWrapper( OpArrayPiper, graph=graph ) opGenericMultiOut.Input.resize(3) opGenericMultiOut.name = "OpSomeProvider" svgOp1 = SvgOperator(opGenericMultiOut, max_child_depth=0) opSum = OpMultiSum(graph=graph) opSum.Inputs.resize(3) svgOp = SvgOperator(opSum, max_child_depth=1) class OpThreshold(Operator): ThresholdLevel = InputSlot() Input = InputSlot() Output = OutputSlot() def setupOutputs(self): self.Output.meta.assignFrom(self.Input.meta)