Example #1
0
 def classify(self, data, output_file):
   out = open(output_file, 'w')
   batches = data.generate_batches(recurrent_net=self.network.recurrent,
                                   batch_size=data.num_timesteps, max_seqs=1)
   forwarder = ClassificationTaskThread(self.network, self.devices, data, batches)
   forwarder.join()
   print >> out, forwarder.output
   out.close()
Example #2
0
 def classify(self, data, output_file):
   out = open(output_file, 'w')
   batches = data.generate_batches(recurrent_net=self.network.recurrent,
                                   batch_size=data.num_timesteps, max_seqs=1)
   forwarder = ClassificationTaskThread(self.network, self.devices, data, batches)
   forwarder.join()
   print(forwarder.output, file=out)
   out.close()
Example #3
0
 def _classification_task(self, network, devices, data, batches):
     """
 Runs a classification task in an executor (async).
 :param network: Engine network.
 :param devices: Devices assigned to this engine.
 :param data: The data on which to classify.
 :param batches: Generated batches.
 :return:
 """
     # This will be executed in `executor` pool
     td = ClassificationTaskThread(network, devices, data, batches)
     td.join()
     return td
Example #4
0
  def forward_single(self, dataset, seq_idx, output_layer_name=None):
    """
    Forwards a single sequence.
    If you want to perform search, and get a number of hyps out, use :func:`search_single`.

    :param Dataset.Dataset dataset:
    :param int seq_idx:
    :param str|None output_layer_name: e.g. "output". if not set, will read from config "forward_output_layer"
    :return: numpy array, output in time major format (time,dim)
    :rtype: numpy.ndarray
    """

    batch = Batch()
    batch.init_with_one_full_sequence(seq_idx=seq_idx, dataset=dataset)
    batch_generator = iter([batch])
    batches = BatchSetGenerator(dataset, generator=batch_generator)

    forwarder = ClassificationTaskThread(self.network, self.devices, dataset, batches)
    forwarder.join()
    assert forwarder.output.shape[1] == 1
    return forwarder.output[:, 0]
Example #5
0
  def forward_single(self, dataset, seq_idx, output_layer_name=None):
    """
    Forwards a single sequence.
    If you want to perform search, and get a number of hyps out, use :func:`search_single`.

    :param Dataset.Dataset dataset:
    :param int seq_idx:
    :param str|None output_layer_name: e.g. "output". if not set, will read from config "forward_output_layer"
    :return: numpy array, output in time major format (time,dim)
    :rtype: numpy.ndarray
    """
    from EngineBatch import Batch, BatchSetGenerator
    batch = Batch()
    batch.init_with_one_full_sequence(seq_idx=seq_idx, dataset=dataset)
    batch_generator = iter([batch])
    batches = BatchSetGenerator(dataset, generator=batch_generator)

    forwarder = ClassificationTaskThread(self.network, self.devices, dataset, batches)
    forwarder.join()
    assert forwarder.output.shape[1] == 1
    return forwarder.output[:, 0]
Example #6
0
 def classification_task(self, network, devices, data, batches):
     #This will be executed in `executor` pool
     td = ClassificationTaskThread(network, devices, data, batches)
     td.join()
     return td