def test_continue_experiment(self):

        recording = Recording(name_to_save='Test1',
                              continue_experiment=False,
                              save_images=True)

        # A just started case should return the continue experiment case
        self.assertEqual(recording._continue_experiment(True)[1], 1)
        # If you don't want to continue, should return also one
        self.assertEqual(recording._continue_experiment(False)[1], 1)

        from carla.driving_benchmark.experiment import Experiment

        recording.write_summary_results(experiment=Experiment(),
                                        pose=[24, 32],
                                        rep=1,
                                        path_distance=200,
                                        remaining_distance=0,
                                        final_time=0.2,
                                        time_out=49,
                                        result=1)
        recording.write_summary_results(experiment=Experiment(),
                                        pose=[24, 32],
                                        rep=1,
                                        path_distance=200,
                                        remaining_distance=0,
                                        final_time=0.2,
                                        time_out=49,
                                        result=1)

        # After writing two experiments it should return 2, so you could start writing os pos 3
        self.assertEqual(recording._continue_experiment(True)[1], 3)
        # If you dont want to continue, should return also one
        self.assertEqual(recording._continue_experiment(False)[1], 1)
Exemplo n.º 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('CameraRGB')
        camera.set(FOV=100)
        camera.set_image_size(200, 88)
        camera.set_position(2.0, 0.0, 1.4)
        camera.set_rotation(-15.0, 0, 0)

        if self._city_name == 'Town01':
            poses_tasks = self._poses_town01()
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        else:
            poses_tasks = self._poses_town02()
            vehicles_tasks = [0, 0, 0, 15]
            pedestrians_tasks = [0, 0, 0, 50]

        experiments_vector = []

        for weather in self.weathers:

            for iteration in range(len(poses_tasks)):
                poses = poses_tasks[iteration]

                #weather=14

                #poses = [[54, 60]]
                #poses=[[37,76]]
                #poses = [[80, 29]]
                #poses = [[50,43]]
                vehicles = vehicles_tasks[iteration]
                pedestrians = pedestrians_tasks[iteration]

                conditions = CarlaSettings()
                conditions.set(SendNonPlayerAgentsInfo=True,
                               NumberOfVehicles=vehicles,
                               NumberOfPedestrians=pedestrians,
                               WeatherId=weather)
                conditions.set(SynchronousMode=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,
                               Repetitions=1)
                experiments_vector.append(experiment)

        return experiments_vector
Exemplo n.º 3
0
    def build_experiments(self):
        """
            Creates the whole set of experiment objects,
            The experiments created depends on the selected Town.

        """

        # We check the town, based on that we define the town related parameters
        # The size of the vector is related to the number of tasks, inside each
        # task there is also multiple poses ( start end, positions )
        if self._city_name == 'Town01':
            poses_tasks = [[[7, 3]], [[138, 17]], [[140, 134]], [[140, 134]]]
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        else:
            poses_tasks = [[[4, 2]], [[37, 76]], [[19, 66]], [[19, 66]]]
            vehicles_tasks = [0, 0, 0, 15]
            pedestrians_tasks = [0, 0, 0, 50]

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

        camera = Camera('CameraRGB')
        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)

        # Based on the parameters, creates a vector with experiment objects.
        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

                )
                # Add all the cameras that were set for this experiments
                conditions.add_sensor(camera)
                experiment = Experiment()
                experiment.set(
                    Conditions=conditions,
                    Poses=poses,
                    Task=iteration,
                    Repetitions=1
                )
                experiments_vector.append(experiment)

        return experiments_vector
    def build_experiments(self):
        """
            Creates the whole set of experiment objects,
            The experiments created depends on the selected Town.

        """

        # We check the town, based on that we define the town related parameters
        # The size of the vector is related to the number of tasks, inside each
        # task there is also multiple poses ( start end, positions )
        if self._city_name == 'Town01':
            poses_tasks = [[[7, 3]], [[138, 17]], [[140, 134]], [[140, 134]]]
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        else:
            poses_tasks = [[[4, 2]], [[37, 76]], [[19, 66]], [[19, 66]]]
            vehicles_tasks = [0, 0, 0, 15]
            pedestrians_tasks = [0, 0, 0, 50]

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

        camera = Camera('CameraRGB')
        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)

        # Based on the parameters, creates a vector with experiment objects.
        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

                )
                # Add all the cameras that were set for this experiments
                conditions.add_sensor(camera)
                experiment = Experiment()
                experiment.set(
                    Conditions=conditions,
                    Poses=poses,
                    Task=iteration,
                    Repetitions=1
                )
                experiments_vector.append(experiment)

        return experiments_vector
Exemplo n.º 5
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('CameraRGB')
        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._city_name == 'Town01':
            poses_tasks = self._poses_town01()
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        else:
            poses_tasks = self._poses_town02()
            vehicles_tasks = [0, 0, 0, 15]
            pedestrians_tasks = [0, 0, 0, 50]

        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
                )
                # Add all the cameras that were set for this experiments

                conditions.add_sensor(camera)

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

        return experiments_vector
Exemplo n.º 6
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('CameraRGB')
        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._city_name == 'Town01':
            poses_tasks = self._poses_town01()
            vehicles_tasks = [25]
            pedestrians_tasks = [25]
        else:
            poses_tasks = self._poses_town02()
            vehicles_tasks = [0, 25]
            pedestrians_tasks = [0, 25]

        experiments_vector = []
        #weathers = [1,3,6,8]
        for weather in self.weathers:
            #prinst(weather , vehicles_tasks)
            for scenario in range(len(vehicles_tasks)):
                for iteration in range(len(poses_tasks)):
                    #print(f"interation : {iteration} , scenario:{scenario}")
                    poses = poses_tasks[iteration]
                    #print("poses re",poses)
                    vehicles = vehicles_tasks[scenario]
                    #print("Vehicles: ",vehicles)
                    pedestrians = pedestrians_tasks[scenario]
                    #print("pedestrians: ",pedestrians)

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

                    conditions.add_sensor(camera)

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

        return experiments_vector
Exemplo n.º 7
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=90)
        camera.set_image_size(300, 300)
        camera.set_position(0.2, 0.0, 0.85)
        camera.set_rotation(-3.0, 0, 0)

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



        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,
                    QualityLevel='Epic'
                )
                # Add all the cameras that were set for this experiments

                conditions.add_sensor(camera)

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

        return experiments_vector
    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]

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

        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
    def test_write_summary_results(self):
        """
            Test writting summary results.
        """
        from carla.driving_benchmark.experiment import Experiment

        recording = Recording(name_to_save='Test1',
                              continue_experiment=False,
                              save_images=True)

        recording.write_summary_results(experiment=Experiment(),
                                        pose=[24, 32],
                                        rep=1,
                                        path_distance=200,
                                        remaining_distance=0,
                                        final_time=0.2,
                                        time_out=49,
                                        result=1)

        with open(os.path.join(recording._path, 'summary.csv'), 'r') as f:
            header = f.readline().split(',')
            # Assert if header is header
            self.assertIn('exp_id', header)

            self.assertEqual(len(header), len(recording._dict_summary))
            # Assert if there is something writen in the row

            written_row = f.readline().split(',')

            # Assert if the number of collums is correct
            self.assertEqual(len(written_row), len(recording._dict_summary))
    def teste_write_measurements_results(self):

        import os
        from carla.driving_benchmark.experiment import Experiment
        from carla.carla_server_pb2 import Measurements
        from carla.carla_server_pb2 import Control

        recording = Recording(name_to_save='Test1',
                              continue_experiment=False,
                              save_images=True)

        reward_vec = [Measurements().player_measurements for x in range(20)]
        control_vec = [Control() for x in range(25)]

        recording.write_measurements_results(experiment=Experiment(),
                                             rep=1,
                                             pose=[24, 32],
                                             reward_vec=reward_vec,
                                             control_vec=control_vec)

        with open(os.path.join(recording._path, 'measurements.csv'), 'r') as f:

            header = f.readline().split(',')
            #Assert if header is header
            self.assertIn('exp_id', header)

            self.assertEqual(len(header), len(recording._dict_measurements))
            #Assert if there is something writen in the row

            written_row = f.readline().split(',')

            #Assert if the number of collums is correct
            self.assertEqual(len(written_row),
                             len(recording._dict_measurements))
    def _generate_test_case(self, poses_to_test):



        recording = Recording(name_to_save='TestMetric'
                              , continue_experiment=False, save_images=True
                              )



        from carla.driving_benchmark.experiment import Experiment
        from carla.carla_server_pb2 import Measurements
        from carla.carla_server_pb2 import Control


        for pose in poses_to_test:
            experiment = Experiment()

            recording.write_summary_results(experiment=experiment, pose=pose, rep=1,
                                            path_distance=200, remaining_distance=0,
                                            final_time=0.2, time_out=49, result=1)


            reward_vec = [Measurements().player_measurements for x in range(25)]
            control_vec = [Control() for x in range(25)]

            recording.write_measurements_results(experiment=experiment,
                                                 rep=1, pose=pose, reward_vec=reward_vec,
                                                 control_vec=control_vec)



        return recording._path
    def test_write_summary_results_good_order(self):
        """
            Test if the summary results are writen in the same order on a new process
        """

        from carla.driving_benchmark.experiment import Experiment

        recording = Recording(name_to_save='Test_good_order',
                              continue_experiment=False,
                              save_images=True)

        for _ in range(0, 10):
            recording.write_summary_results(experiment=Experiment(),
                                            pose=[24, 32],
                                            rep=1,
                                            path_distance=200,
                                            remaining_distance=0,
                                            final_time=0.2,
                                            time_out=49,
                                            result=1)

        recording = Recording(name_to_save='Test_good_order',
                              continue_experiment=True,
                              save_images=True)

        for _ in range(0, 10):
            recording.write_summary_results(experiment=Experiment(),
                                            pose=[24, 32],
                                            rep=1,
                                            path_distance=200,
                                            remaining_distance=0,
                                            final_time=0.2,
                                            time_out=49,
                                            result=1)

        recording = Recording(name_to_save='Test_good_order',
                              continue_experiment=True,
                              save_images=True)

        for _ in range(0, 10):
            recording.write_summary_results(experiment=Experiment(),
                                            pose=[24, 32],
                                            rep=1,
                                            path_distance=200,
                                            remaining_distance=0,
                                            final_time=0.2,
                                            time_out=49,
                                            result=1)

        recording = Recording(name_to_save='Test_good_order',
                              continue_experiment=True,
                              save_images=True)

        for _ in range(0, 10):
            recording.write_summary_results(experiment=Experiment(),
                                            pose=[24, 32],
                                            rep=1,
                                            path_distance=200,
                                            remaining_distance=0,
                                            final_time=0.2,
                                            time_out=49,
                                            result=1)
    def test_get_pose_and_experiment_corner(self):
        """
            Test getting the pose from multiple cases.
        """
        from carla.driving_benchmark.experiment import Experiment

        recording = Recording(name_to_save='Test1',
                              continue_experiment=False,
                              save_images=True)

        pose, experiment = recording.get_pose_and_experiment(1)

        # An starting experiment should return one

        self.assertEqual(pose, 0)
        self.assertEqual(experiment, 0)

        pose, experiment = recording.get_pose_and_experiment(2)
        self.assertEqual(pose, 0)
        self.assertEqual(experiment, 0)

        recording.write_summary_results(experiment=Experiment(),
                                        pose=[24, 32],
                                        rep=1,
                                        path_distance=200,
                                        remaining_distance=0,
                                        final_time=0.2,
                                        time_out=49,
                                        result=1)

        pose, experiment = recording.get_pose_and_experiment(1)

        print(pose, experiment)
        self.assertEqual(pose, 0)
        self.assertEqual(experiment, 1)

        pose, experiment = recording.get_pose_and_experiment(2)

        print(pose, experiment)
        # An starting experiment should return one
        self.assertEqual(pose, 1)
        self.assertEqual(experiment, 0)

        pose, experiment = recording.get_pose_and_experiment(3)

        print(pose, experiment)
        # An starting experiment should return one
        self.assertEqual(pose, 1)
        self.assertEqual(experiment, 0)

        recording.write_summary_results(experiment=Experiment(),
                                        pose=[24, 32],
                                        rep=1,
                                        path_distance=200,
                                        remaining_distance=0,
                                        final_time=0.2,
                                        time_out=49,
                                        result=1)

        pose, experiment = recording.get_pose_and_experiment(2)

        self.assertEqual(pose, 0)
        self.assertEqual(experiment, 1)

        pose, experiment = recording.get_pose_and_experiment(3)

        self.assertEqual(pose, 2)
        self.assertEqual(experiment, 0)
    def test_get_pose_and_experiment(self):
        """
            Test getting the pose and the experiment from a previous executed benchmark
        """

        recording = Recording(name_to_save='Test1',
                              continue_experiment=False,
                              save_images=True)

        from carla.driving_benchmark.experiment import Experiment

        pose, experiment = recording.get_pose_and_experiment(25)

        # An starting experiment should return zero zero

        self.assertEqual(pose, 0)
        self.assertEqual(experiment, 0)

        recording.write_summary_results(experiment=Experiment(),
                                        pose=[24, 32],
                                        rep=1,
                                        path_distance=200,
                                        remaining_distance=0,
                                        final_time=0.2,
                                        time_out=49,
                                        result=1)
        recording.write_summary_results(experiment=Experiment(),
                                        pose=[24, 32],
                                        rep=1,
                                        path_distance=200,
                                        remaining_distance=0,
                                        final_time=0.2,
                                        time_out=49,
                                        result=1)

        pose, experiment = recording.get_pose_and_experiment(25)
        self.assertEqual(pose, 2)
        self.assertEqual(experiment, 0)

        for _ in range(23):
            recording.write_summary_results(experiment=Experiment(),
                                            pose=[24, 32],
                                            rep=1,
                                            path_distance=200,
                                            remaining_distance=0,
                                            final_time=0.2,
                                            time_out=49,
                                            result=1)

        pose, experiment = recording.get_pose_and_experiment(25)
        self.assertEqual(pose, 0)
        self.assertEqual(experiment, 1)

        for _ in range(23):
            recording.write_summary_results(experiment=Experiment(),
                                            pose=[24, 32],
                                            rep=1,
                                            path_distance=200,
                                            remaining_distance=0,
                                            final_time=0.2,
                                            time_out=49,
                                            result=1)

        pose, experiment = recording.get_pose_and_experiment(25)
        self.assertEqual(pose, 23)
        self.assertEqual(experiment, 1)
Exemplo n.º 15
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('CameraRGB')
        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._city_name == 'Town01':
            poses_tasks = self._poses_town01()
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        elif self._city_name == 'Town02':
            poses_tasks = self._poses_town02()
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        elif self._city_name == 'Town01_nemesis':
            poses_tasks = self._poses_town01_nemesis()
            vehicles_tasks = [0, 0, 0, 0]
            pedestrians_tasks = [0, 0, 0, 0]
        elif self._city_name == 'Town02_nemesis':
            poses_tasks = self._poses_town02_nemesis()
            vehicles_tasks = [0, 0, 0, 0]
            pedestrians_tasks = [0, 0, 0, 0]
        elif self._city_name == 'Town01_mini':
            poses_tasks = self._poses_town01_mini()
            vehicles_tasks = [0, 0, 0, 0]
            pedestrians_tasks = [0, 0, 0, 0]

        experiments_vector = []
        """repeating experiment"""
        num_iters = 171
        weathers_iters = [1] * num_iters

        for weather in weathers_iters:

            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)
                # Add all the cameras that were set for this experiments

                conditions.add_sensor(camera)

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

        return experiments_vector
Exemplo n.º 16
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('CameraRGB')
        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._city_name == 'Town01':

            if self._subset == 'keep_lane':
                poses_tasks = [self._poses_town01()[0]]
                vehicles_tasks = [0]
                pedestrians_tasks = [0]

            elif self._subset == 'one_turn':
                poses_tasks = [self._poses_town01()[1]]
                vehicles_tasks = [0]
                pedestrians_tasks = [0]

            elif self._subset == 'keep_lane_one_turn':
                poses_tasks = self._poses_town01()[:2]
                vehicles_tasks = [0, 0]
                pedestrians_tasks = [0, 0]

            elif self._subset == 'no_dynamic_objects':
                poses_tasks = self._poses_town01()[:3]
                vehicles_tasks = [0, 0, 0]
                pedestrians_tasks = [0, 0, 0]

            elif self._subset is None:
                poses_tasks = self._poses_town01()
                vehicles_tasks = [0, 0, 0, 20]
                pedestrians_tasks = [0, 0, 0, 50]

            else:
                raise ValueError(
                    "experiments-subset must be keep_lane or keep_lane_one_turn or no_dynamic_objects or None"
                )

        else:
            raise ValueError("city must be Town01 for training")

        experiments_vector = []

        for i, iteration in enumerate(range(len(poses_tasks))):

            for weather in self.weathers:

                poses = poses_tasks[iteration]
                vehicles = vehicles_tasks[iteration]
                pedestrians = pedestrians_tasks[iteration]

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

                conditions.add_sensor(camera)

                experiment = Experiment()
                experiment.set(Conditions=conditions,
                               Poses=poses,
                               Task=iteration,
                               Repetitions=1)

                experiments_vector.append(experiment)

        return experiments_vector
    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('CameraRGB')
        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._task == 'go-straight':
            task_select = 0
        elif self._task == 'turn-right':
            task_select = 1
        elif self._task == 'turn-left':
            task_select = 2
        elif self._task == 'go-straight-2':
            task_select = 3
        elif self._task == 'turn-right-2':
            task_select = 4
        elif self._task == 'turn-left-2':
            task_select = 5

        if self._city_name == 'Town01':
            poses_tasks = self._poses_town01()
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        elif self._city_name == 'Town02':
            poses_tasks = self._poses_town02()
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        elif self._city_name[:-1] == 'Town01_nemesis':
            poses_tasks = [self._poses_town01_nemesis()[task_select]]
            vehicles_tasks = [0, 0, 0, 0, 0, 0]
            pedestrians_tasks = [0, 0, 0, 0, 0, 0]
        elif self._city_name[:-1] == 'Town02_nemesis':
            poses_tasks = [self._poses_town02_nemesis()[task_select]]
            vehicles_tasks = [0, 0, 0, 0, 0, 0]
            pedestrians_tasks = [0, 0, 0, 0, 0, 0]

        experiments_vector = []
        """repeating experiment"""
        num_iters = self._iters
        weathers_iters = [self._weather] * num_iters

        # 0 - Default
        # 1 - ClearNoon
        # 2 - CloudyNoon
        # 3 - WetNoon
        # 4 - WetCloudyNoon
        # 5 - MidRainyNoon
        # 6 - HardRainNoon
        # 7 - SoftRainNoon
        # 8 - ClearSunset
        # 9 - CloudySunset
        # 10 - WetSunset
        # 11 - WetCloudySunset
        # 12 - MidRainSunset
        # 13 - HardRainSunset
        # 14 - SoftRainSunset

        for weather in weathers_iters:

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

                ## add here
                # random the scenario
                #weather_num_random = int(random.uniform(0,14))
                #vehicles_num_random = int(random.uniform(0,1000))
                #pedestrain_num_random = int(random.uniform(0,1000))
                #vehicles = vehicles_num_random
                #pedestrains = pedestrain_num_random
                #weather = weather_num_random
                vehicles = 400
                pedestrains = 400
                #weather =
                ##

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

                conditions.add_sensor(camera)

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

        return experiments_vector
Exemplo n.º 18
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('CameraMiddle')
        camera.set(FOV=90)
        camera.set_image_size(768, 576)
        camera.set_position(1.5, 0.0, 1.6)
        camera.set_rotation(0, 0, 0)

        if self._city_name == 'Town01':
            poses_tasks = self._poses_town01()
            vehicles_tasks = [0, 0, 0, 100]
            pedestrians_tasks = [0, 0, 0, 300]
            n_samples = [0, 0, 30 // 4, 60 // 4]
            #n_samples = [3, 6, 6, 9]
        else:
            poses_tasks = self._poses_town02()
            vehicles_tasks = [0, 0, 0, 50]
            pedestrians_tasks = [0, 0, 0, 150]
            n_samples = [0, 0, 15, len(poses_tasks[-1])]
            #n_samples = [3, 6, 6, 9]

        experiments_vector = []

        random.seed(1)

        for weather in self.weathers:

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

                nsample = n_samples[iteration]
                if nsample == 0:
                    continue
                poses = random.sample(poses, nsample)

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

                conditions.add_sensor(camera)

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

        return experiments_vector
Exemplo n.º 19
0
    def build_experiments(self):
        """
            Creates the whole set of experiment objects,
            The experiments created depends on the selected Town.

        """

        # We check the town, based on that we define the town related parameters
        # The size of the vector is related to the number of tasks, inside each
        # task there is also multiple poses ( start end, positions )
        if self._city_name == 'Town01':
            #poses_tasks = [[[7, 3]], [[138, 17]], [[140, 134]], [[140, 134]]]
            poses_tasks = [[[138, 134]]]
            vehicles_tasks = [20]
            pedestrians_tasks = [10]
        else:
            right_curves = [[[1, 56], [65, 69], [78, 51], [44, 61], [40, 17],
                             [71, 16], [74, 38], [46, 12], [19, 18], [26, 74],
                             [37, 76], [11, 44], [20, 6], [10, 22], [28, 2],
                             [5, 15], [14, 33], [34, 8]]]
            left_curves = [[[57, 82], [72, 43], [52, 79], [70, 66], [43, 14],
                            [11, 47], [79, 32], [37, 75], [75, 16], [26, 73],
                            [39, 5], [2, 37], [34, 13], [6, 35], [10, 19],
                            [23, 6], [5, 30], [16, 2]]]
            special_test = [[[19, 66], [79, 14], [42, 13], [31, 71], [54, 30],
                             [10, 61], [66, 3], [27, 12], [2, 29], [16, 14],
                             [70, 73], [46, 67], [51, 81], [56, 65], [43, 54]]]
            corl_task2 = [[[19, 66], [79, 14], [19, 57], [23, 1], [53, 76],
                           [42, 13], [31, 71], [33, 5], [54, 30], [10, 61],
                           [66, 3], [27, 12], [79, 19], [2, 29], [16, 14],
                           [5, 57], [70, 73], [46, 67], [57, 50], [61, 49],
                           [21, 12], [51, 81], [77, 68], [56, 65], [43, 54]]]

            #poses_tasks = corl_task2
            poses_tasks = [[[10, 19]]]
            vehicles_tasks = [0]  #*len(poses_tasks[0])
            pedestrians_tasks = [0]  #*len(poses_tasks[0])

        # We set the camera
        # This single RGB camera is used on every experiment
        '''camera = Camera('CameraRGB')
        camera.set(FOV=90)
        camera.set_image_size(800, 600)
        camera.set_position(1.44, 0.0, 1.2)
        camera.set_rotation(0, 0, 0)'''

        camera0 = Camera('CameraRGB0')
        camera0.set(FOV=90)
        camera0.set_image_size(400, 300)
        camera0.set_position(1.7, 0.0, 1.3)
        camera0.set_rotation(0, 0, 0)

        camera1 = Camera('CameraRGB1')
        camera1.set(FOV=90)
        camera1.set_image_size(400, 300)
        camera1.set_position(1.7, 0.0, 1.3)
        camera1.set_rotation(0, -45, 0)

        camera2 = Camera('CameraRGB2')
        camera2.set(FOV=90)
        camera2.set_image_size(400, 300)
        camera2.set_position(1.7, 0.0, 1.3)
        camera2.set_rotation(0, +45, 0)

        # Based on the parameters, creates a vector with experiment objects.
        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)
                # Add all the cameras that were set for this experiments
                conditions.add_sensor(camera0)
                conditions.add_sensor(camera1)
                conditions.add_sensor(camera2)
                experiment = Experiment()
                experiment.set(Conditions=conditions,
                               Poses=poses,
                               Task=iteration,
                               Repetitions=1)
                experiments_vector.append(experiment)
            '''path0=os.listdir('CameraRGB0')
            path1=os.listdir('CameraRGB1')
            path2=os.listdir('CameraRGB2')
            os.mkdir('CameraRGB')

            width=400
            height=300

            total_width = width*3
            max_height = height

            i = 0
            images=[]
            images.append(Image.open('CameraRGB1/'+path1[i]))
            images.append(Image.open('CameraRGB0/'+path0[i]))
            images.append(Image.open('CameraRGB2/'+path2[i]))
            new_im = Image.new('RGB', (total_width, max_height))
            x_offset = 0
            for im in images:
                new_im.paste(im, (x_offset,0))
                x_offset += im.size[0]
                new_im.save('CameraRGB/'+path0[i])
            i = i+1'''

        return experiments_vector
Exemplo n.º 20
0
    def build_experiments(self):
        """
            Creates the whole set of experiment objects,
            The experiments created depends on the selected Town.

        """

        # We check the town, based on that we define the town related parameters
        # The size of the vector is related to the number of tasks, inside each
        # task there is also multiple poses ( start end, positions )
        if self._city_name == 'Town01':
            poses_tasks = [[[7, 3]], [[138, 17]], [[140, 134]], [[140, 134]]]
            vehicles_tasks = [0, 0, 0, 20]
            pedestrians_tasks = [0, 0, 0, 50]
        else:
            right_curves =  [[[1,56],[65,69],[78,51],[44,61],[40,17],[71,16],[74,38],[46,12],
                              [19,18],[26,74],[37,76],[11,44],[20,6],[10,22],[28,2],[5,15],
                              [14,33],[34,8]]]      
            left_curves =  [[[57,82],[72,43],[52,79],[70,66],[43,14],[11,47],[79,32],[37,75],
                             [75,16],[26,73],[39,5],[2,37],[34,13],[6,35],[10,19],[23,6],
                             [5,30],[16,2]]] 
            special_test = [[[19, 66], [79, 14],[42, 13], [31, 71], 
                             [54, 30], [10, 61], [66, 3], [27, 12],
                             [2, 29], [16, 14],[70, 73], [46, 67],
                             [51, 81], [56, 65], [43, 54]]]
            corl_task2 = [[[19, 66], [79, 14], [19, 57], [23, 1],
                    [53, 76], [42, 13], [31, 71], [33, 5],
                    [54, 30], [10, 61], [66, 3], [27, 12],
                    [79, 19], [2, 29], [16, 14], [5, 57],
                    [70, 73], [46, 67], [57, 50], [61, 49], [21, 12],
                    [51, 81], [77, 68], [56, 65], [43, 54]]]

            poses_tasks = corl_task2
            vehicles_tasks = [0]*len(poses_tasks[0])
            pedestrians_tasks = [0]*len(poses_tasks[0])

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

        camera = Camera('CameraRGB')
        camera.set(FOV=90)
        camera.set_image_size(800, 600)
        camera.set_position(1.44, 0.0, 1.2)
        camera.set_rotation(0, 0, 0)

        # Based on the parameters, creates a vector with experiment objects.
        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

                )
                # Add all the cameras that were set for this experiments
                conditions.add_sensor(camera)
                experiment = Experiment()
                experiment.set(
                    Conditions=conditions,
                    Poses=poses,
                    Task=iteration,
                    Repetitions=1
                )
                experiments_vector.append(experiment)

        return experiments_vector