Exemplo n.º 1
0
def retrain(im1, im2):
    fp1 = open('im1.png', 'wb')
    fp1.write(base64.b64decode(im1))
    fp1.close()
    fp2 = open('im2.png', 'wb')
    fp2.write(base64.b64decode(im2))
    fp2.close()
    img1 = Image.open('im1.png')
    img1.load()
    data1 = np.asarray(img1, dtype="int32")

    img2 = Image.open('im2.png')
    img2.load()
    data2 = np.asarray(img2, dtype="int32")
    data1 = np.array(data1)
    data2 = np.array(data1)

    RESULT = np.copy(data2)
    ORIGINAL = np.copy(data1)
    [numRow, numCol] = RESULT.shape
    for x in range(numRow):
        dfs_iterative(RESULT, x, 0)
        dfs_iterative(RESULT, x, numCol - 1)

    for y in range(numCol):
        dfs_iterative(RESULT, 0, y)
        dfs_iterative(RESULT, numRow - 1, y)

    train = []
    target = []

    tile_size = 16
    # send this to configuration the 16
    for x in range(0, numRow - tile_size + 1, tile_size):
        for y in range(0, numCol - tile_size + 1, tile_size):
            temp = RESULT[x:x + tile_size, y:y + tile_size]
            if -1 not in temp:
                train.append(
                    (normalize(ORIGINAL[x:x + tile_size, y:y +
                                        tile_size])).transpose().flatten())
                if 0 in temp and 1 in temp:
                    target.append(1)
                else:
                    target.append(0)
    print(np.array(train).shape)
    print(np.array(target).shape)
    np.savetxt("fooI.csv", np.array(train), delimiter=",")
    np.savetxt("fooO.csv", np.array(target), delimiter=",")
Exemplo n.º 2
0
def retrain(im1, im2):
	fp1 = open('im1.png', 'wb')
	fp1.write(base64.b64decode(im1))
	fp1.close()
	fp2 = open('im2.png', 'wb')
	fp2.write(base64.b64decode(im2))
	fp2.close()
	img1 = Image.open('im1.png')
	img1.load()
	data1 = np.asarray( img1, dtype="int32")

	img2 = Image.open('im2.png')
	img2.load()
	data2 = np.asarray( img2, dtype="int32")
	data1 = np.array(data1)
	data2 = np.array(data1)


	RESULT = np.copy(data2)
	ORIGINAL = np.copy(data1)
	[numRow, numCol] = RESULT.shape
	for x in range(numRow):
		dfs_iterative(RESULT, x, 0)
		dfs_iterative(RESULT, x, numCol - 1)

	for y in range(numCol):
		dfs_iterative(RESULT, 0, y)
		dfs_iterative(RESULT, numRow - 1, y)

	train = []
	target = []

	tile_size = 16
	# send this to configuration the 16
	for x in range(0, numRow - tile_size + 1, tile_size):
		for y in range(0, numCol - tile_size + 1, tile_size):
			temp = RESULT[x:x + tile_size, y:y + tile_size]
			if -1 not in temp:
				train.append((normalize(ORIGINAL[x:x + tile_size, y:y + tile_size])).transpose().flatten())
				if 0 in temp and 1 in temp:
					target.append(1)
				else:
					target.append(0)
	print(np.array(train).shape)
	print(np.array(target).shape)
	np.savetxt("fooI.csv", np.array(train), delimiter=",")
	np.savetxt("fooO.csv", np.array(target), delimiter=",")
Exemplo n.º 3
0
	def test_overflow(self):
		size = 256
		MAT = np.zeros([size, size])
		# print(MAT)
		dfs_iterative(MAT, 0, 0)
Exemplo n.º 4
0
	def test_dfs_iterative(self):
		MAT = np.array([[0, 0, 0, 1], [0, 2, 0, 3], [0, 0, 0, 7], [1, 0, 2, 0]])
		dfs_iterative(MAT, 0, 3)
		dfs_iterative(MAT, 0, 2)
Exemplo n.º 5
0
    stdscr = curses.initscr()
    curses.cbreak()
    curses.noecho()
    curses.curs_set(False)
    curses.start_color()
    utils.initialize_colors()
else:
    stdscr = None

arguments = (stdscr, *utils.extract_all(sys.argv[1]), animated_flag)
result = choice

if choice == 'bfs':
    result = result, *bfs.bfs_iterative(*arguments)
elif choice == 'dfs':
    result = result, *dfs.dfs_iterative(*arguments)
elif choice == 'random':
    result = result, *random_search.random_search(*arguments)
elif choice == 'dijkstra':
    result = result, *dijkstra.dijkstra(*arguments)
elif choice == 'greedy':
    result = result, *greedy_search.greedy_search(*arguments)
elif choice == 'a-star':
    result = result, *a_star.a_star(*arguments)

if animated_flag:
    curses.curs_set(True)
    curses.echo()
    curses.nocbreak()
    curses.endwin()
Exemplo n.º 6
0
 def test_overflow(self):
     size = 256
     MAT = np.zeros([size, size])
     # print(MAT)
     dfs_iterative(MAT, 0, 0)
Exemplo n.º 7
0
 def test_dfs_iterative(self):
     MAT = np.array([[0, 0, 0, 1], [0, 2, 0, 3], [0, 0, 0, 7], [1, 0, 2,
                                                                0]])
     dfs_iterative(MAT, 0, 3)
     dfs_iterative(MAT, 0, 2)