Ejemplo n.º 1
0
def the_method():
    if request.headers['Content-Type'] == 'text/plain':
        return "Text Message: " + request.data

    elif request.headers['Content-Type'] == 'application/json':
        return "JSON Message: " + json.dumps(request.json)

    elif request.headers['Content-Type'] == 'application/octet-stream':
        print(request.data)
        f = open('./binary', 'wb')
        f.write(request.data)
        f.close()
        return "Binary message written!"
    else:
        f = request.files['binarydata']
        f.seek(0)
        my_bytes = f.read()

        index = 0
        matrix = []
        row = []
        for byte in my_bytes:
            normalized = (float(byte) - 0) / (255 - 0)
            row.append(normalized)
            if (index % row_size == (row_size - 1)):
                matrix.append(row)
                row = []
            index = index + 1
        np_array = np.array([matrix], dtype=np.float64)

        print(np_array[0].shape)
        #print("np_array[0]. Type : {} | Value : {}".format(type(np_array[0][0][0]),np_array[0][0][0]))

        neural_network = NeuralNet(row_size, row_size)
        neural_network.load_model('StoredModel.modelconfig')

        arg_max, max_val = neural_network.predict_element(np_array)
        lb = labels_map[arg_max]
        print('ArgMax : {} | MaxVal : {} |Label : {}'.format(
            arg_max, max_val, lb))

        result = {
            'Confidence': max_val.item(),
            'Predicted': arg_max.item(),
            'Label': lb
        }
        return json.dumps(result)
Ejemplo n.º 2
0
import numpy as np
import sys
from neural import NeuralNet
from dataset import get_all_categories_shuffled, numpy_array_from_file, prepare_data

labels_dictionary = {'Circle': 0, 'L': 1, 'RightArrow': 2}
labels_map = ['Circle', 'L', 'RightArrow']

#Replace with your root folder that holds the dataset of images
all_bytes, all_labels = prepare_data("Datasets/DatasetSample0/Images",
                                     labels_dictionary, 56, 56)

nn = NeuralNet(56, 56)
nn.build_layers()
nn.fit_data(training_data=all_bytes,
            training_labels=all_labels,
            epochs=10,
            accuracy=0.999)
nn.save_model('easter_egg_ahlabikyafraise_')
#nn.load_model('easter_egg_ahlabikyafraise_')

image_path = sys.argv[1]
test_image = numpy_array_from_file(image_path)
test_image = test_image / 255

arg_max, prediction_level = nn.predict_element(test_image)
print('arg_max : {} which is {} with prediction : {}'.format(
    arg_max, labels_map[arg_max], prediction_level))