Example #1
0
    def __init__(self,
                 replacement=True,
                 start=0,
                 equalizeCategories=False,
                 *args,
                 **kwargs):
        """
        Args:
            replacement: Whether the same image can be picked multiple times.
            start: Number of random choices to skip at the beginning, useful
                   when seeding the random number generator.
        """
        BaseExplorer.__init__(self, *args, **kwargs)

        if type(replacement) not in (bool, int):
            raise RuntimeError("'replacement' should be a boolean")
        if type(start) is not int:
            raise RuntimeError("'start' should be an integer")

        self.replacement = replacement
        self.start = start
        self.equalizeCategories = equalizeCategories
        self.imagesByCat = None

        if not self.replacement:
            self.history = []
Example #2
0
    def __init__(self, sweepDirections=['left', 'right', 'up', 'down'],
                 shiftDuringSweep=1, sweepOffObject=False, *args, **kwargs):
        """
        Args:
        sweepDirections: Directions for sweeping. Must be a list containing
          one or more of 'left', 'right', 'up', and 'down' for horizontal and
          vertical sweeps, or 'leftup', 'leftdown', 'rightup', and 'rightdown'
          for diagonal sweeps (or 'upleft, 'downleft', 'upright', and
          'downright'). Can also be the string 'all', for all eight directions.
        shiftDuringSweep: Number of pixels to jump with each step (during
          a sweep).
        sweepOffObject: Whether the sensor can only include a part of the
          object, as specified by the bounding box. If False, it will only move
          to positions that include as much of the object as possible.
        """
        BaseExplorer.__init__(self, *args, **kwargs)

        if sweepDirections == 'all':
            sweepDirections = ['left', 'right', 'up', 'down',
              'leftdown', 'leftup', 'rightdown', 'rightup']
        else:
            for direction in sweepDirections:
                if direction not in ('left', 'right', 'up', 'down',
                    'leftup', 'upleft', 'leftdown', 'downleft',
                    'rightup', 'upright', 'rightdown', 'downright'):
                    raise RuntimeError('Unknown sweep direction: %s' % direction)
        if type(shiftDuringSweep) is not int:
            raise RuntimeError("'shiftDuringSweep' should be an integer")
        if type(sweepOffObject) not in (bool, int):
            raise RuntimeError("'sweepOffObject' should be a boolean")

        self.sweepDirections = sweepDirections
        self.shiftDuringSweep = shiftDuringSweep
        self.sweepOffObject = sweepOffObject
Example #3
0
    def __init__(self, sweepDirections=["right", "down"], shiftDuringSweep=1,
                 shiftBetweenSweeps=1, sweepOffObject=False, order=None,
                 *args, **kwargs):
        """
        Args:
            sweepDirections: Directions for sweeping (a list containing one or
                             more of 'left', 'right', 'up', and 'down').
            shiftDuringSweep: Number of pixels to jump with each step (during a
                              sweep).
            shiftBetweenSweeps: Number of pixels to jump in between sweeps
                                (for example, when moving down a line after
                                sweeping across).
            sweepOffObject: Whether the sensor can only include a part of the
                            object, as specified by the bounding box. If False,
                            it will only move to positions that include as much
                            of the object as possible. If True, it will sweep
                            until all of the object moves off the sensor. If
                            set to a floating point number between 0 and 1,
                            then it will sweep until that fraction of the
                            object moves off the sensor.
            order: Order in which to iterate (outer to inner). Default progresses
                   through switching images, filters, and sweeping, where
                   switching images is the outer loop and sweeping is the inner
                   loop. Should be a list containing 'image', 'sweep', and
                   0, 1, ... numFilters-1.
        """
        BaseExplorer.__init__(self, *args, **kwargs)

        for direction in sweepDirections:
            if direction not in ('left', 'right', 'up', 'down'):
                raise RuntimeError("Unknown sweep direction: '%s'" % direction)
        if type(shiftDuringSweep) is not int:
            raise RuntimeError("'shiftDuringSweep' must be an integer")
        if type(shiftBetweenSweeps) is not int:
            raise RuntimeError("'shiftBetweenSweeps' must be an integer")
        if float(sweepOffObject) < 0 or float(sweepOffObject) > 1.0:
            raise RuntimeError("'sweepOffObject' should be a boolean, or floating point"
                               " number between 0 and 1")
        if order is not None:
            if 'image' not in order or 'sweep' not in order:
                raise RuntimeError("'order' must contain both 'image' and 'sweep'")
            if len([x for x in order if type(x) == str]) > 2:
                raise RuntimeError("'order' must contain no other strings besides "
                                   "'image' and 'sweep'")
            self.customOrder = True
        else:
            self.customOrder = False

        self.sweepDirections = sweepDirections
        self.shiftDuringSweep = shiftDuringSweep
        self.shiftBetweenSweeps = shiftBetweenSweeps
        self.sweepOffObject = sweepOffObject
        self.order = order
Example #4
0
    def __init__(self, replacement=True, start=0, equalizeCategories=False,
                 *args, **kwargs):
        """
        Args:
            replacement: Whether the same image can be picked multiple times.
            start: Number of random choices to skip at the beginning, useful
                   when seeding the random number generator.
        """
        BaseExplorer.__init__(self, *args, **kwargs)

        if type(replacement) not in (bool, int):
            raise RuntimeError("'replacement' should be a boolean")
        if type(start) is not int:
            raise RuntimeError("'start' should be an integer")

        self.replacement = replacement
        self.start = start
        self.equalizeCategories = equalizeCategories
        self.imagesByCat = None

        if not self.replacement:
            self.history = []
Example #5
0
    def __init__(self,
                 sweepDirections=["right", "down"],
                 shiftDuringSweep=1,
                 shiftBetweenSweeps=1,
                 sweepOffObject=False,
                 order=None,
                 *args,
                 **kwargs):
        """
        Args:
            sweepDirections: Directions for sweeping (a list containing one or
                             more of 'left', 'right', 'up', and 'down').
            shiftDuringSweep: Number of pixels to jump with each step (during a
                              sweep).
            shiftBetweenSweeps: Number of pixels to jump in between sweeps
                                (for example, when moving down a line after
                                sweeping across).
            sweepOffObject: Whether the sensor can only include a part of the
                            object, as specified by the bounding box. If False,
                            it will only move to positions that include as much
                            of the object as possible. If True, it will sweep
                            until all of the object moves off the sensor. If
                            set to a floating point number between 0 and 1,
                            then it will sweep until that fraction of the
                            object moves off the sensor.
            order: Order in which to iterate (outer to inner). Default progresses
                   through switching images, filters, and sweeping, where
                   switching images is the outer loop and sweeping is the inner
                   loop. Should be a list containing 'image', 'sweep', and
                   0, 1, ... numFilters-1.
        """
        BaseExplorer.__init__(self, *args, **kwargs)

        for direction in sweepDirections:
            if direction not in ('left', 'right', 'up', 'down'):
                raise RuntimeError("Unknown sweep direction: '%s'" % direction)
        if type(shiftDuringSweep) is not int:
            raise RuntimeError("'shiftDuringSweep' must be an integer")
        if type(shiftBetweenSweeps) is not int:
            raise RuntimeError("'shiftBetweenSweeps' must be an integer")
        if float(sweepOffObject) < 0 or float(sweepOffObject) > 1.0:
            raise RuntimeError(
                "'sweepOffObject' should be a boolean, or floating point"
                " number between 0 and 1")
        if order is not None:
            if 'image' not in order or 'sweep' not in order:
                raise RuntimeError(
                    "'order' must contain both 'image' and 'sweep'")
            if len([x for x in order if type(x) == str]) > 2:
                raise RuntimeError(
                    "'order' must contain no other strings besides "
                    "'image' and 'sweep'")
            self.customOrder = True
        else:
            self.customOrder = False

        self.sweepDirections = sweepDirections
        self.shiftDuringSweep = shiftDuringSweep
        self.shiftBetweenSweeps = shiftBetweenSweeps
        self.sweepOffObject = sweepOffObject
        self.order = order