def test(self): # Define the files we'll be making testProjectName = 'test_project.ilp' # Clean up: Remove the test data files we created last time (just in case) for f in [testProjectName]: try: os.remove(f) except: pass # Create an empty project with h5py.File(testProjectName) as testProject: testProject.create_dataset("ilastikVersion", data=0.6) # Create an operator to work with and give it some input g = Graph() op = OpMockPixelClassifier(graph=g) operatorToSave = op serializer = PixelClassificationSerializer(operatorToSave, 'PixelClassificationTest') op.LabelInputs.resize( 1 ) # Create some labels labeldata = numpy.zeros(op.dataShape) labeldata[:,:,0:5,:,:] = 1 labeldata[:,:,50:60,:] = 2 # Slice them into our operator op.LabelInputs[0][0:1, 0:10, 0:5, 0:100, 0:1] = labeldata[:,:,0:5,:,:] op.LabelInputs[0][0:1, 0:10, 50:60, 0:100, 0:1] = labeldata[:,:,50:60,:,:] # Simulate the predictions changing by setting the prediction output dirty op.PredictionProbabilities[0].setDirty(slice(None)) # Enable prediction storage serializer.predictionStorageEnabled = True # Serialize! serializer.serializeToHdf5(testProject, testProjectName) # Check that the prediction data was written to the file assert (testProject['PixelClassificationTest/Predictions/predictions0000'][...] == op.PredictionProbabilities[0][...].wait()).all() # Deserialize into a fresh operator operatorToLoad = OpMockPixelClassifier(graph=g) deserializer = PixelClassificationSerializer(operatorToLoad, 'PixelClassificationTest') deserializer.deserializeFromHdf5(testProject, testProjectName) # Did the data go in and out of the file without problems? assert len(operatorToLoad.LabelImages) == 1 assert (operatorToSave.LabelImages[0][...].wait() == operatorToLoad.LabelImages[0][...].wait()).all() assert (operatorToSave.LabelImages[0][...].wait() == labeldata[...]).all() os.remove(testProjectName)
def __init__(self, workflow, projectFileGroupName): self._topLevelOperator = OpIIBoostPixelClassification(parent=workflow) def on_classifier_changed(slot, roi): if self._topLevelOperator.classifier_cache.Output.ready() and \ self._topLevelOperator.classifier_cache.fixAtCurrent.value is True and \ self._topLevelOperator.classifier_cache.Output.value is None: # When the classifier is deleted (e.g. because the number of features has changed, # then notify the workflow. (Export applet should be disabled.) self.appletStateUpdateRequested() self._topLevelOperator.classifier_cache.Output.notifyDirty( on_classifier_changed) super(IIBoostPixelClassificationApplet, self).__init__("Synapse Detection") # We can use the ordinary pixel classification serializer class. self._serializableItems = [ PixelClassificationSerializer(self._topLevelOperator, projectFileGroupName) ] self._gui = None # GUI needs access to the serializer to enable/disable prediction storage self.predictionSerializer = self._serializableItems[0] # FIXME: For now, we can directly connect the progress signal from the classifier training operator # directly to the applet's overall progress signal, because it's the only thing we report progress for at the moment. # If we start reporting progress for multiple tasks that might occur simultaneously, # we'll need to aggregate the progress updates. self._topLevelOperator.opTrain.progressSignal.subscribe( self.progressSignal)
def test(self): # Define the files we'll be making testProjectName = 'test_project.ilp' # Clean up: Remove the test data files we created last time (just in case) for f in [testProjectName]: try: os.remove(f) except: pass # Create an empty project with h5py.File(testProjectName) as testProject: testProject.create_dataset("ilastikVersion", data="1.0.0") # Create an operator to work with and give it some input g = Graph() op = OpMockPixelClassifier(graph=g) operatorToSave = op serializer = PixelClassificationSerializer(operatorToSave, 'PixelClassificationTest') op.LabelInputs.resize( 1 ) # Create some labels labeldata = numpy.zeros(op.dataShape) labeldata[:,:,0:5,:,:] = 1 labeldata[:,:,50:60,:] = 2 # Slice them into our operator op.LabelInputs[0][0:1, 0:10, 0:5, 0:100, 0:1] = labeldata[:,:,0:5,:,:] op.LabelInputs[0][0:1, 0:10, 50:60, 0:100, 0:1] = labeldata[:,:,50:60,:,:] # change label names and colors op.LabelNames.setValue( ["Label1", "Label2"] ) op.LabelColors.setValue( [(255,30,30), (30,255,30)] ) op.PmapColors.setValue( [(255,30,30), (30,255,30)] ) # Simulate the predictions changing by setting the prediction output dirty op.PredictionProbabilities[0].setDirty(slice(None)) # Serialize! serializer.serializeToHdf5(testProject, testProjectName) # Deserialize into a fresh operator operatorToLoad = OpMockPixelClassifier(graph=g) deserializer = PixelClassificationSerializer(operatorToLoad, 'PixelClassificationTest') deserializer.deserializeFromHdf5(testProject, testProjectName) # Did the data go in and out of the file without problems? assert len(operatorToLoad.LabelImages) == 1 assert (operatorToSave.LabelImages[0][...].wait() == operatorToLoad.LabelImages[0][...].wait()).all() assert (operatorToSave.LabelImages[0][...].wait() == labeldata[...]).all() assert operatorToSave.LabelNames.value == operatorToLoad.LabelNames.value assert (numpy.array(operatorToSave.LabelColors.value) == numpy.array(operatorToLoad.LabelColors.value)).all() assert (numpy.array(operatorToSave.PmapColors.value) == numpy.array(operatorToLoad.PmapColors.value)).all() os.remove(testProjectName)
def test(self): # Define the files we'll be making testProjectName = 'test_project.ilp' # Clean up: Remove the test data files we created last time (just in case) for f in [testProjectName]: try: os.remove(f) except: pass # Create an empty project with h5py.File(testProjectName) as testProject: testProject.create_dataset("ilastikVersion", data=b"1.0.0") # Create an operator to work with and give it some input g = Graph() op = OpMockPixelClassifier(graph=g) operatorToSave = op serializer = PixelClassificationSerializer(operatorToSave, 'PixelClassificationTest') op.LabelInputs.resize( 1 ) # Create some labels labeldata = numpy.zeros(op.dataShape) labeldata[:,:,0:5,:,:] = 1 labeldata[:,:,50:60,:] = 2 # Slice them into our operator op.LabelInputs[0][0:1, 0:10, 0:5, 0:100, 0:1] = labeldata[:,:,0:5,:,:] op.LabelInputs[0][0:1, 0:10, 50:60, 0:100, 0:1] = labeldata[:,:,50:60,:,:] # change label names and colors op.LabelNames.setValue( ["Label1", "Label2"] ) op.LabelColors.setValue( [(255,30,30), (30,255,30)] ) op.PmapColors.setValue( [(255,30,30), (30,255,30)] ) # Simulate the predictions changing by setting the prediction output dirty op.PredictionProbabilities[0].setDirty(slice(None)) # Serialize! serializer.serializeToHdf5(testProject, testProjectName) # Deserialize into a fresh operator operatorToLoad = OpMockPixelClassifier(graph=g) deserializer = PixelClassificationSerializer(operatorToLoad, 'PixelClassificationTest') deserializer.deserializeFromHdf5(testProject, testProjectName) # Did the data go in and out of the file without problems? assert len(operatorToLoad.LabelImages) == 1 assert (operatorToSave.LabelImages[0][...].wait() == operatorToLoad.LabelImages[0][...].wait()).all() assert (operatorToSave.LabelImages[0][...].wait() == labeldata[...]).all() assert operatorToSave.LabelNames.value == operatorToLoad.LabelNames.value, \ "{} != {}".format( operatorToSave.LabelNames.value, operatorToLoad.LabelNames.value ) assert (numpy.array(operatorToSave.LabelColors.value) == numpy.array(operatorToLoad.LabelColors.value)).all() assert (numpy.array(operatorToSave.PmapColors.value) == numpy.array(operatorToLoad.PmapColors.value)).all() os.remove(testProjectName)