code: def create_environment(
      world, sensors, n_vehicles, n_walkers, spawn_points, client, tick
  ):
      global sensors_callback
      sensors_ret = []
      blueprint_library = world.get_blueprint_library()
  
      # setup sensors
      for sensor_spec in sensors:
          bp = blueprint_library.find(sensor_spec["type"])
  
          if sensor_spec["type"].startswith("sensor.camera"):
              bp.set_attribute(
                  "image_size_x", str(sensor_spec["width"])
              )
              bp.set_attribute(
                  "image_size_y", str(sensor_spec["height"])
              )
              bp.set_attribute("fov", str(sensor_spec["fov"]))
              sensor_location = carla.Location(
                  x=sensor_spec["x"],
                  y=sensor_spec["y"],
                  z=sensor_spec["z"],
              )
              sensor_rotation = carla.Rotation(
                  pitch=sensor_spec["pitch"],
                  roll=sensor_spec["roll"],
                  yaw=sensor_spec["yaw"],
              )
  
          elif sensor_spec["type"].startswith("sensor.lidar"):
              bp.set_attribute("range", "200")
              bp.set_attribute("rotation_frequency", "10")
              bp.set_attribute("channels", "32")
              bp.set_attribute("upper_fov", "15")
              bp.set_attribute("lower_fov", "-30")
              bp.set_attribute(
                  "points_per_second", str(sensor_spec["pts_per_sec"])
              )
              sensor_location = carla.Location(
                  x=sensor_spec["x"],
                  y=sensor_spec["y"],
                  z=sensor_spec["z"],
              )
              sensor_rotation = carla.Rotation(
                  pitch=sensor_spec["pitch"],
                  roll=sensor_spec["roll"],
                  yaw=sensor_spec["yaw"],
              )
  
          elif sensor_spec["type"].startswith("sensor.other.gnss"):
              sensor_location = carla.Location(
                  x=sensor_spec["x"],
                  y=sensor_spec["y"],
                  z=sensor_spec["z"],
              )
              sensor_rotation = carla.Rotation()
  
          # create sensor
          sensor_transform = carla.Transform(
              sensor_location, sensor_rotation
          )
          sensor = world.spawn_actor(bp, sensor_transform)
  
          # add callbacks
          sc = CallBack()
          sensor.listen(sc)
  
          sensors_callback.append(sc)
          sensors_ret.append(sensor)
  
      vehicles_list = []
      walkers_list = []
      all_id = []
  
      blueprint = world.get_blueprint_library().filter(
          "vehicle.audi.a2"
      )[0]
      walker_bp = world.get_blueprint_library().filter(
          "walker.pedestrian.0001"
      )[0]
  
      # @todo cannot import these directly.
      SpawnActor = carla.command.SpawnActor
      SetAutopilot = carla.command.SetAutopilot
      FutureActor = carla.command.FutureActor
  
      # --------------
      # Spawn vehicles
      # --------------
      batch = []
      for num, transform in enumerate(spawn_points):
          if num >= n_vehicles:
              break
          blueprint.set_attribute("role_name", "autopilot")
          batch.append(
              SpawnActor(blueprint, transform).then(
                  SetAutopilot(FutureActor, True)
              )
          )
  
      for response in client.apply_batch_sync(batch, False):
          if response.error:
              logging.error(response.error)
          else:
              vehicles_list.append(response.actor_id)
  
      # -------------
      # Spawn Walkers
      # -------------
      # some settings
      percentagePedestriansRunning = (
          0.0  # how many pedestrians will run
      )
      percentagePedestriansCrossing = (
          0.0  # how many pedestrians will walk through the road
      )
      if n_walkers > 0:
          # 1. take all the random locations to spawn
          spawn_points = []
          for i in range(n_walkers):
              spawn_point = carla.Transform()
              loc = world.get_random_location_from_navigation()
              if loc != None:
                  spawn_point.location = loc
                  spawn_points.append(spawn_point)
          # 2. we spawn the walker object
          batch = []
          walker_speed = []
          for spawn_point in spawn_points:
              # set as not invincible
              if walker_bp.has_attribute("is_invincible"):
                  walker_bp.set_attribute("is_invincible", "false")
              # set the max speed
              if walker_bp.has_attribute("speed"):
                  # walking
                  walker_speed.append(
                      walker_bp.get_attribute(
                          "speed"
                      ).recommended_values[1]
                  )
              else:
                  print("Walker has no speed")
                  walker_speed.append(0.0)
              batch.append(SpawnActor(walker_bp, spawn_point))
          results = client.apply_batch_sync(batch, True)
          walker_speed2 = []
          for i in range(len(results)):
              if results[i].error:
                  logging.error(results[i].error)
              else:
                  walkers_list.append({"id": results[i].actor_id})
                  walker_speed2.append(walker_speed[i])
          walker_speed = walker_speed2
          # 3. we spawn the walker controller
          batch = []
          walker_controller_bp = world.get_blueprint_library().find(
              "controller.ai.walker"
          )
          for i in range(len(walkers_list)):
              batch.append(
                  SpawnActor(
                      walker_controller_bp,
                      carla.Transform(),
                      walkers_list[i]["id"],
                  )
              )
          results = client.apply_batch_sync(batch, True)
          for i in range(len(results)):
              if results[i].error:
                  logging.error(results[i].error)
              else:
                  walkers_list[i]["con"] = results[i].actor_id
              # 4. we put altogether the walkers and controllers id to get the objects from their id
          for i in range(len(walkers_list)):
              all_id.append(walkers_list[i]["con"])
              all_id.append(walkers_list[i]["id"])
  
      all_actors = world.get_actors(all_id)
  
      # ensures client has received the last transform of the walkers we have just created
      tick()
  
      # 5. initialize each controller and set target to walk to (list is [controler, actor, controller, actor ...])
      # set how many pedestrians can cross the road
      world.set_pedestrians_cross_factor(percentagePedestriansCrossing)
      for i in range(0, len(all_id), 2):
          # start walker
          all_actors[i].start()
          # set walk to random point
          all_actors[i].go_to_location(
              world.get_random_location_from_navigation()
          )
          # max speed
          all_actors[i].set_max_speed(float(walker_speed[int(i / 2)]))
  
      print(
          "Spawned %d vehicles and %d walkers."
          % (len(vehicles_list), len(walkers_list))
      )
  
      return (
          vehicles_list,
          walkers_list,
          all_id,
          all_actors,
          sensors_ret,
      )
  
imports: import sys
  from tr import tr
  import argparse
  import cpuinfo
  import glob
  import math
  import numpy
  import os
  import psutil
  import pygame
  import shutil
  import GPUtil
  import threading
  import time
  import logging
  import carla
label_desc: Use image node_id 5 for calling a global function with example usage: create_environment(world, sensors, n_vehicles, n_walkers, spawn_points, client, tick) and returns: vehicles_list,  walkers_list,  all_id,  all_actors,  sensors_ret