Variational Generator

This commit is contained in:
Si11ium
2020-03-10 16:59:51 +01:00
parent 21e7e31805
commit 1b5a7dc69e
10 changed files with 177 additions and 95 deletions

View File

@ -18,10 +18,6 @@ import lib.variables as V
class Map(object):
# This setting is for Img mode "L" aka GreyScale Image; values: 0-255
white = 255
black = 0
def __copy__(self):
return copy.deepcopy(self)
@ -51,6 +47,7 @@ class Map(object):
def __init__(self, name='', array_like_map_representation=None):
if array_like_map_representation is not None:
array_like_map_representation = array_like_map_representation.astype(np.float32)
if array_like_map_representation.ndim == 2:
array_like_map_representation = np.expand_dims(array_like_map_representation, axis=0)
assert array_like_map_representation.ndim == 3
@ -70,7 +67,7 @@ class Map(object):
# Check pixels for their color (determine if walkable)
for idx, value in np.ndenumerate(self.map_array):
if value != self.black:
if value != V.BLACK:
# IF walkable, add node
graph.add_node(idx, count=0)
# Fully connect to all surrounding neighbors
@ -91,10 +88,9 @@ class Map(object):
if image.mode != 'L':
image = image.convert('L')
map_array = np.expand_dims(np.array(image), axis=0)
map_array = np.where(np.asarray(map_array) == cls.white, 1, 0)
if embedding_size:
assert isinstance(embedding_size, tuple), f'embedding_size was of type: {type(embedding_size)}'
embedding = np.zeros(embedding_size)
embedding = np.full(embedding_size, V.BLACK)
embedding[:map_array.shape[0], :map_array.shape[1], :map_array.shape[2]] = map_array
map_array = embedding
@ -146,12 +142,15 @@ class Map(object):
polyline = trajectory.xy_vertices
polyline.extend(reversed(other_trajectory.xy_vertices))
img = Image.new('L', (self.height, self.width), 0)
img = Image.new('L', (self.height, self.width), color=V.WHITE)
draw = ImageDraw.Draw(img)
draw.polygon(polyline, outline=1, fill=1)
draw.polygon(polyline, outline=V.BLACK, fill=V.BLACK)
a = (np.asarray(img) * np.where(self.as_2d_array == self.black, 1, 0)).sum()
binary_img = np.where(np.asarray(img).squeeze() == V.BLACK, 1, 0)
binary_map = np.where(self.as_2d_array == V.BLACK, 1, 0)
a = (binary_img * binary_map).sum()
if a:
return V.ALTERNATIVE # Non-Homotoph

View File

@ -42,9 +42,9 @@ class Trajectory(object):
return list(zip(self._vertices[:-1], self._vertices[1:]))
def draw_in_array(self, shape):
trajectory_space = np.zeros(shape)
trajectory_space = np.zeros(shape).astype(np.float32)
for index in self.vertices:
trajectory_space[index] = 1
trajectory_space[index] = V.WHITE
return trajectory_space
@property