def _conv1x1_forward(conv, x, is_incremental): """Conv1x1 forward """ if is_incremental: x = conv.incremental_forward(x) else: x = conv(x) return x
def main(): move_old = load("move") auto_old = load("auto") on_old = load("on") superdecorate("CONVOLUTIONAL MAZE RUNNER ROBOT") imp(None, on_old) imp(auto_old, None) while(1): # Check if there is any change in mode or status on, auto = load("on"), load("auto") if(on != on_old): imp(None, on) if(auto != auto_old): imp(auto, None) while (load("on")=="1" and load("auto")=="1"): # Load Data decorate("Loading Data") coord = load("coord").split(' ') x0, y0 = int(coord[0]), int(coord[1]) x1, y1 = int(coord[2]), int(coord[3]) print("Starting Point: (" + str(x0) + "," + str(y0) + ")") print("Ending Point: (" + str(x1) + "," + str(y1) + ")") # Conv Neural Network decorate("Running Convolutional Neural Network") maze = conv(0) print("Walls detected:") print(maze) # A* Pathfinding Algorithm decorate("Running A* Pathfinding Algorithm") start = (x0, y0) end = (x1, y1) path = astar(maze, start, end) print("Shortest path found: " + str(path)) # Encoder decorate("Encoding Data") orders = encoder(path) print("Orders encoded: " + str(orders)) # Send orders via Bluetooth decorate("Sending orders to Robot") blue_auto(orders) print("Orders sent") # Change mode to OFF write("on",0) while (load("on")=="1" and load("auto")=="0"): # Load manual control move = load("move") if (move != move_old): imp(move, None) # Send orther via bluetoooth blue_manual(move) t.sleep(0.5) move_old = move t.sleep(0.5) on_old, auto_old = on, auto
#!/usr/bin/python from fft import * from conv import * from test import rnd_data import time n = 2**11 t0 = time.time() conv(rnd_data(n), rnd_data(n)) t1 = time.time() print t1-t0 t0 = time.time() conv_simple(rnd_data(n), rnd_data(n)) t1 = time.time() print t1-t0
def test_conv_returns_keras_sequential_model(): assert isinstance(conv(3, (28, 28, 1)), keras.engine.sequential.Sequential)
def test_conv_and_conv_simple_return_the_same(self): c1 = conv_simple(self.a, self.b) c2 = conv (self.a, self.b) for i in range(self.n): self.assertAlmostEqual(c1[i], c2[i])
train_and_adjust(training_inputs, training_outputs, training_epochs) ## THIS IS THE PLACE WHERE THE AI IS TESTED ########################################### ===================================================================================""" l1_filter = numpy.zeros((2, 3, 3)) # Creates 2 number filters, each with 3 rows and 3 columns l1_filter[0, :, :] = numpy.array([[[-1, 0, 1, ], # creates the first array detecting vertical edges [-1, 0, 1, ], [-1, 0, 1, ]]]) l1_filter[1, :, :] = numpy.array([[[1, 1, 1], # creates the second array detecting horizontal edges [0, 0, 0], [-1, -1, -1]]]) l1_feature_map = conv(image, l1_filter) # Convolves image according to conv function and the l1 filter l1_feature_map_relu = relu(l1_feature_map) l1_feature_map_relu_pool = pooling(l1_feature_map_relu, 2, 2) # Second conv layer l2_filter = numpy.random.rand(3, 5, 5, l1_feature_map_relu_pool.shape[-1]) print("\n**Working with conv layer 2**") l2_feature_map = conv(l1_feature_map_relu_pool, l2_filter) print("\n**ReLU**") l2_feature_map_relu = relu(l2_feature_map) print("\n**Pooling**")
img_gauss = np.zeros((img.shape[0], img.shape[1], 3)) if mode_conv == "valid": img_gauss = np.zeros( (img.shape[0] - len(kernel) + 1, img.shape[1] - len(kernel) + 1, 3)) sep_filter_0 = np.zeros((size, 1)) for i in range(size): sep_filter_0[i, 0] = Gauss_fun(sigma, i - size // 2) sep_filter_0 = sep_filter_0 / np.sum(sep_filter_0) sep_filter_1 = sep_filter_0.T img_gauss1d = img_gauss.copy() img_sharp = img_gauss.copy() img_bi = img_gauss.copy() for i in range(3): img_gauss[:, :, i] = conv(image=img[:, :, i], kernel=kernel, mode_conv=mode_conv, mode_padding=mode_padding) for i in range(3): img_bi[:, :, i] = Bilateral_Filter(image=img[:, :, i], sigma_s=sigma, sigma_r=sigma_r, size=size, mode_conv=mode_conv, mode_padding=mode_padding) for i in range(3): img_gauss1d[:, :, i] = conv(image=img[:, :, i], kernel=sep_filter_0, mode_conv=mode_conv, mode_padding=mode_padding) for i in range(3):