コード例 #1
0
    def build_experiments(self):
        """
        Creates the whole set of experiment objects,
        The experiments created depend on the selected Town.
        """

        # We set the RGB, seg cameras
        if self.rgb:
            camera = Camera('rgb')
            camera.set(FOV=100)
            camera.set_image_size(800, 600)
            camera.set_position(2.0, 0.0, 1.4)
            camera.set_rotation(-15.0, 0, 0)
        if self.seg:
            seg = Camera('seg', PostProcessing='SemanticSegmentation')
            seg.set(FOV=100)
            seg.set_image_size(800, 600)
            seg.set_position(2.0, 0.0, 1.4)
            seg.set_rotation(-15.0, 0, 0)

        poses_tasks = self._poses()
        vehicles_tasks = [20]
        pedestrians_tasks = [50]
        task_names = ['normal']

        experiments_vector = []

        for weather in self.weathers:

            for iteration in range(len(poses_tasks)):
                poses = poses_tasks[iteration]
                vehicles = vehicles_tasks[iteration]
                pedestrians = pedestrians_tasks[iteration]

                conditions = CarlaSettings()
                conditions.set(
                    SendNonPlayerAgentsInfo=True,
                    NumberOfVehicles=vehicles,
                    NumberOfPedestrians=pedestrians,
                    WeatherId=weather

                )
                conditions.set(DisableTwoWheeledVehicles=True)
                # Add all the cameras that were set for this experiments
                if self.rgb:
                    conditions.add_sensor(camera)
                if self.seg:
                    conditions.add_sensor(seg)

                experiment = Experiment()
                experiment.set(
                    Conditions=conditions,
                    Poses=poses,
                    Task=iteration,
                    TaskName=task_names[iteration],
                    Repetitions=1
                )
                experiments_vector.append(experiment)

        return experiments_vector
コード例 #2
0
    def build_experiments(self):
        """
        Creates the whole set of experiment objects,
        The experiments created depend on the selected Town.


        """

        # We set the camera
        # This single RGB camera is used on every experiment

        camera = Camera('rgb')
        camera.set(FOV=100)
        camera.set_image_size(800, 600)
        camera.set_position(2.0, 0.0, 1.4)
        camera.set_rotation(-15.0, 0, 0)

        poses_tasks = self._poses()
        vehicles_tasks = [0, 15, 70]
        pedestrians_tasks = [0, 50, 150]

        vehicles_tasks = [70]
        pedestrians_tasks = [150]

        task_names = ['empty', 'normal', 'cluttered']
        task_names = ['cuttered']

        experiments_vector = []

        for weather in self.weathers:

            for iteration in range(len(poses_tasks)):
                poses = poses_tasks[iteration]
                vehicles = vehicles_tasks[iteration]
                pedestrians = pedestrians_tasks[iteration]

                conditions = CarlaSettings()
                conditions.set(SendNonPlayerAgentsInfo=True,
                               NumberOfVehicles=vehicles,
                               NumberOfPedestrians=pedestrians,
                               WeatherId=weather)
                conditions.set(DisableTwoWheeledVehicles=True)
                # Add all the cameras that were set for this experiments

                conditions.add_sensor(camera)

                experiment = Experiment()
                experiment.set(Conditions=conditions,
                               Poses=poses,
                               Task=iteration,
                               TaskName=task_names[iteration],
                               Repetitions=1)
                experiments_vector.append(experiment)

        return experiments_vector
コード例 #3
0
def game_loop(args, agent):
    pygame.init()
    pygame.font.init()
    world = None
    total_images = 0

    if args.output_folder is not None:
        os.makedirs(args.output_folder)

    try:
        with make_carla_client(args.host, args.port) as client:
            # Hack to fix for the issue 310, we force a reset, so it does not get
            #  the positions on first server reset.
            client.load_settings(CarlaSettings())
            client.start_episode(0)

            display = pygame.display.set_mode(
                (args.width, args.height), pygame.HWSURFACE | pygame.DOUBLEBUF)

            hud = HUD(args.width, args.height)
            world = World(client, hud)
            controller = KeyboardControl(world, False)

            #spawn_point = world.world.get_map().get_spawn_points()[0]
            objective = world.get_objective()
            clock = pygame.time.Clock()
            while True:
                if controller.parse_events(world, clock):
                    return

                world.tick(clock)
                measurements, sensor_data = world.get_agent_sensor()
                world.render(display)
                pygame.display.flip()
                print(controller.get_command())
                control = agent.run_step(
                    measurements, sensor_data, controller.get_command(),
                    (objective.location.x, objective.location.y,
                     objective.location.z))

                world.camera_manager.set_sensor(sensor_data['hudcamera'].data)
                attentions = agent.get_attentions()
                world.camera_manager.show_image_mini(agent.latest_image,
                                                     attentions[0],
                                                     attentions[1],
                                                     attentions[2])
                print(control)
                world.apply_control(control)
                if args.output_folder is not None:
                    scipy.misc.imsave(
                        os.path.join(args.output_folder,
                                     'image' + str(total_images) + '.png'),
                        agent.latest_image)
                    scipy.misc.imsave(
                        os.path.join(args.output_folder,
                                     'layer1_' + str(total_images) + '.png'),
                        attentions[0])
                    scipy.misc.imsave(
                        os.path.join(args.output_folder,
                                     'layer2_' + str(total_images) + '.png'),
                        attentions[1])
                    scipy.misc.imsave(
                        os.path.join(args.output_folder,
                                     'layer3_' + str(total_images) + '.png'),
                        attentions[2])
                    total_images += 1
    finally:

        pygame.quit()
コード例 #4
0
def make_carla_settings(benchmark=None, task=None):
    """Make a CarlaSettings object with the settings we need."""

    settings = CarlaSettings()
    settings.set(SendNonPlayerAgentsInfo=True,
                 SynchronousMode=True,
                 NumberOfVehicles=30,
                 NumberOfPedestrians=50,
                 WeatherId=1)

    settings.set(DisableTwoWheeledVehicles=True)

    settings.randomize_seeds()  # IMPORTANT TO RANDOMIZE THE SEEDS EVERY TIME
    camera0 = sensor.Camera('rgb')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=100)
    camera0.set_image_size(800, 600)
    camera0.set_position(2.0, 0.0, 1.4)
    camera0.set_rotation(-15.0, 0, 0)

    settings.add_sensor(camera0)

    camera0 = sensor.Camera('hudcamera')
    camera0.set_image_size(WINDOW_WIDTH, WINDOW_HEIGHT)
    camera0.set(FOV=100)
    camera0.set_image_size(1280, 730)
    camera0.set_position(-5.5, 0.0, 2.8)
    camera0.set_rotation(-15.0, 0, 0)

    settings.add_sensor(camera0)

    return settings