Beispiel #1
0
def testModel(predictionModel, predictionDataFile):
    predictionData = readTensorFromCSV(predictionDataFile)
    net = prediction.Batch()
    net.parameter.batchSize = predictionData.getDimensionSize(0)
    net.input.setModelInput(prediction.model, predictionModel)
    net.input.setTensorInput(prediction.data, predictionData)
    return net.compute()
Beispiel #2
0
def test(predictionModel, reader):
    """Tests AlexNet with given dataset reader"""

    # Create the neural network prediction algorithm
    net = prediction.Batch()

    # Set the prediction model retrieved from the training stage
    net.input.setModelInput(prediction.model, predictionModel)

    # Create auxiliary object to compute error rates (defined in services.h)
    errorRateCounter = ClassificationErrorCounter()

    # Reset reader's iterator the dataset begining
    reader.reset()

    batchCounter = 0

    # Advance dataset reader's iterator to the next batch
    while reader.next():

        batchCounter += 1

        # Set the input data batch to the neural network
        net.input.setTensorInput(prediction.data, reader.getBatch())

        # Compute the neural network forward pass
        net.compute()

        # Get tensor of predicted probailities for each class and update error rate
        predictionResult = net.getResult().getResult(prediction.prediction)
        errorRateCounter.update(predictionResult, reader.getGroundTruthBatch())

        print("{} test batches processed".format(batchCounter))

    return errorRateCounter.getTop5ErrorRate()
Beispiel #3
0
def test(predictionModel, testingData, testingGroundTruth):
    net = prediction.Batch()

    net.input.setModelInput(prediction.model, predictionModel)
    net.input.setTensorInput(prediction.data, testingData)

    predictionResult = net.compute()

    printPredictedClasses(predictionResult, testingGroundTruth)

    return predictionResult
Beispiel #4
0
    def predict(self, data, batch_size=None, rebuild=True):
        """Predicts labels based on a prediction model.

		Supported notation is ``with net.predict(...) as predictions:``

		Args:
			data (:obj:`daal.data_management.Tensor` or :obj:`numpy.ndarray`): Prediction data.
			batch_size (:obj:`int`): Batch size for processing prediction data.
			rebuild (:obj:`bool`): Control parameter to force rebuild of the model.

		Returns:
			:py:class:`pydaalcontrib.nn.DAALNet`: DAAL network with the evaluated predictions.   

		Raises:
			 ValueError: If the provided ``data`` are of the wrong type.
		"""
        if isinstance(data, np.ndarray):
            _data = HomogenTensor(data.copy(), ntype=data.dtype)
        elif not isinstance(data, Tensor):
            raise ValueError('Data is not of numpy.ndarray or Tensor type!')

        if not batch_size or batch_size > _data.getDimensionSize(0):
            batch_size = _data.getDimensionSize(0)

        if rebuild and self.do_rebuild:
            #TODO: refactor set rebuild=False once memory allocation is fixed on prediction in Intel DAAL 2018
            parameter = prediction.Parameter()
            parameter.batchSize = batch_size
            self.do_rebuild = False
            rebuild_args = {
                'data_dims': [batch_size] + _data.getDimensions()[1:],
                'parameter': parameter
            }
            self.model = self.build_model(self.descriptor,
                                          False,
                                          rebuild=rebuild_args,
                                          **self.build_args)
        elif 'train_result' in self.__dict__:
            self.model = self.train_result.get(
                training.model).getPredictionModel_Float32()

        net = prediction.Batch()
        net.parameter.batchSize = batch_size
        net.input.setModelInput(prediction.model, self.model)
        net.input.setTensorInput(prediction.data, _data)

        self.predictions = SubtensorDescriptor(ntype=data.dtype)
        self.predict_result = net.compute().getResult(prediction.prediction)
        self.predict_result.getSubtensor(
            [], 0, self.predict_result.getDimensionSize(0), readOnly,
            self.predictions)

        return self
def testModel(predictionModel):

    # Read testing data set from a .csv file and create a tensor to store input data
    predictionData = readTensorFromCSV(testDatasetFile)

    # Create an algorithm to compute the neural network predictions
    net = prediction.Batch()

    # Set the batch size for the neural network prediction
    net.parameter.batchSize = predictionData.getDimensionSize(0)

    # Set input objects for the prediction neural network
    net.input.setModelInput(prediction.model, predictionModel)
    net.input.setTensorInput(prediction.data, predictionData)

    # Run the neural network prediction
    return net.compute()