Esempio n. 1
0
  def __init__(self, parent, network, numTopResults=5):
    NetworkInspector.__init__(self, parent, network)

    self.classifier = None

    # Find the classifier
    for element in _getElements(network):
      if 'categoriesOut' in element.spec.outputs:
        self.classifier = element
        break
    else:
      import warnings
      warnings.warn("No classifier found (no region with 'categoriesOut')",
          stacklevel=1)

    # Get the categoryInfo from the sensor
    sensor = _getElement(network, 'sensor')
    self.categoryInfo = _getSelf(sensor).getParameter('categoryInfo') \
        if _hasParameter(sensor, 'categoryInfo') else []

    # Truncate numTopResults based on number of categories
    numTopResults = min(numTopResults, len(self.categoryInfo))
    numTopResults = max(3, numTopResults)  # Absolute minimum
    self.numTopResults = numTopResults

    # Create the view
    self.traits_view = View(
      Item('inferenceResults', show_label=False,
        editor=InferenceResultsEditor(numTopResults=self.numTopResults))
    )
Esempio n. 2
0
    def __init__(self, parent, network, numTopResults=5):
        NetworkInspector.__init__(self, parent, network)

        self.classifier = None

        # Find the classifier
        for element in _getElements(network):
            if 'categoriesOut' in element.spec.outputs:
                self.classifier = element
                break
        else:
            import warnings
            warnings.warn(
                "No classifier found (no region with 'categoriesOut')",
                stacklevel=1)

        # Get the categoryInfo from the sensor
        sensor = _getElement(network, 'sensor')
        self.categoryInfo = _getSelf(sensor).getParameter('categoryInfo') \
            if _hasParameter(sensor, 'categoryInfo') else []

        # Truncate numTopResults based on number of categories
        numTopResults = min(numTopResults, len(self.categoryInfo))
        numTopResults = max(3, numTopResults)  # Absolute minimum
        self.numTopResults = numTopResults

        # Create the view
        self.traits_view = View(
            Item('inferenceResults',
                 show_label=False,
                 editor=InferenceResultsEditor(
                     numTopResults=self.numTopResults)))
  def __init__(self, parent, experiment, tierCount=0, showProgressBar=False,
               multipleDatasets=False, startImmediately=True):
    """
    """
    #title()
    self.experiment = experiment
    self.pause = True
    self.experiment.pause = True
    self.runCount = None

    network = experiment.network

    NetworkInspector.__init__(self, parent, network)

    self.tierCount = tierCount
    self.showProgressBar = showProgressBar
    self.multipleDatasets = multipleDatasets

    self.stopTarget = None
    self.iteration = 0
    self.iterationCount = 0
    self.usingPauseTarget = False
    self.stepping = False

    # Look for all sensors (regions without inputs)
    # If all sensors are of a supported type, seeking backward is supported
    # Otherwise, seeking backward is not supported, because not all sensors
    # can be run in reverse
    self.sensors = []
    for element in _getElements(self.network):
      if _isSensor(element):
        if element.type == 'VectorFileSensor':
          self.sensors.append(element)
        else:
          # Unsupported sensor type
          self.sensors = []
          break

    # Set the stop button label differently for training and testing
    # The stop button isn't shown at all if neither training nor testing, so
    # don't worry about that case
    if not self.tierCount and self.multipleDatasets:
      self.add_trait('stopButton', Button(label='Skip to next dataset'))
    else:
      self.add_trait('stopButton', Button(label='Stop training this tier'))


    # Set up the default pause target (next error), which the user will be
    # able to change later
    #self._createDefaultPauseTarget()
    #self.pauseTarget = self.defaultPauseTarget

    # Set up the Traits view
    self._createView()

    if startImmediately:
      self.start()  # Start running the network
  def __init__(self, parent, network):

    NetworkInspector.__init__(self, parent, network)

    # Find the classifier
    self.classifier = _findClassifier(network)
    if not self.classifier:
      raise RuntimeError("No classifier found (no region with 'categoriesOut')")

    # Get the categoryInfo from the sensor
    sensor = _getElement(network, 'sensor')
    self.categoryInfo = _getCategoryInfo(sensor)
    self.catNames = [cat[0] for cat in self.categoryInfo]

    # Acquire reference to the gabor region
    if 'GaborRegion' in _getRegionType(network, 'level1SP'):
      self._hasGabor = True
      self._gaborRegion = None
      self._gaborProxy = None
      gaborRegion = _getElement(network, VisionUtils.getTierName(1, network=network))
      if gaborRegion:
        self._gaborProxy = _getGaborProxy(gaborRegion)

      # Obtain gabor scales
      gaborInputDims = self._gaborProxy._inputDims
      baseWidth = float(gaborInputDims[0][1])
      self.scales = [float(dims[1])/baseWidth for dims in gaborInputDims]

      # Used to store cached gabor responses
      self._cachedResponses = {}
    else:
      self._gaborRegion = None
      self._hasGabor = False

    self.showTitle = False
    self.mode = 'unfiltered'
    self.filterOnCategory = False
    self.logDir = ""
    self._bboxes = None
    self._imageFilenames = None


    # Check if our classifier complies with the required API:
    self._compliantClassifier = _classifierComplies(self.classifier)
    if self._compliantClassifier:
      # Convert category labels to numpy
      c = _getSelf(self.classifier)
      categoryList = c.getCategoryList()
      if categoryList is None:
        categoryList = []
      self._catLabels = numpy.array(categoryList)
      self.numPrototypes = "Total Prototypes: %d" % len(self._catLabels)

    # Parameters that need to be handled with custom code in updateParameters
    customParameters = {
      'numPresentationsInLog': Str,
      'logDir': Str,
      # Used for displaying "Distance:"
      'dummy': Str
    }

    for name, trait in customParameters.iteritems():
      self.add_trait(name, trait(label=name))

    self._createDefaultImages()

    # Add traits
    if not self._hasGabor:
      availableSpaces = ['pixel']
    else:
      availableSpaces = ['pixel', 'gabor']

    for k in xrange(self._numNeighbors):
      for spaceType in availableSpaces:
        traitName = '%s%03d' % (spaceType, k)
        self.add_trait(traitName, Instance(PIL.Image.Image))
        exec "self.%s = self._missingImage" % traitName

      traitName = 'score%03d' % k
      self.add_trait(traitName, Str)
      protoScoreStr = self._makeScoreString()
      exec "self.%s = protoScoreStr" % traitName

      traitName = 'imagename%03d' % k
      self.add_trait(traitName, Str)
      imagename = ""
      exec "self.%s = imagename" % traitName

    self.createView()
Esempio n. 5
0
    def __init__(self, parent, network):

        NetworkInspector.__init__(self, parent, network)

        # Find the classifier
        self.classifier = _findClassifier(network)
        if not self.classifier:
            raise RuntimeError(
                "No classifier found (no region with 'categoriesOut')")

        # Get the categoryInfo from the sensor
        sensor = _getElement(network, 'sensor')
        self.categoryInfo = _getCategoryInfo(sensor)
        self.catNames = [cat[0] for cat in self.categoryInfo]

        # Acquire reference to the gabor region
        if 'GaborRegion' in _getRegionType(network, 'level1SP'):
            self._hasGabor = True
            self._gaborRegion = None
            self._gaborProxy = None
            gaborRegion = _getElement(
                network, VisionUtils.getTierName(1, network=network))
            if gaborRegion:
                self._gaborProxy = _getGaborProxy(gaborRegion)

            # Obtain gabor scales
            gaborInputDims = self._gaborProxy._inputDims
            baseWidth = float(gaborInputDims[0][1])
            self.scales = [
                float(dims[1]) / baseWidth for dims in gaborInputDims
            ]

            # Used to store cached gabor responses
            self._cachedResponses = {}
        else:
            self._gaborRegion = None
            self._hasGabor = False

        self.showTitle = False
        self.mode = 'unfiltered'
        self.filterOnCategory = False
        self.logDir = ""
        self._bboxes = None
        self._imageFilenames = None

        # Check if our classifier complies with the required API:
        self._compliantClassifier = _classifierComplies(self.classifier)
        if self._compliantClassifier:
            # Convert category labels to numpy
            c = _getSelf(self.classifier)
            categoryList = c.getCategoryList()
            if categoryList is None:
                categoryList = []
            self._catLabels = numpy.array(categoryList)
            self.numPrototypes = "Total Prototypes: %d" % len(self._catLabels)

        # Parameters that need to be handled with custom code in updateParameters
        customParameters = {
            'numPresentationsInLog': Str,
            'logDir': Str,
            # Used for displaying "Distance:"
            'dummy': Str
        }

        for name, trait in customParameters.iteritems():
            self.add_trait(name, trait(label=name))

        self._createDefaultImages()

        # Add traits
        if not self._hasGabor:
            availableSpaces = ['pixel']
        else:
            availableSpaces = ['pixel', 'gabor']

        for k in xrange(self._numNeighbors):
            for spaceType in availableSpaces:
                traitName = '%s%03d' % (spaceType, k)
                self.add_trait(traitName, Instance(PIL.Image.Image))
                exec "self.%s = self._missingImage" % traitName

            traitName = 'score%03d' % k
            self.add_trait(traitName, Str)
            protoScoreStr = self._makeScoreString()
            exec "self.%s = protoScoreStr" % traitName

            traitName = 'imagename%03d' % k
            self.add_trait(traitName, Str)
            imagename = ""
            exec "self.%s = imagename" % traitName

        self.createView()
    def __init__(self,
                 parent,
                 experiment,
                 tierCount=0,
                 showProgressBar=False,
                 multipleDatasets=False,
                 startImmediately=True):
        """
    """
        #title()
        self.experiment = experiment
        self.pause = True
        self.experiment.pause = True
        self.runCount = None

        network = experiment.network

        NetworkInspector.__init__(self, parent, network)

        self.tierCount = tierCount
        self.showProgressBar = showProgressBar
        self.multipleDatasets = multipleDatasets

        self.stopTarget = None
        self.iteration = 0
        self.iterationCount = 0
        self.usingPauseTarget = False
        self.stepping = False

        # Look for all sensors (regions without inputs)
        # If all sensors are of a supported type, seeking backward is supported
        # Otherwise, seeking backward is not supported, because not all sensors
        # can be run in reverse
        self.sensors = []
        for element in _getElements(self.network):
            if _isSensor(element):
                if element.type == 'VectorFileSensor':
                    self.sensors.append(element)
                else:
                    # Unsupported sensor type
                    self.sensors = []
                    break

        # Set the stop button label differently for training and testing
        # The stop button isn't shown at all if neither training nor testing, so
        # don't worry about that case
        if not self.tierCount and self.multipleDatasets:
            self.add_trait('stopButton', Button(label='Skip to next dataset'))
        else:
            self.add_trait('stopButton',
                           Button(label='Stop training this tier'))

        # Set up the default pause target (next error), which the user will be
        # able to change later
        #self._createDefaultPauseTarget()
        #self.pauseTarget = self.defaultPauseTarget

        # Set up the Traits view
        self._createView()

        if startImmediately:
            self.start()  # Start running the network