def save_global_record(route_record, sensors, endpoint): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() stats_dict = route_record.__dict__ data['_checkpoint']['global_record'] = stats_dict data['values'] = [ '{:.3f}'.format(stats_dict['scores']['score_composed']), '{:.3f}'.format(stats_dict['scores']['score_route']), '{:.3f}'.format(stats_dict['scores']['score_penalty']), # infractions '{:.3f}'.format(stats_dict['infractions']['collisions_layout']), '{:.3f}'.format( stats_dict['infractions']['collisions_pedestrian']), '{:.3f}'.format(stats_dict['infractions']['collisions_vehicle']), '{:.3f}'.format(stats_dict['infractions']['outside_route_lanes']), '{:.3f}'.format(stats_dict['infractions']['red_light']), '{:.3f}'.format(stats_dict['infractions']['route_dev']), '{:.3f}'.format(stats_dict['infractions']['stop_infraction']), '{:.3f}'.format(stats_dict['infractions']['route_timeout']), '{:.3f}'.format(stats_dict['infractions']['vehicle_blocked']) ] data['labels'] = [ 'avg. total score', 'avg. route score', 'avg. infraction penalty', 'collisions with layout', 'collisions with pedestrians', 'collisions with vehicles', 'off-road infractions', 'red lights infractions', 'route deviation infractions', 'stop sign infractions', 'timeouts', 'vehicle blocked' ] data['sensors'] = sensors save_dict(endpoint, data)
def save_state(self, endpoint): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() data['_checkpoint']['progress'] = [self._index, self.total] save_dict(endpoint, data)
def save_global_record(route_record, sensors, total_routes, endpoint): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() stats_dict = route_record.__dict__ data['_checkpoint']['global_record'] = stats_dict data['values'] = ['{:.3f}'.format(stats_dict['scores']['score_composed']), '{:.3f}'.format(stats_dict['scores']['score_route']), '{:.3f}'.format(stats_dict['scores']['score_penalty']), # infractions '{:.3f}'.format(stats_dict['infractions']['collisions_pedestrian']), '{:.3f}'.format(stats_dict['infractions']['collisions_vehicle']), '{:.3f}'.format(stats_dict['infractions']['collisions_layout']), '{:.3f}'.format(stats_dict['infractions']['red_light']), '{:.3f}'.format(stats_dict['infractions']['stop_infraction']), '{:.3f}'.format(stats_dict['infractions']['outside_route_lanes']), '{:.3f}'.format(stats_dict['infractions']['route_dev']), '{:.3f}'.format(stats_dict['infractions']['route_timeout']), '{:.3f}'.format(stats_dict['infractions']['vehicle_blocked']) ] data['labels'] = ['Avg. driving score', 'Avg. route completion', 'Avg. infraction penalty', 'Collisions with pedestrians', 'Collisions with vehicles', 'Collisions with layout', 'Red lights infractions', 'Stop sign infractions', 'Off-road infractions', 'Route deviations', 'Route timeouts', 'Agent blocked' ] entry_status = "Finished" eligible = "True" route_records = data["_checkpoint"]["records"] progress = data["_checkpoint"]["progress"] if progress[1] != total_routes: raise Exception('Critical error with the route registry.') if len(route_records) != total_routes or progress[0] != progress[1]: entry_status = "Finished with missing data" eligible = "False" else: for route in route_records: route_status = route["status"] if "Agent crashed" in route_status: entry_status = "Finished with agent errors" break data['entry_status'] = entry_status data['eligible'] = eligible save_dict(endpoint, data)
def resume(self, endpoint): data = fetch_dict(endpoint) if data and dictor(data, '_checkpoint.records'): records = data['_checkpoint']['records'] for record in records: self._registry_route_records.append(to_route_record(record))
def save_entry_status(entry_status, eligible, endpoint): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() data['entry_status'] = entry_status data['eligible'] = eligible save_dict(endpoint, data)
def save_sensors(sensors, endpoint): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() if not data['sensors']: data['sensors'] = sensors save_dict(endpoint, data)
def resume(self, endpoint): data = fetch_dict(endpoint) if data: checkpoint_dict = dictor(data, '_checkpoint') if checkpoint_dict and 'progress' in checkpoint_dict: current_route, total_routes = checkpoint_dict['progress'] if current_route <= self.total: self._index = current_route else: print('Problem reading checkpoint. Route id {} ' 'larger than maximum number of routes {}'.format( current_route, self.total))
def save_record(route_record, index, endpoint): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() stats_dict = route_record.__dict__ record_list = data['_checkpoint']['records'] if index > len(record_list): print('Error! No enough entries in the list') sys.exit(-1) elif index == len(record_list): record_list.append(stats_dict) else: record_list[index] = stats_dict save_dict(endpoint, data)
def save_global_record(route_record, sensors, endpoint): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() stats_dict = route_record.__dict__ data['_checkpoint']['global_record'] = stats_dict data['values'] = [ '{:.3f}'.format(stats_dict['scores']['score_composed']), '{:.3f}'.format(stats_dict['scores']['score_route']), '{:.3f}'.format(stats_dict['scores']['score_penalty']), # infractions '{:.3f}'.format(stats_dict['infractions']['collisions_pedestrian'] ), '{:.3f}'.format(stats_dict['infractions']['collisions_vehicle']), '{:.3f}'.format(stats_dict['infractions']['collisions_layout']), '{:.3f}'.format(stats_dict['infractions']['red_light']), '{:.3f}'.format(stats_dict['infractions']['stop_infraction']), '{:.3f}'.format(stats_dict['infractions']['outside_route_lanes']), '{:.3f}'.format(stats_dict['infractions']['route_dev']), '{:.3f}'.format(stats_dict['infractions']['route_timeout']), '{:.3f}'.format(stats_dict['infractions']['vehicle_blocked']), # addition: new event '{:.3f}'.format(stats_dict['infractions']['on_sidewalk']), '{:.3f}'.format(stats_dict['infractions']['off_road']), '{:.3f}'.format( stats_dict['infractions']['outside_lane_infraction']), '{:.3f}'.format(stats_dict['infractions']['wrong_lane']), '{:.3f}'.format(stats_dict['infractions']['collisions_invisible']) ] data['labels'] = [ 'Avg. driving score', 'Avg. route completion', 'Avg. infraction penalty', 'Collisions with pedestrians', 'Collisions with vehicles', 'Collisions with layout', 'Red lights infractions', 'Stop sign infractions', 'Off-road infractions', 'Route deviations', 'Route timeouts', 'Agent blocked', 'On Sidewalk', 'Off Road', 'Outside Lane', 'Collisions Invisible' ] data['sensors'] = sensors save_dict(endpoint, data)
def main(): """ Used to help with the visualization of the scenario trigger points, as well as its modifications. --town: Selects the town --scenario: The scenario that will be printed. Use the number of the scenarios 1 2 3 ... --modify: Used to modify the trigger_points of the given scenario in args.scenarios. debug is auto-enabled here. It will be shown red if they aren't apart enough or green, if they are --debug: If debug is selected, the points will be shown one by one, and stored at --endpoint, in case some copy-pasting is required. """ # general parameters parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter) parser.add_argument('--town', default='Town08') parser.add_argument('--debug', action='store_true') parser.add_argument('--reload', action='store_true') parser.add_argument('--inipoint', default="") parser.add_argument('--endpoint', default="set_new_scenarios.json") parser.add_argument('--scenarios', nargs='+', default='Scenario7') parser.add_argument('--modify', action='store_true') parser.add_argument('--host', default='localhost', help='IP of the host server (default: localhost)') parser.add_argument('--port', default='2000', help='TCP port to listen to (default: 2000)') args = parser.parse_args() # 0) Set the world client = carla.Client(args.host, int(args.port)) client.set_timeout(20) if args.reload: world = client.load_world(args.town) else: world = client.get_world() settings = world.get_settings() settings.fixed_delta_seconds = None settings.synchronous_mode = False world.apply_settings(settings) # 1) Read the json file data = fetch_dict(args.inipoint) data = data["available_scenarios"][0] town_data = data[args.town] new_args_scenario = [] for ar_sc in args.scenarios: new_args_scenario.append("Scenario" + ar_sc) args.scenarios = new_args_scenario for scenarios in town_data: if args.modify: modify_junction_scenarios(world, scenarios, args) else: draw_scenarios(world, scenarios, args) print(" ---------------------------- ") for ar_sc in args.scenarios: print(" {} is colored as {}".format(ar_sc, SCENARIO_COLOR[ar_sc][1])) print(" ---------------------------- ")
def main(): """Used to help with the visualization of the scenario trigger points""" # general parameters parser = argparse.ArgumentParser( formatter_class=RawTextHelpFormatter, description="Draw, validate or create Leaderboard scenarios. " "For multiple scenarios, separate them by spaces (example '1 3 6 9')") parser.add_argument('--host', default='localhost', help='IP of the host server (default: localhost)') parser.add_argument('--port', default='2000', help='TCP port to listen to (default: 2000)') # Path from which all scenarios will be taken parser.add_argument( '-f', '--file-path', default="../data/all_towns_traffic_scenarios_public.json", help='path to the .json file containing the scenarios') # Different tests. CHOOSE ONLY ONE. parser.add_argument('--draw-scenarios', nargs='+', help='Draw the scenarios.') parser.add_argument( '--validate-scenarios', nargs='+', help='Checks whether or not a scenario is well positioned in lane') parser.add_argument( '--create-junction-scenarios', action='store_true', help='Creates scenarios 7 to 10 using scenario 4 as reference') # Debug tool, to easily differentiate between scenarios parser.add_argument( '--debug', action='store_true', help= 'Scenarios are printed one by one, and additional information is given' ) # Town loading arguments parser.add_argument('--load-town', help='Loads a specific town (example "Town01")') parser.add_argument('--reload-town', action='store_true', help='Reloads the town') args = parser.parse_args() if args.load_town and args.reload_town: raise ValueError( "'load_town' and 'reload' can't be active at the same time") try: client = carla.Client(args.host, int(args.port)) client.set_timeout(20) if args.load_town: world = client.load_world(args.load_town) elif args.reload_town: world = client.reload_world() else: world = client.get_world() tmap = world.get_map() settings = world.get_settings() settings.fixed_delta_seconds = None settings.synchronous_mode = False world.apply_settings(settings) # Read the json file data = fetch_dict(args.file_path) town_name = world.get_map().name.split("/")[-1] town_data = data["available_scenarios"][0][town_name] if args.draw_scenarios: scenarios = ["Scenario" + ar_sc for ar_sc in args.draw_scenarios] draw_scenarios(world, town_data, scenarios, args.debug) elif args.validate_scenarios: scenarios = [ "Scenario" + ar_sc for ar_sc in args.validate_scenarios ] validate_scenarios(world, town_data, tmap, scenarios, args.debug) elif args.create_junction_scenarios: scenarios = ["Scenario4"] create_scenarios(world, town_data, tmap, scenarios, args.debug) except KeyboardInterrupt: pass
def save_global_record(route_record, sensors, endpoint, filename, config): data = fetch_dict(endpoint) if not data: data = create_default_json_msg() stats_dict = route_record.__dict__ data['_checkpoint']['global_record'] = stats_dict data['values'] = [ '{:.3f}'.format(stats_dict['scores']['score_composed']), '{:.3f}'.format(stats_dict['scores']['score_route']), '{:.3f}'.format(stats_dict['scores']['score_penalty']), # infractions '{:.3f}'.format(stats_dict['infractions']['collisions_layout']), '{:.3f}'.format( stats_dict['infractions']['collisions_pedestrian']), '{:.3f}'.format(stats_dict['infractions']['collisions_vehicle']), '{:.3f}'.format(stats_dict['infractions']['outside_route_lanes']), '{:.3f}'.format(stats_dict['infractions']['red_light']), '{:.3f}'.format(stats_dict['infractions']['route_dev']), '{:.3f}'.format(stats_dict['infractions']['stop_infraction']), '{:.3f}'.format(stats_dict['infractions']['route_timeout']), '{:.3f}'.format(stats_dict['infractions']['vehicle_blocked']), '{:.3f}'.format(config.weather.precipitation) ] data['labels'] = [ 'avg. total score', 'avg. route score', 'avg. infraction penalty', 'collisions with layout', 'collisions with pedestrians', 'collisions with vehicles', 'off-road infractions', 'red lights infractions', 'route deviation infractions', 'stop sign infractions', 'timeouts', 'vehicle blocked', 'precipitation', 'precipitation_deposits', 'cloudiness', 'wind_intensity', 'sun_azimuth_angle', 'sun_altitude_angle', 'fog_density', 'fog_distance', 'wetness' ] data['sensors'] = sensors # fields = ['avg. total score', 'avg. route score', 'avg. infraction penalty', 'collisions with layout', # 'collisions with pedestrians', 'collisions with vehicles', 'off-road infractions', # 'red lights infractions', 'route deviation infractions', 'stop sign infractions', # 'timeouts', 'vehicle blocked'] myvalues = [{ 'avg. total score': '{:.3f}'.format(stats_dict['scores']['score_composed']), 'avg. route score': '{:.3f}'.format(stats_dict['scores']['score_route']), 'avg. infraction penalty': '{:.3f}'.format(stats_dict['scores']['score_penalty']), 'collisions with layout': math.ceil(stats_dict['infractions']['collisions_layout']), 'collisions with pedestrians': math.ceil(stats_dict['infractions']['collisions_pedestrian']), 'collisions with vehicles': math.ceil(stats_dict['infractions']['collisions_vehicle']), 'off-road infractions': '{:.3f}'.format(stats_dict['infractions']['outside_route_lanes']), 'red lights infractions': '{:.3f}'.format(stats_dict['infractions']['red_light']), 'route deviation infractions': '{:.3f}'.format(stats_dict['infractions']['route_dev']), 'stop sign infractions': '{:.3f}'.format(stats_dict['infractions']['stop_infraction']), 'timeouts': '{:.3f}'.format(stats_dict['infractions']['route_timeout']), 'vehicle blocked': '{:.3f}'.format(stats_dict['infractions']['vehicle_blocked']), 'precipitation': '{:.3f}'.format(config.weather.precipitation), 'precipitation_deposits': '{:.3f}'.format(config.weather.precipitation_deposits), 'cloudiness': '{:.3f}'.format(config.weather.cloudiness), 'wind_intensity': '{:.3f}'.format(config.weather.wind_intensity), 'sun_azimuth_angle': '{:.3f}'.format(config.weather.sun_azimuth_angle), 'sun_altitude_angle': '{:.3f}'.format(config.weather.sun_altitude_angle), 'fog_density': '{:.3f}'.format(config.weather.fog_density), 'fog_distance': '{:.3f}'.format(config.weather.fog_distance), 'wetness': '{:.3f}'.format(config.weather.wetness) }] file_exists = os.path.isfile(filename) # writing to csv file with open(filename, 'a') as csvfile: # creating a csv dict writer object writer = csv.DictWriter(csvfile, fieldnames=data['labels']) if not file_exists: # writing headers (field names) writer.writeheader() # writing data rows writer.writerows(myvalues) save_dict(endpoint, data)