Giter VIP home page Giter VIP logo

deepracer-bayes-alignment's Introduction

Aligning DeepRacer Track Geometries with Bayesian Optimization

The AWS DeepRacer Virtual Circuit is run every month and recently the race courses are slight variations of the available training courses.

The race cource waypoints are not released to developers, which makes it difficult to evaluate logs of the track laps run on that private track.

Because the Training Track and Race Track are ~70% similar, and both are available as SVG, we can fit them together and generate a NumPy array for use in jupyter notebooks for analysis. I was able to achieve a pretty good result by hand, but it wasn't quite right. To improve this I used Bayesian Optimization to generate a good estimate of the Race Track NumPy oordinates.

Source and Results

Training Track SVG NumPy coordinates (provided)
Canada_Training.npy
Race Track SVG NumPy coordinates (Bayes generated)
canada_race.npy

Method

The tools I used are:

Goal: function to optimize

The function I wanted to optimize was the "fit" of the Race Track onto the Training Track. So the function is of the form:

f(scale, rotate, translate)

I found that the optimization runs much faster and results are more accurate if I narrowed the search boundaries. So I used the expected track length from the log files to find the exact scale and reduce the function to optimize down to:

f(rotate, translate)

Inputs: Starting Geometries

The optimization process started with Shapely geometrics,

Training Track: NumPy to Shapely LineString:

Race Track: SVG Path to NumPy array to Shapely LineString:

Prepare for Optimization

  1. Scale first since we know the desired centerline length:
from shapely import affinity

scale_factor = DESIRED_LENGTH / ls_source_center_line.length
ls_source_center_line = affinity.scale(ls_source_center_line, xfact=scale_factor, yfact=scale_factor)
  1. Align the shapes so they are overlapped, reducing the translation search space:
target_center = Polygon(ls_source_center_line).centroid
source_center = Polygon(ls_target_center_line).centroid
p_source = affinity.translate(p_source, 
                              xoff=(target_center.x - source_center.x),
                              yoff=(target_center.y - source_center.y))
  1. Set the bounds of optimization search:
minx, miny, maxx, maxy = p_target.bounds
mintx = minx - target_center.x
maxtx = maxx - target_center.x
minty = miny - target_center.y
maxty = maxy - target_center.y
pbounds = {
    'r': (-180,180),      # degree of rotation
    'x': (mintx, maxtx),  # centroid definitely won't move outside of target bounds
    'y': (minty, maxty)
}

Iterate

The function passed to the optimizer is

def coincident_area(r,x,y):
    global p_source
    global p_target
    p_source_t = affinity.translate(p_source, xoff=x, yoff=y)
    p_source_r = affinity.rotate(p_source_t, r, origin='centroid')
    intersection = p_source_r.intersection(p_target)
    difference = p_source_r.difference(p_target)
    return intersection.area - 20*difference.area # penalize overhang so optimization doesn't find some odd orientation that has largest overlap

I tried a few different functions and this one worked the best.

Result

The canada_race.npy file has the generated output, after converting the final shape to a NumPy array and save it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.