Exemple #1
0
    def __init__(self,
                 full_dof=False,
                 use_finite_diff=True,
                 interpolation_method='cubic',
                 stamped_pose_only=False):
        """Class constructor."""
        self._logger = logging.getLogger('wp_trajectory_generator')
        out_hdlr = logging.StreamHandler(sys.stdout)
        out_hdlr.setFormatter(
            logging.Formatter(
                get_namespace().replace('/', '').upper() +
                ' -- %(asctime)s | %(levelname)s | %(module)s | %(message)s'))
        out_hdlr.setLevel(logging.INFO)
        self._logger.addHandler(out_hdlr)
        self._logger.setLevel(logging.INFO)

        self._path_generators = dict()
        self._logger.info('Waypoint interpolators available:')
        for gen in PathGenerator.get_all_generators():
            self._logger.info('\t - ' + gen.get_label())
            self._path_generators[gen.get_label()] = gen
            self._path_generators[gen.get_label()].set_full_dof(full_dof)
        # Time step between interpolated samples
        self._dt = None
        # Last time stamp
        self._last_t = None
        # Last interpolated point
        self._last_pnt = None
        self._this_pnt = None

        # Flag to generate only stamped pose, no velocity profiles
        self._stamped_pose_only = stamped_pose_only

        self._t_step = 0.001

        # Interpolation method
        self._interp_method = interpolation_method

        # True if the path is generated for all degrees of freedom, otherwise
        # the path will be generated for (x, y, z, yaw) only
        self._is_full_dof = full_dof

        # Use finite differentiation if true, otherwise use motion regression
        # algorithm
        self._use_finite_diff = use_finite_diff
        # Time window used for the regression method
        self._regression_window = 0.5
        # If the regression method is used, adjust the time step
        if not self._use_finite_diff:
            self._t_step = self._regression_window / 30

        # Flags to indicate that the interpolation process has started and
        # ended
        self._has_started = False
        self._has_ended = False

        # The parametric variable to use as input for the interpolator
        self._cur_s = 0

        self._init_rot = quaternion_about_axis(0.0, [0, 0, 1])
Exemple #2
0
    def __init__(self):
        self._map_frame = rospy.get_param('~map_frame', '/odom')
        self._path_topic = rospy.get_param('~path_topic', '/path')

        self._model_name = rospy.get_param('~gz_model_name', 'rosbot')
        self._reference_name = rospy.get_param('~gz_reference_frame', 'world')

        self._gazebo_state = GazeboState(self._model_name,
                                         self._reference_name)
        self._path_generator = PathGenerator()
        self._path_handler = PathsHandler(self._map_frame, self._path_topic)

        self._paths = rospy.get_param('~paths', [])
        self._path_idx = 0
        self._next_path = False
        self._next_path_srv = rospy.Service('next_path', Empty,
                                            self._next_path_cb)
    def __init__(self, full_dof=False, use_finite_diff=True,
                 interpolation_method='cubic',
                 stamped_pose_only=False):
        """Class constructor."""
        self._logger = logging.getLogger('wp_trajectory_generator')
        out_hdlr = logging.StreamHandler(sys.stdout)
        out_hdlr.setFormatter(logging.Formatter(
            get_namespace().replace('/', '').upper() + ' -- %(asctime)s | %(levelname)s | %(module)s | %(message)s'))
        out_hdlr.setLevel(logging.INFO)
        self._logger.addHandler(out_hdlr)
        self._logger.setLevel(logging.INFO)

        self._path_generators = dict()
        self._logger.info('Waypoint interpolators available:')
        for gen in PathGenerator.get_all_generators():
            self._logger.info('\t - ' + gen.get_label())
            self._path_generators[gen.get_label()] = gen
            self._path_generators[gen.get_label()].set_full_dof(full_dof)
        # Time step between interpolated samples
        self._dt = None
        # Last time stamp
        self._last_t = None
        # Last interpolated point
        self._last_pnt = None
        self._this_pnt = None

        # Flag to generate only stamped pose, no velocity profiles
        self._stamped_pose_only = stamped_pose_only

        self._t_step = 0.001

        # Interpolation method
        self._interp_method = interpolation_method

        # True if the path is generated for all degrees of freedom, otherwise
        # the path will be generated for (x, y, z, yaw) only
        self._is_full_dof = full_dof

        # Use finite differentiation if true, otherwise use motion regression
        # algorithm
        self._use_finite_diff = use_finite_diff
        # Time window used for the regression method
        self._regression_window = 0.5
        # If the regression method is used, adjust the time step
        if not self._use_finite_diff:
            self._t_step = self._regression_window / 30

        # Flags to indicate that the interpolation process has started and
        # ended
        self._has_started = False
        self._has_ended = False

        # The parametric variable to use as input for the interpolator
        self._cur_s = 0

        self._init_rot = quaternion_about_axis(0.0, [0, 0, 1])
Exemple #4
0
    def __init__(self, features_file, hand_features_file, hand_features_file2,
                 skus_file):
        self._model = keras.applications.vgg16.VGG16(weights='imagenet',
                                                     include_top=False,
                                                     input_shape=(224, 224, 3),
                                                     pooling='avg')
        self.graph = tf.get_default_graph()

        self._preprocess = keras.applications.vgg16.preprocess_input
        self._load_files(features_file, hand_features_file,
                         hand_features_file2, skus_file)
        self.path_generator = PathGenerator()
Exemple #5
0
    def __init__(self):

        rospy.init_node('global_planner')
        self.path_type = rospy.get_param('path_type', 1)
        
        self.path_pub = rospy.Publisher("/navigation/global_planner/path", Path, queue_size=10)
        self.debug = rospy.Publisher("/one_pose", PoseStamped, queue_size=5)
        self.debug2 = rospy.Publisher("/one_pose_2", PoseStamped, queue_size=5)

        # path generator class
        self.path_gen = PathGenerator()
        self.path = path_from_coordinates(self.path_gen.generator_rounded_path())

        rate = rospy.Rate(10)

        while not rospy.is_shutdown():

          self.path_pub.publish(self.path)
          #self.debug.publish(self.path.poses[8])
          #self.debug2.publish(self.path.poses[10])

          rate.sleep()
Exemple #6
0
def make_sn_fc_path_generator(latent_dim=128,
                              branches_per_layer=8,
                              img_size=28,
                              image_channels=1,
                              equal_split=False,
                              leak=0.0,
                              batch_norm='common',
                              **kwargs):
    def block_generator(in_feat, out_feat):
        def make_block():
            return nn.Sequential(nn.Linear(in_feat, out_feat),
                                 nn.LeakyReLU(leak))

        return make_block

    def last_layer_generator(out_dim):
        def make_last_layer():
            return nn.Linear(8 * WIDTH, out_dim)

        return make_last_layer

    img_shape = [image_channels, img_size, img_size]

    if not (isinstance(branches_per_layer, tuple)
            or isinstance(branches_per_layer, list)):
        branches_per_layer = [branches_per_layer] * 5

    normalization_module = nn.BatchNorm1d if batch_norm == 'common' else Identity
    model = nn.Sequential(
        BlocksBunch(block_generator(latent_dim, WIDTH),
                    branches_per_layer[0],
                    equal_split=equal_split), normalization_module(WIDTH),
        BlocksBunch(block_generator(WIDTH, 2 * WIDTH),
                    branches_per_layer[1],
                    equal_split=equal_split), normalization_module(2 * WIDTH),
        BlocksBunch(block_generator(2 * WIDTH, 4 * WIDTH),
                    branches_per_layer[2],
                    equal_split=equal_split), normalization_module(4 * WIDTH),
        BlocksBunch(block_generator(4 * WIDTH, 8 * WIDTH),
                    branches_per_layer[3],
                    equal_split=equal_split), normalization_module(8 * WIDTH),
        BlocksBunch(last_layer_generator(int(np.prod(img_shape))),
                    branches_per_layer[4],
                    equal_split=equal_split), nn.Tanh())

    return PathGenerator(model, [latent_dim], img_shape, **kwargs)
Exemple #7
0
    def __init__(self,
                 full_dof=False,
                 use_finite_diff=True,
                 interpolation_method='cubic_interpolator'):
        """Class constructor."""
        self._path_generators = dict()
        for gen in PathGenerator.get_all_generators():
            self._path_generators[gen.get_label()] = gen
            self._path_generators[gen.get_label()].set_full_dof(full_dof)
        # Time step between interpolated samples
        self._dt = None
        # Last time stamp
        self._last_t = None
        # Last interpolated point
        self._last_pnt = None
        self._this_pnt = None

        self._t_step = 0.001

        # Interpolation method
        self._interp_method = interpolation_method

        # True if the path is generated for all degrees of freedom, otherwise
        # the path will be generated for (x, y, z, yaw) only
        self._is_full_dof = full_dof

        # Use finite differentiation if true, otherwise use motion regression
        # algorithm
        self._use_finite_diff = use_finite_diff
        # Time window used for the regression method
        self._regression_window = 0.5
        # If the regression method is used, adjust the time step
        if not self._use_finite_diff:
            self._t_step = self._regression_window / 30

        # Flags to indicate that the interpolation process has started and
        # ended
        self._has_started = False
        self._has_ended = False

        # The parametric variable to use as input for the interpolator
        self._cur_s = 0
Exemple #8
0
def make_mnist_path_generator(latent_dim=100,
                              branches_per_layer=8,
                              img_size=28,
                              constant_noise=True,
                              backprop_noise=False):
    def block_generator(in_feat, out_feat, normalize=True):
        def make_block():
            layers = [nn.Linear(in_feat, out_feat)]
            if normalize:
                layers.append(nn.BatchNorm1d(out_feat, 0.8))
            layers.append(nn.LeakyReLU(0.2, inplace=True))
            return torch.nn.Sequential(*layers)

        return make_block

    def last_layer_generator(out_dim):
        def make_last_layer():
            return nn.Linear(1024, out_dim)

        return make_last_layer

    img_shape = [1, img_size, img_size]

    if branches_per_layer is not tuple or branches_per_layer is not list:
        branches_per_layer = [branches_per_layer] * 5
    model = nn.Sequential(
        BlocksBunch(block_generator(latent_dim, 128, normalize=False),
                    branches_per_layer[0]),
        BlocksBunch(block_generator(128, 256, normalize=False),
                    branches_per_layer[1]),
        BlocksBunch(block_generator(256, 512, normalize=False),
                    branches_per_layer[2]),
        BlocksBunch(block_generator(512, 1024, normalize=False),
                    branches_per_layer[3]),
        BlocksBunch(last_layer_generator(int(np.prod(img_shape))),
                    branches_per_layer[4]), nn.Tanh())

    return PathGenerator(model, [latent_dim],
                         img_shape,
                         constant_noise=constant_noise,
                         backprop_noise=backprop_noise)
def build_dictionary():
    block_blob_service = BlockBlobService(
        account_name='hackathonnetshoes',
        account_key=
        '1syRJGXjNT8s3eZR1lCLTuo7OCDm6LfMDAMNh1ej8Krs8mpwy3EeheTq1bnXCehOTIo0Glffu5MKZhskULys6A=='
    )
    generator = block_blob_service.list_blobs('hackthonns')
    path_generator = PathGenerator()
    idx = 0

    with open('../../grupo2storage2/features/hand_crafted/features.pickle',
              'wb') as features_handle:
        with open('../../grupo2storage2/features/hand_crafted/skus.pickle',
                  'wb') as sku_handle:

            for blob in generator:
                if (not blob.name.endswith('.jpg')):
                    continue

                if ('produtos' not in blob.name):
                    continue

                print('[{0}] processing {1}'.format(
                    idx, os.path.basename(blob.name)))
                blob = block_blob_service.get_blob_to_bytes(
                    'hackthonns', blob.name)

                image_file_in_mem = io.BytesIO(blob.content)
                inputShape = (300, 300)
                img = load_img(image_file_in_mem)
                image = img_to_array(img)
                feature = extract_feature(image, path_generator)

                sku = os.path.basename(blob.name).split(".")[0]
                pickle.dump(feature,
                            features_handle,
                            protocol=pickle.HIGHEST_PROTOCOL)
                pickle.dump(sku, sku_handle, protocol=pickle.HIGHEST_PROTOCOL)
                idx += 1
Exemple #10
0
class PathPublisher:
    def __init__(self):
        self._map_frame = rospy.get_param('~map_frame', '/odom')
        self._path_topic = rospy.get_param('~path_topic', '/path')

        self._model_name = rospy.get_param('~gz_model_name', 'rosbot')
        self._reference_name = rospy.get_param('~gz_reference_frame', 'world')

        self._gazebo_state = GazeboState(self._model_name,
                                         self._reference_name)
        self._path_generator = PathGenerator()
        self._path_handler = PathsHandler(self._map_frame, self._path_topic)

        self._paths = rospy.get_param('~paths', [])
        self._path_idx = 0
        self._next_path = False
        self._next_path_srv = rospy.Service('next_path', Empty,
                                            self._next_path_cb)

    def start(self):
        rospy.sleep(2)

        while not rospy.is_shutdown():
            if self._next_path:
                self._gazebo_state.reset()
                path = self._paths[self._path_idx]
                x, y, yaw = self._path_generator.generate(path)
                self._path_handler.publish(x, y, yaw)
                self._path_idx = 0 if (self._path_idx
                                       == (len(self._paths) -
                                           1)) else (self._path_idx + 1)
                self._next_path = False

    def _next_path_cb(self, req):
        self._next_path = True
        return EmptyResponse()
 def interpolator_tags(self):
     return [gen.get_label() for gen in PathGenerator.get_all_generators()]
Exemple #12
0
def make_conv_path_generator(latent_dim=128,
                             branches_per_layer=8,
                             img_size=64,
                             upsamples=3,
                             batch_norm=False,
                             equal_split=False,
                             leak=0.0,
                             **kwargs):
    def linear_layer_generator(in_dim, out_dim):
        def make_layer():
            layer = nn.Linear(in_dim, out_dim)
            return layer

        return make_layer

    def upconv_layer_generator(input_channels, out_channels, kernel):
        def make_layer():
            layer = nn.ConvTranspose2d(input_channels,
                                       out_channels,
                                       kernel,
                                       stride=2,
                                       padding=1)
            torch.nn.init.kaiming_uniform_(layer.weight)
            return layer

        return make_layer

    if not (isinstance(branches_per_layer, list)
            or isinstance(branches_per_layer, tuple)):
        branches_per_layer = [branches_per_layer] * (1 + upsamples)

    relu = nn.LeakyReLU(leak, True)
    crop = Crop([1, 1])

    # I input linear
    linear_out_dim = 2**(upsamples - 1) * 4 * 4 * DIM

    linear = BlocksBunch(linear_layer_generator(latent_dim, linear_out_dim),
                         branches_per_layer[0],
                         equal_split=equal_split)

    reshape = Reshape([-1, 2**(upsamples - 1) * DIM, 4, 4])
    bn = nn.BatchNorm1d(linear_out_dim) if batch_norm else Identity()
    input = nn.Sequential(linear, bn, relu, reshape)

    # II upsampling
    upconvs = []
    for i in range(upsamples):
        in_channels = 2**(upsamples - 1 - i) * DIM
        out_channels = in_channels // 2 if i < upsamples - 1 else 3

        upconvs.append(
            BlocksBunch(upconv_layer_generator(in_channels,
                                               out_channels,
                                               kernel=5),
                        branches_per_layer[i + 1],
                        equal_split=equal_split))

        if i < upsamples - 1:
            if batch_norm:
                upconvs.append(nn.BatchNorm2d(out_channels))
            upconvs.append(relu)
        upconvs.append(crop)
    upconvs.append(nn.Tanh())

    model = nn.Sequential(*([input] + upconvs))
    return PathGenerator(model, [latent_dim], [3, img_size, img_size],
                         **kwargs)
from path_generator import PathGenerator
from visibility.graphs import Graphs
import math
import matplotlib.pyplot as plt
from utils.config import Configurator
from pathlib import Path
import os
import cProfile

graphs = Graphs()
g = graphs.get_graph(complexity=12)
file_path = Path(__file__)

config_fn = 'default.yaml'
yaml_fp = os.path.join(str(file_path.parent.parent), 'configs', config_fn)
configurator = Configurator(yaml_fp)
config = configurator.configurate()

path_gen = PathGenerator(config, build=False, sinus_object=True)

start = list(g.start)
end = list(g.end)
xx,xy,uv,uomega,tot_solver_time,overhead_times = path_gen.run(g, start, end)

path_gen.plot_results(xx,xy,uv,uomega, start, end, dynamic=True, video=False)
plt.show()
 def interpolator_tags(self):
     return [gen.get_label() for gen in PathGenerator.get_all_generators()]
Exemple #15
0
def init(map_file, maneuvers_file, sign_file):
    global path_gen
    path_gen = PathGenerator(
        map_file, maneuvers_file,
        sign_file)  # global variable, load this module once
Exemple #16
0
from path_generator import PathGenerator
from urllib import request
from PIL import Image
import requests
import json
import numpy as np

SUBSCRIPTION_KEY = 'dfcc754dec614553a36066c96ab7f0b3'
BASE_URI = 'https://api.cognitive.microsoft.com/bing/v7.0/images/visualsearch'
STORAGE_URI = 'https://grupo2storage2.blob.core.windows.net/grupo2cont/search'

path_generator = PathGenerator()

class Croper:
    def __init__(self, data_path, temp_path):
        self.data_path = data_path
        self.temp_path = temp_path

    def print_json(obj):
        """Print the object as json"""
        print(json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': ')))

    def calculate_bounding_box_coordinates(self, float_top_left, float_bottom_right, shape):
        int_top_left = (int(shape[1] * float_top_left['x']), int(shape[0] * float_top_left['y']))
        int_bottom_right = (int(shape[1] * float_bottom_right['x']), int(shape[0] * float_bottom_right['y']))
        return (int_top_left, int_bottom_right)

    def crop_image_products(self, img, products_visual_search):
        products_visual_search['croppedProduct'] = []
        for idx, ((top_left_x, top_left_y), (bottom_right_x, bottom_right_y)) in enumerate(
                products_visual_search['boundingBox']):
Exemple #17
0
import numpy as np
import matplotlib.pyplot as plt
from utils.config import Configurator
from pathlib import Path
import os

graphs = Graphs()
file_path = Path(__file__)

config_fn = 'default.yaml'
yaml_fp = os.path.join(str(file_path.parent.parent), 'configs', config_fn)
configurator = Configurator(yaml_fp)
config = configurator.configurate()

runtime = []
overhead = []
for i in range(1, 12):
    print(f'STARTING NUMBER {i}')
    path_gen = PathGenerator(config, build=False)
    g = graphs.get_graph(complexity=i)
    start = list(g.start)
    end = list(g.end)
    xx, xy, uv, uomega, solver_times, overhead_times = path_gen.run(
        g, start, end)
    loop_times = [x + y for x, y in zip(solver_times, overhead_times)]
    overhead += overhead_times
    runtime += solver_times

loop = [x + y for x, y in zip(overhead, runtime)]
path_gen.plot_solver_hist(loop)
plt.show()
def generate_plot(config_filename):

    yaml_fp = os.path.join(str(file_path.parent.parent), 'configs',
                           config_filename)

    configurator = Configurator(yaml_fp)
    config = configurator.configurate()

    path_gen = PathGenerator(config, build=False)

    start = list(g.start)
    end = list(g.end)
    xx, xy, uv, uomega, _, _ = path_gen.run(g, start, end)

    fig, ax = plt.subplots(2, 1)
    fig.set_figheight(6)
    fig.set_figwidth(10)

    vel_ax = ax[0]
    path_gen.mpc_generator.plot_vel(vel_ax, uv)
    #vel_ax.set_xlabel('Time [s]')
    vel_ax.set_ylabel('Linear elocity [m/s]')
    vel_ax.legend(['Linear velocity'])
    vel_ax.grid('on')

    omega_ax = ax[1]
    path_gen.mpc_generator.plot_omega(omega_ax, uomega)
    omega_ax.set_xlabel('Time [s]')
    omega_ax.set_ylabel('Angular velocity [rad/s]')
    omega_ax.legend(['Angular velocity'])
    omega_ax.grid('on')

    fig2, ax2 = plt.subplots(1, 1)
    fig2.set_figheight(15)
    fig2.set_figwidth(15)
    path_ax = ax2
    path_gen.ppp.plot_all(path_ax)
    path_ax.plot(xx, xy, c='b', label='Path', marker='o', alpha=0.5)
    path_ax.plot(start[0], start[1], marker='*', color='g', markersize=15)
    path_ax.plot(end[0], end[1], marker='*', color='r', markersize=15)

    path_ax.set_xlabel('X [m]', fontsize=12)
    path_ax.set_ylabel('Y [m]', fontsize=12)

    legend_elems = [
        Line2D([0], [0], color='k', label='Original Boundary'),
        Line2D([0], [0], color='g', label='Padded Boundary'),
        Line2D([0], [0], color='r', label='Original Obstacles'),
        Line2D([0], [0], color='b', label='Padded Obstacles'),
        Line2D([0], [0], linestyle='--', color='k', label='A-Star Path'),
        Line2D([0], [0],
               marker='o',
               color='b',
               label='Generated Path',
               alpha=0.5),
        Line2D([0], [0], color='r', marker='*', label='Start Position'),
        Line2D([0], [0], color='g', marker='*', label='End Position'),
    ]

    path_ax.legend(handles=legend_elems)
    path_ax.axis('equal')

    fig.savefig(os.path.join(folder_name,
                             config_filename + f'_vel_omega_{str(t)}.png'),
                dpi=600,
                format='png')
    fig2.savefig(os.path.join(folder_name,
                              config_filename + f'_path_{str(t)}.png'),
                 dpi=600,
                 format='png')

    plt.close('all')
Exemple #19
0
def make_sn_conv32_path_generator(latent_dim=128,
                                  branches_per_layer=8,
                                  img_size=64,
                                  batch_norm='none',
                                  equal_split=False,
                                  leak=0.0,
                                  seed_dim=4,
                                  first_linear=True,
                                  **kwargs):
    def linear_layer_gen(in_dim, out_dim):
        def make_linear_layer():
            return nn.Linear(in_dim, out_dim)

        return make_linear_layer

    def upconv_layer_gen(in_channels,
                         out_channels,
                         kernel,
                         stride,
                         padding=(0, 0)):
        def make_upconv_layer():
            if batch_norm == 'per_block':
                bn = nn.BatchNorm2d(out_channels)
            elif batch_norm == 'lazy':
                bn = LazyBatchNorm(out_channels)
            else:
                bn = Identity()

            return nn.Sequential(
                nn.ConvTranspose2d(in_channels,
                                   out_channels,
                                   kernel_size=kernel,
                                   stride=stride,
                                   padding=padding),
                bn,
            )

        return make_upconv_layer

    def make_blocks_bunch(in_channels,
                          out_channels,
                          blocks,
                          kernel,
                          stride,
                          padding=(0, 0)):
        bn = nn.BatchNorm2d(
            out_channels) if batch_norm == 'common' else Identity()
        return nn.Sequential(
            BlocksBunch(
                upconv_layer_gen(in_channels, out_channels, kernel, stride,
                                 padding), blocks, equal_split),
            bn,
            nn.LeakyReLU(leak),
        )

    if not (isinstance(branches_per_layer, list)
            or isinstance(branches_per_layer, tuple)):
        branches_per_layer = [branches_per_layer] * 5

    if first_linear:
        first_layer = [
            BlocksBunch(
                linear_layer_gen(latent_dim, seed_dim * seed_dim * 512),
                branches_per_layer[0], equal_split),
            Reshape([-1, 512, seed_dim, seed_dim])
        ]
    else:
        first_layer = [
            make_blocks_bunch(latent_dim, 512, branches_per_layer[0], 4, 1)
        ]

    model = nn.Sequential(*(first_layer + [
        make_blocks_bunch(512, 256, branches_per_layer[1], 4, 2, (1, 1)),
        make_blocks_bunch(256, 128, branches_per_layer[2], 4, 2, (1, 1)),
        make_blocks_bunch(128, 64, branches_per_layer[3], 4, 2, (1, 1)),
        BlocksBunch(upconv_layer_gen(64, 1, 3, 1, (
            1, 1)), branches_per_layer[4], equal_split),
        nn.Tanh()
    ]))

    latent_dim = [latent_dim] if first_linear else [latent_dim, 1, 1]
    return PathGenerator(model, latent_dim, [1, img_size, img_size], **kwargs)
Exemple #20
0
def make_resnet_generator(resnet_gen_config,
                          latent_dim=128,
                          branches_per_layer=8,
                          img_size=128,
                          batch_norm='none',
                          equal_split=False,
                          leak=0.0,
                          image_channels=3,
                          **kwargs):
    def make_dense():
        dense = nn.Linear(
            latent_dim,
            resnet_gen_config.seed_dim**2 * resnet_gen_config.channels[0])
        nn.init.xavier_uniform_(dense.weight.data, 1.)
        return dense

    def make_final():
        final = nn.Conv2d(resnet_gen_config.channels[-1],
                          image_channels,
                          3,
                          stride=1,
                          padding=1)
        nn.init.xavier_uniform_(final.weight.data, 1.)
        return final

    def res_block_gen(in_channels, out_channels, batch_norm):
        if batch_norm == 'lazy':
            batch_norm = LazyBatchNorm
        elif batch_norm == 'per_block':
            batch_norm = nn.BatchNorm2d
        else:
            batch_norm = None

        def make_res_block():
            return ResBlockGenerator(in_channels,
                                     out_channels,
                                     batch_norm=batch_norm,
                                     leak=leak)

        return make_res_block

    channels = resnet_gen_config.channels
    if isinstance(branches_per_layer, int):
        branches_per_layer = [branches_per_layer] * (len(channels) + 1)

    input_layers = [
        BlocksBunch(make_dense, branches_per_layer[0],
                    equal_split=equal_split),
        Reshape([-1, channels[0], 4, 4])
    ]
    res_blocks = [
        BlocksBunch(res_block_gen(channels[i], channels[i + 1], batch_norm),
                    branches_per_layer[i + 1],
                    equal_split=equal_split) for i in range(len(channels) - 1)
    ]
    out_layers = [
        nn.BatchNorm2d(channels[-1]),
        nn.ReLU(),
        BlocksBunch(make_final,
                    branches_per_layer[-1],
                    equal_split=equal_split),
        nn.Tanh()
    ]

    model = nn.Sequential(*(input_layers + res_blocks + out_layers))

    return PathGenerator(model, [latent_dim],
                         [image_channels, img_size, img_size], **kwargs)
import math
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import matplotlib.patches as mpatches
from utils.config import Configurator
from pathlib import Path
import os
import time

file_path = Path(__file__)
yaml_fp = os.path.join(str(file_path.parent.parent), 'configs', 'jconf_3.yaml')

configurator = Configurator(yaml_fp)
config = configurator.configurate()

path_gen = PathGenerator(config, build=False)

graphs = Graphs()
g = graphs.get_graph(complexity=9)

start = list(g.start)
end = list(g.end)

xx, xy, uv, uomega, _, _ = path_gen.run(g, start, end)

fig, ax = plt.subplots(2, 1)
fig.set_figheight(6)
fig.set_figwidth(10)

vel_ax = ax[0]
path_gen.mpc_generator.plot_vel(vel_ax, uv)