Example #1
0
def main():

    capture_layer = CaptureLayer()
    input_layer = InputLayer()
    control_layer = ControlLayer()

    main_loop = True

    capture_thread = Process(target=capture_layer.run_capture)
    serial_thread = Process(target=serial_control)

    capture_thread.start()
    serial_thread.start()
    last_busy = 1

    while main_loop:
        shape = capture_layer.marker_shape[:]

        input_layer.update(shape, motor_busy.value)

        control_layer.update(input_layer)
        control_vector[0:3] = control_layer.get_control_vector()

        if last_busy != motor_busy.value:
            last_busy = motor_busy.value
            print("BUSY" if motor_busy.value else "FREE")

        if control_vector[1] != 0:
            print("%d cm, %.1f deg" % (input_layer.distance_cm, input_layer.angle_deg)," "*8)
            print("desired %d cm = %d steps" % (control_layer.desired_cm, control_vector[1]),
                "conf: %.2f" % input_layer.distance_filter.confidence())

        sleep(0.020)
Example #2
0
    def __init__(self, userid):
        self.inputLayer = InputLayer()
        self.hiddenLayers = []
        self.outputLayer = OutputLayer()

        self.userid = userid
        self.outputs = []
Example #3
0
 def __init__(self, train_x, train_y, test_x, test_y):
     self.train_x = train_x
     self.train_y = train_y
     self.test_x = test_x
     self.test_y = test_y
     self.preprocess()
     self.input_layer = InputLayer(self.train_x.shape[1])
     self.output_layer = OutputLayer(len(self.train_y), self.input_layer)
     self.input_layer.prev_layer = self.output_layer
     self.accuracy = 0
     self.loss = 0
     self.add_layer(LayerDense(self.train_x.shape[1], 64))
     self.add_layer(LayerDense(64, 32))
     self.add_layer(LayerDense(32, len(self.train_y)))
     self.optimizer = OptimizerAdam(learning_rate=0.05, decay=5e-7)
def build_neural_network(opencl_context, inputs, targets, layers,
                         learning_rate, regulization):
    input_layer = InputLayer(inputs, opencl_context)
    model_layers = []
    model_layers.append(input_layer)
    for i in range(len(layers) - 1):
        layer = Layer(layers[i], np.tanh, learning_rate, regulization,
                      opencl_context)
        layer.link_prev(model_layers[-1])
        model_layers.append(layer)
    #add output layer
    layer = Layer(layers[-1], np.exp, learning_rate, regulization,
                  opencl_context)
    layer.link_prev(model_layers[-1])
    model_layers.append(layer)
    return model_layers
Example #5
0
 def __init__(self,
              layers,
              l2_decay=0.001,
              debug=False,
              learning_rate=0.001):
     super(Network, self).__init__()
     mapping = {
         "input": lambda x: InputLayer(x),
         "fc": lambda x: FullyConnectedLayer(x),
         "convolution": lambda x: ConvLayer(x),
         "pool": lambda x: MaxPoolLayer(x),
         "squaredloss": lambda x: SquaredLossLayer(x),
         "softmax": lambda x: SoftmaxLayer(x),
         "relu": lambda x: ReLULayer(x),
         "dropout": lambda x: DropoutLayer(x)
     }
     self.layers = []
     self.l2_decay = l2_decay
     self.debug = debug
     self.learning_rate = learning_rate
Example #6
0
 def __init__(self, n_input, n_output):
     self.input_layer = InputLayer(n_input)
     self.output_layer = OutputLayer(n_output, self.input_layer)
     self.input_layer.prev_layer = self.output_layer
     self.accuracy = 0
     self.loss = 0
Example #7
0
            round((random.uniform(0.4, 0.6)), 5) for _ in range(QUANTITY_INPUT)
        ]
        weight_relation_vector.append(t)

    return weight_relation_vector


if __name__ == '__main__':
    epoch = 10
    size_sample = 100
    quantity_cluster = 5

    output_layer = OutputLayer(form_weight_relation(quantity_cluster),
                               quantity_cluster)
    input_layer = InputLayer(form_sample(size_sample),
                             output_layer,
                             size_sample=size_sample)

    help_epoch = []
    help_function = []

    speed_function_start = 0.5
    delta_function_start = 0.5
    for i in range(epoch):
        delta_function = (-i / (epoch + 1) + 1)
        #delta_function = 1
        speed_function = speed_function_start * e**(i / epoch)
        k = input_layer.epoch(output_layer.weight_relation_vector,
                              output_layer.quantity_cluster, delta_function,
                              speed_function)
Example #8
0
File: net.py Project: ailadson/nn
 def __init__(self, num_units):
     self.layers = [InputLayer(num_units)]
Example #9
0
}

graph = topological_sort(feed_dict)
output = forward_pass(f, graph)
logging.info(output)
print(output)

# Layer
import numpy as np
from input_layer import InputLayer
from linear_layer import LinearLayer
from helper_layer import *

print("Layer Linear Transform")

inputs, weights, bias = InputLayer(), InputLayer(), InputLayer()
f = LinearLayer(inputs, weights, bias)

x = np.array([[-1., -2.], [-1, -2]])
w = np.array([[2., -3], [2., -3]])
b = np.array([-3., -5])

feed_dict = {inputs: x, weights: w, bias: b}

graph = topological_sort_layer(feed_dict)
output = forward_pass_layer(f, graph)
logging.info(output)
print(output)

# Sigmoid
from sigmoid import Sigmoid
Example #10
0
from neural_network import NeuralNetwork
from input_layer import InputLayer
from output_layer import OutputLayer
from hidden_layer import HiddenLayer

# test train xor function
model = NeuralNetwork(InputLayer(2), HiddenLayer(2, "sigmoid"),
                      OutputLayer(1, "sigmoid"))
train_input = [[1, 1], [1, 0], [0, 1], [0, 0]]
train_output = [0, 1, 1, 0]
model.train(train_input, train_output, 1, 0.1, 20)
model.predict([1, 1])
model.predict([1, 0])
model.predict([0, 1])
model.predict([0, 0])