Exemplo n.º 1
0
def test_one(protocol, variables):
    train = database.get(protocol, 'train', database.CLASSES, variables)
    norm = preprocessor.estimate_norm(numpy.vstack(train))
    train_normed = preprocessor.normalize(train, norm)
    trainer = algorithm.MultiClassTrainer()
    machine = trainer.train(train_normed)
    test = database.get(protocol, 'test', database.CLASSES, variables)
    test_normed = preprocessor.normalize(test, norm)
    test_predictions = machine.predict(numpy.vstack(test_normed))
    test_labels = algorithm.make_labels(test).astype(int)
    return analysis.CER(test_predictions, test_labels)
    def __init__(self, data, clf):
        training_data = data["training"]
        testing_data = data["test"]
        self.train = preprocessor.normalize(training_data[:, :-1])
        self.train_labels = training_data[:, -1:].reshape(training_data.shape[0], )
        # print(self.train_labels.shape)

        self.test = preprocessor.normalize(testing_data[:, :-1])
        self.test_labels = testing_data[:, -1:]
        self.confusion_matrix = np.zeros((2, 2))
        self.clf = clf
        self.accuracy = 0
        self.prediction_results = dict()
        self.failed_predictions = dict()
Exemplo n.º 3
0
def get_input(image, boxes):
    images = get_cropped_images(boxes, image)
    preprocessed_images = [
        normalize(images),
        preprocess(images, histogram_stretching),
        preprocess(images, histogram_equalization), boxes
    ]
    return preprocessed_images
Exemplo n.º 4
0
def get_preprocessed_images(images):
    images = [
        normalize(images),
        preprocess(images, histogram_stretching),
        preprocess(images, histogram_equalization)
    ]
    images = [
        np.array([resize(img, (256, 256)) for img in imgs]) for imgs in images
    ]
    return images
Exemplo n.º 5
0
def get_inputs(images, boxes):
    cropped_images = np.array([imgs for i in range(0, len(images)) for imgs in get_cropped_images(boxes[i], images[i])])
    flattened_boxes = np.array([values for _boxes in boxes for values in _boxes])

    preprocessed_images = [
        normalize(cropped_images),
        preprocess(cropped_images, histogram_stretching),
        preprocess(cropped_images, histogram_equalization),
        flattened_boxes
    ]
    return preprocessed_images
Exemplo n.º 6
0
def test_one(protocol, variables):
    """Runs one single test, returns the CER on the test set"""

    # 1. get the data from our preset API for the database
    train = database.get(protocol, "train", database.CLASSES, variables)

    # 2. preprocess the data using our module preprocessor
    norm = preprocessor.estimate_norm(numpy.vstack(train))
    train_normed = preprocessor.normalize(train, norm)

    # 3. trains our logistic regression system
    trainer = algorithm.MultiClassTrainer()
    machine = trainer.train(train_normed)

    # 4. applies the machine to predict on the 'unseen' test data
    test = database.get(protocol, "test", database.CLASSES, variables)
    test_normed = preprocessor.normalize(test, norm)
    test_predictions = machine.predict(numpy.vstack(test_normed))
    test_labels = algorithm.make_labels(test).astype(int)
    return analysis.CER(test_predictions, test_labels)
Exemplo n.º 7
0
def test_one(protocol, variables):
  """Runs one single test, returns the CER on the test set"""

  # 1. get the data from our preset API for the database
  train = database.get(protocol, 'train', database.CLASSES, variables)

  # 2. preprocess the data using our module preprocessor
  norm = preprocessor.estimate_norm(numpy.vstack(train))
  train_normed = preprocessor.normalize(train, norm)

  # 3. trains our logistic regression system
  trainer = algorithm.MultiClassTrainer()
  machine = trainer.train(train_normed)

  # 4. applies the machine to predict on the 'unseen' test data
  test = database.get(protocol, 'test', database.CLASSES, variables)
  test_normed = preprocessor.normalize(test, norm)
  test_predictions = machine.predict(numpy.vstack(test_normed))
  test_labels = algorithm.make_labels(test).astype(int)
  return analysis.CER(test_predictions, test_labels)
Exemplo n.º 8
0
def test1(pathToModel, Text):
    #generate Normalized text from given raw text
    fr = Text
    fw = open('normalizedTestText.txt', 'w', encoding='UTF-8')
    normalizedText = normalize(fr)
    #print(len(normalizedText[0]))
    first = True
    for sentence in normalizedText[0]:
        if (not first):
            fw.write('\n')
        first = False
        fw.write(sentence + '।')
    fw.close()
    #Generate feature values for the given text for testing
    directory = os.path.dirname(pathToModel) + '/Required/'
    featureSet = loadFeatureSet(directory + 'featureSet')
    labels = getLables(featureSet)
    fr = open('normalizedTestText.txt', 'r', encoding='UTF-8')
    featureValues = getFeatureValues(featureSet, fr.read())
    #load the model from disk
    model = pickle.load(open(pathToModel, 'rb'))
    featureVector = [featureValues]

    #Generate pandas dataSet for testing the model
    dataSet = pd.DataFrame.from_records(featureVector, columns=labels)
    x = dataSet[labels].values

    #get predicted result
    result = predict(model, x)

    #get class name map for getting actual name of the predicted class
    classNameMap = pickle.load(open(directory + 'classNameMap', 'rb'))
    """
	In testing module, after classNameMap loading and before returning do this,
	"""
    pred_prob = model.predict_proba(featureVector)
    proba_list = []
    proba_list.append(classNameMap[result[0]])
    for i in range(0, len(classNameMap)):
        proba_list.append(str(pred_prob[0][i]) + " " + str(classNameMap[i]))
    return proba_list
Exemplo n.º 9
0
 def process(self, trace, idx=-1):
     #TODO casting to int might screw floaters. however this is an unlikely scenario
     return preprocessor.normalize(
         trace, min=self.min, max=self.max, dst_type=self.dst_type)
Exemplo n.º 10
0
def preprocess_images(images):
    return normalize(np.array([resize(image, (100, 100)) for image in images]))
Exemplo n.º 11
0
 def process(self, trace, idx=-1):
     #TODO casting to int might screw floaters. however this is an unlikely scenario
     return preprocessor.normalize(trace,
                                   min=self.min,
                                   max=self.max,
                                   dst_type=self.dst_type)