コード例 #1
0
    def testFree(self):
        sampleData = numpy.indices((100, 200, 150), dtype=numpy.float32).sum(0)
        sampleData = vigra.taggedView(sampleData, axistags='xyz')

        graph = Graph()
        opData = OpArrayPiperWithAccessCount(graph=graph)
        opData.Input.setValue(sampleData)

        op = OpCompressedCache(graph=graph)
        #logger.debug("Setting block shape...")
        op.BlockShape.setValue([100, 75, 50])
        op.Input.connect(opData.Output)

        op.Output[...].wait()
        mem = op.usedMemory()
        keys = [x[0] for x in op.getBlockAccessTimes()]
        key = keys[0]
        op.freeBlock(key)
        assert op.usedMemory() < mem
コード例 #2
0
    def testFree(self):
        sampleData = numpy.indices((100, 200, 150), dtype=numpy.float32).sum(0)
        sampleData = vigra.taggedView(sampleData, axistags='xyz')
        
        graph = Graph()
        opData = OpArrayPiperWithAccessCount(graph=graph)
        opData.Input.setValue(sampleData)
        
        op = OpCompressedCache(graph=graph)
        #logger.debug("Setting block shape...")
        op.BlockShape.setValue([100, 75, 50])
        op.Input.connect(opData.Output)

        op.Output[...].wait()
        mem = op.usedMemory()
        keys = map(lambda x: x[0], op.getBlockAccessTimes())
        key = keys[0]
        op.freeBlock(key)
        assert op.usedMemory() < mem
コード例 #3
0
    def testReasonableCompression(self):
        # compression should be *way* better than this
        expected_factor = 4.0
        graph = Graph()
        sampleData = numpy.zeros((10000, 1000), dtype=numpy.uint8)
        sampleData = vigra.taggedView(sampleData, axistags="xy")

        opData = OpArrayPiper(graph=graph)
        opData.Input.setValue(sampleData)

        op = OpCompressedCache(parent=None, graph=graph)
        op.Input.connect(opData.Output)

        assert op.Output.ready()
        assert op.usedMemory() == 0.0, "cache must not be filled at this point"
        op.Output[...].wait()
        assert op.usedMemory() <= (
            sampleData.nbytes / expected_factor
        ), "Compression of all-zeroes should be better than factor " "{}".format(expected_factor)
コード例 #4
0
    def testReasonableCompression(self):
        # compression should be *way* better than this
        expected_factor = 4.0
        graph = Graph()
        sampleData = numpy.zeros((10000, 1000), dtype=numpy.uint8)
        sampleData = vigra.taggedView(sampleData, axistags='xy')

        opData = OpArrayPiper(graph=graph)
        opData.Input.setValue(sampleData)

        op = OpCompressedCache(parent=None, graph=graph)
        op.Input.connect(opData.Output)

        assert op.Output.ready()
        assert op.usedMemory() == 0.0,\
            "cache must not be filled at this point"
        op.Output[...].wait()
        assert op.usedMemory() <= (sampleData.nbytes /expected_factor),\
            "Compression of all-zeroes should be better than factor "\
            "{}".format(expected_factor)
コード例 #5
0
    def testReportGeneration(self):
        graph = Graph()
        sampleData = numpy.random.randint(0, 256, size=(50, 50, 50))
        sampleData = sampleData.astype(numpy.uint8)
        sampleData = vigra.taggedView(sampleData, axistags='xyz')

        opData = OpArrayPiper(graph=graph)
        opData.Input.setValue(sampleData)

        op = OpCompressedCache(parent=None, graph=graph)
        op.BlockShape.setValue((25, 25, 25))
        op.Input.connect(opData.Output)

        before = time.time()
        assert op.Output.ready()
        assert op.usedMemory() == 0.0,\
            "cache must not be filled at this point"
        op.Output[...].wait()
        assert op.usedMemory() > 0.0,\
            "cache must contain data at this point"
        after = time.time()

        r = MemInfoNode()
        op.generateReport(r)
        # not sure how good this can be compressed, but the cache
        # should hold memory by now
        assert r.usedMemory > 0
        # check sanity of last access time
        assert r.lastAccessTime >= before, str(r.lastAccessTime)
        assert r.lastAccessTime <= after, str(r.lastAccessTime)
        assert r.fractionOfUsedMemoryDirty == 0.0

        opData.Input.setDirty(
            (slice(0, 25), slice(0, 25), slice(0, 25)))
        assert op.fractionOfUsedMemoryDirty() < 1.0
        assert op.fractionOfUsedMemoryDirty() > 0

        opData.Input.setDirty(slice(None))
        assert op.fractionOfUsedMemoryDirty() == 1.0
コード例 #6
0
    def testReportGeneration(self):
        graph = Graph()
        sampleData = numpy.random.randint(0, 256, size=(50, 50, 50))
        sampleData = sampleData.astype(numpy.uint8)
        sampleData = vigra.taggedView(sampleData, axistags='xyz')

        opData = OpArrayPiper(graph=graph)
        opData.Input.setValue(sampleData)

        op = OpCompressedCache(parent=None, graph=graph)
        op.BlockShape.setValue((25, 25, 25))
        op.Input.connect(opData.Output)

        before = time.time()
        assert op.Output.ready()
        assert op.usedMemory() == 0.0,\
            "cache must not be filled at this point"
        op.Output[...].wait()
        assert op.usedMemory() > 0.0,\
            "cache must contain data at this point"
        after = time.time()

        r = MemInfoNode()
        op.generateReport(r)
        # not sure how good this can be compressed, but the cache
        # should hold memory by now
        assert r.usedMemory > 0
        # check sanity of last access time
        assert r.lastAccessTime >= before, str(r.lastAccessTime)
        assert r.lastAccessTime <= after, str(r.lastAccessTime)
        assert r.fractionOfUsedMemoryDirty == 0.0

        opData.Input.setDirty((slice(0, 25), slice(0, 25), slice(0, 25)))
        assert op.fractionOfUsedMemoryDirty() < 1.0
        assert op.fractionOfUsedMemoryDirty() > 0

        opData.Input.setDirty(slice(None))
        assert op.fractionOfUsedMemoryDirty() == 1.0
コード例 #7
0
ファイル: opCachedLabelImage.py プロジェクト: burcin/lazyflow
class OpCachedLabelImage(OpCache):
    """
    Combines OpLabelImage with OpCompressedCache, and provides a default block shape.
    """
    Input = InputSlot()
    
    BackgroundLabels = InputSlot(optional=True) # Optional. See OpLabelImage for details.
    BlockShape = InputSlot(optional=True)   # If not provided, blockshape is 1 time slice, 1 channel slice, 
                                            #  and the entire volume in xyz.
    Output = OutputSlot()

    # Serialization support
    InputHdf5 = InputSlot(optional=True)
    CleanBlocks = OutputSlot()
    OutputHdf5 = OutputSlot() # See OpCachedLabelImage for details
    
    # Schematic:
    #
    # BackgroundLabels --     BlockShape --
    #                    \                 \
    # Input ------------> OpLabelImage ---> OpCompressedCache --> Output
    #                                                        \
    #                                                         --> CleanBlocks
    
    def __init__(self, *args, **kwargs):
        warn_deprecated("OpCachedLabelImage is deprecated, use OpLabelVolume instead")
        super(OpCachedLabelImage, self).__init__(*args, **kwargs)
        
        # Hook up the labeler
        self._opLabelImage = OpLabelImage( parent=self )
        self._opLabelImage.Input.connect( self.Input )
        self._opLabelImage.BackgroundLabels.connect( self.BackgroundLabels )

        # Hook up the cache
        self._opCache = OpCompressedCache( parent=self )
        self._opCache.Input.connect( self._opLabelImage.Output )
        self._opCache.InputHdf5.connect( self.InputHdf5 )
        
        # Hook up our output slots
        self.Output.connect( self._opCache.Output )
        self.CleanBlocks.connect( self._opCache.CleanBlocks )
        self.OutputHdf5.connect( self._opCache.OutputHdf5 )
        
    def generateReport(self, report):
        return self._opCache.generateReport(report)
    
    def usedMemory(self):
        return self._opCache.usedMemory()
    
    def fractionOfUsedMemoryDirty(self):
        return self._opCache.fractionOfUsedMemoryDirty()
    
    def lastAccessTime(self):
        return self._opCache.lastAccessTime()
    
    def setupOutputs(self):
        if self.BlockShape.ready():
            self._opCache.BlockShape.setValue( self.BlockShape.value )
        else:
            # By default, block shape is the same as the entire image shape,
            #  but only 1 time slice and 1 channel slice
            taggedBlockShape = self.Input.meta.getTaggedShape()
            taggedBlockShape['t'] = 1
            taggedBlockShape['c'] = 1
            self._opCache.BlockShape.setValue( tuple( taggedBlockShape.values() ) )

    def execute(self, slot, subindex, roi, destination):
        assert False, "Shouldn't get here."
    
    def propagateDirty(self, slot, subindex, roi):
        pass # Nothing to do...

    def setInSlot(self, slot, subindex, roi, value):
        assert slot == self.Input or slot == self.InputHdf5, "Invalid slot for setInSlot(): {}".format( slot.name )
コード例 #8
0
class OpCachedLabelImage(OpCache):
    """
    Combines OpLabelImage with OpCompressedCache, and provides a default block shape.
    """
    Input = InputSlot()

    BackgroundLabels = InputSlot(
        optional=True)  # Optional. See OpLabelImage for details.
    BlockShape = InputSlot(
        optional=True
    )  # If not provided, blockshape is 1 time slice, 1 channel slice,
    #  and the entire volume in xyz.
    Output = OutputSlot()

    # Serialization support
    InputHdf5 = InputSlot(optional=True)
    CleanBlocks = OutputSlot()
    OutputHdf5 = OutputSlot()  # See OpCachedLabelImage for details

    # Schematic:
    #
    # BackgroundLabels --     BlockShape --
    #                    \                 \
    # Input ------------> OpLabelImage ---> OpCompressedCache --> Output
    #                                                        \
    #                                                         --> CleanBlocks

    def __init__(self, *args, **kwargs):
        warn_deprecated(
            "OpCachedLabelImage is deprecated, use OpLabelVolume instead")
        super(OpCachedLabelImage, self).__init__(*args, **kwargs)

        # Hook up the labeler
        self._opLabelImage = OpLabelImage(parent=self)
        self._opLabelImage.Input.connect(self.Input)
        self._opLabelImage.BackgroundLabels.connect(self.BackgroundLabels)

        # Hook up the cache
        self._opCache = OpCompressedCache(parent=self)
        self._opCache.Input.connect(self._opLabelImage.Output)
        self._opCache.InputHdf5.connect(self.InputHdf5)

        # Hook up our output slots
        self.Output.connect(self._opCache.Output)
        self.CleanBlocks.connect(self._opCache.CleanBlocks)
        self.OutputHdf5.connect(self._opCache.OutputHdf5)

    def generateReport(self, report):
        return self._opCache.generateReport(report)

    def usedMemory(self):
        return self._opCache.usedMemory()

    def fractionOfUsedMemoryDirty(self):
        return self._opCache.fractionOfUsedMemoryDirty()

    def lastAccessTime(self):
        return self._opCache.lastAccessTime()

    def setupOutputs(self):
        if self.BlockShape.ready():
            self._opCache.BlockShape.setValue(self.BlockShape.value)
        else:
            # By default, block shape is the same as the entire image shape,
            #  but only 1 time slice and 1 channel slice
            taggedBlockShape = self.Input.meta.getTaggedShape()
            taggedBlockShape['t'] = 1
            taggedBlockShape['c'] = 1
            self._opCache.BlockShape.setValue(tuple(taggedBlockShape.values()))

    def execute(self, slot, subindex, roi, destination):
        assert False, "Shouldn't get here."

    def propagateDirty(self, slot, subindex, roi):
        pass  # Nothing to do...

    def setInSlot(self, slot, subindex, roi, value):
        assert slot == self.Input or slot == self.InputHdf5, "Invalid slot for setInSlot(): {}".format(
            slot.name)