Exemple #1
0
    def startScenarios(self):
        _drivingMode = [
            786603, 11.0
        ]  # mode (0-4294967296), speed (0-20), only if auto drive
        _vehicle = 'oracle'  # "blista", "voltic", "packer", "oracle"
        _weather = 'CLEAR'  # "CLEAR", "EXTRASUNNY", "CLOUDS", "OVERCAST", "RAIN", "CLEARING", "THUNDER", "SMOG", "FOGGY", "XMAS", "SNOWLIGHT", "BLIZZARD", "NEUTRAL", "SNOW"
        _time = [10, 30]  # HH, MM
        _location = [-281.8045, -1396.085]  # [-274.2653, -1122.707]

        dataset = Dataset(throttle=True,
                          brake=True,
                          steering=True,
                          vehicles=True,
                          trafficSigns=True,
                          peds=True,
                          speed=True,
                          yawRate=True,
                          location=True,
                          time=True)
        scenario = Scenario(drivingMode=_drivingMode,
                            vehicle=_vehicle,
                            weather=_weather,
                            time=_time,
                            location=_location)
        start_msg = Start(dataset=dataset, scenario=scenario)
        jsonstr = start_msg.to_json().encode()

        c = Message(START_SCENARIOS, data=jsonstr)
        self.__sendMsg(c)
Exemple #2
0
def main():
    global client, scenario

    client = Client(ip='localhost',
                    port=8000,
                    datasetPath='D:/no_traffic/dataset' + str(i) + '.pz',
                    compressionLevel=9)
    scenario = Scenario(weather=weather,
                        vehicle='blista',
                        time=[set_time, 0],
                        drivingMode=-1,
                        location=location)  # 设置数据集存储位置,采集数据所用的车辆型号
    client.sendMessage(Start(scenario=scenario, dataset=dataset))
    print("load deepGTAV successfully! \nbegin")

    while True:
        fo = open(txt_position, "r")  # 配置1
        txt = fo.read()
        fo.close()
        if txt == '0':
            tongji = open(tongji_position, "w+")
            tongji.write("left:" + str(left) + " right:" + str(right) +
                         " total:" + str(total))
            tongji.close()
            print('=====================end=====================')
            exit(0)
        elif txt == '1':
            drive()
Exemple #3
0
    def work(self):
        """
        Pretend this worker method does work that takes a long time. During this time, the thread's
        event loop is blocked, except if the application's processEvents() is called: this gives every
        thread (incl. main) a chance to process events, which in this sample means processing signals
        received from GUI (such as abort).
        """
        thread_name = QThread.currentThread().objectName()
        thread_id = int(
            QThread.currentThreadId())  # cast to int() is necessary
        self.sig_msg.emit('Running worker #{} from thread "{}" (#{})'.format(
            self.__id, thread_name, thread_id))

        # Creates a new connection to DeepGTAV using the specified ip and port.
        # If desired, a dataset path and compression level can be set to store in memory all the data received in a gziped pickle file.
        # We don't want to save a dataset in this case
        self.client = Client(ip=self.args.host, port=self.args.port)
        # self.client = Client(ip="127.0.0.1", port=8000)

        # We set the scenario to be in manual driving, and everything else random (time, weather and location).
        # See deepgtav/messages.py to see what options are supported
        scenario = Scenario(drivingMode=-1)  #manual driving

        # Send the Start request to DeepGTAV. Dataset is set as default, we only receive frames at 10Hz (320, 160)
        self.client.sendMessage(Start(scenario=scenario))

        # Dummy agent
        model = Model()

        # Start listening for messages coming from DeepGTAV. We do it for 80 hours
        stoptime = time.time() + 80 * 3600
        while (time.time() < stoptime and (not self.__abort)):
            # We receive a message as a Python dictionary
            app.processEvents()
            message = self.client.recvMessage()

            # The frame is a numpy array that can we pass through a CNN for example
            image = frame2numpy(message['frame'], (320, 160))
            commands = model.run(image)
            self.sig_step.emit(self.__id, 'step ' + str(time.time()))
            self.sig_image.emit(image.tolist())
            # We send the commands predicted by the agent back to DeepGTAV to control the vehicle
            self.client.sendMessage(
                Commands(commands[0], commands[1], commands[2]))

        # We tell DeepGTAV to stop
        self.client.sendMessage(Stop())
        self.client.close()

        self.sig_done.emit(self.__id)
Exemple #4
0
 def __init__(self, args_):
     self.__args = args_
     self.__driving_mode = [786603, 55.0]
     self.__driving_vehicle = 'Blista'
     self.__starting_time = 5
     self.__starting_weather = 4
     self.__starting_location = [-2730, 2300]
     self.__frame_size = [650, 418] 
     self.__client, self.__scenario, self.__dataset, self.__detection_pickleFile = None, None, None, None
     self.__total_written_images = 0
     self.__images_to_capture = self.__args['images_to_capture']
     self.__save_dir = self.__args['save_dir']
     self.__target_shape = (200,88)
     self.__labels_csv = None
     self.__init_client()
     self.__init_scenairo()
     self.__prepare_datasets()
     self.__client.sendMessage(Start(scenario=self.__scenario, dataset=self.__dataset))
     self.__old_location = []
Exemple #5
0
def reset(weatherIndex=0):
    ''' Resets position of car to a specific location '''
    # Same conditions as below |
    client.sendMessage(Stop())
    dataset = Dataset(rate=30,
                      frame=frame_capture_size,
                      throttle=True,
                      brake=True,
                      steering=True,
                      location=True,
                      speed=True,
                      yawRate=True,
                      direction=True)
    # dataset = Dataset(rate=30, frame=[400,300], throttle=True, brake=True, steering=True, location=True, speed=True, yawRate=True, direction=True, reward=[18.0, 0.5])
    # Automatic driving scenario
    # scenario = Scenario(weather='EXTRASUNNY',vehicle='voltic',time=[12,0],drivingMode=[786603,70.0],location=[-2573.13916015625, 3292.256103515625, 13.241103172302246])
    # scenario = Scenario(weather=weatherList[weatherIndex],vehicle='voltic',time=[12,0],drivingMode=[4294967295,70.0],location=[-2573.13916015625, 3292.256103515625, 13.241103172302246])
    scenario = Scenario(weather=weatherList[weatherIndex],
                        vehicle='voltic',
                        time=[12, 0],
                        drivingMode=[2883621, 20.0],
                        wander=False)
    client.sendMessage(Start(scenario=scenario,
                             dataset=dataset))  # Start request
Exemple #6
0
                        '--port',
                        default=8000,
                        help='The port where DeepGTAV is running')
    args = parser.parse_args()

    # Creates a new connection to DeepGTAV using the specified ip and port.
    # If desired, a dataset path and compression level can be set to store in memory all the data received in a gziped pickle file.
    # We don't want to save a dataset in this case
    client = Client(ip=args.host, port=args.port)

    # We set the scenario to be in manual driving, and everything else random (time, weather and location).
    # See deepgtav/messages.py to see what options are supported
    scenario = Scenario(drivingMode=-1)  #manual driving

    # Send the Start request to DeepGTAV. Dataset is set as default, we only receive frames at 10Hz (320, 160)
    client.sendMessage(Start(scenario=scenario))

    # Dummy agent
    model = Model()

    # Start listening for messages coming from DeepGTAV. We do it for 80 hours
    stoptime = time.time() + 80 * 3600
    while time.time() < stoptime:
        try:
            # We receive a message as a Python dictionary
            message = client.recvMessage()
            print(message)

            # The frame is a numpy array that can we pass through a CNN for example
            image = frame2numpy(message['frame'], (320, 160))
            commands = model.run(image)
Exemple #7
0
    # Dataset options
    dataset = Dataset(rate=30,
                      frame=[320, 160],
                      throttle=True,
                      brake=True,
                      steering=True,
                      location=True,
                      drivingMode=True)
    # Automatic driving scenario
    scenario = Scenario(
        weather='EXTRASUNNY',
        vehicle='blista',
        time=[12, 0],
        drivingMode=[786603, 20.0],
        location=[-2573.13916015625, 3292.256103515625, 13.241103172302246])
    client.sendMessage(Start(scenario=scenario,
                             dataset=dataset))  # Start request

    count = 0
    old_location = [0, 0, 0]

    while True:  # Main loop
        try:
            # Message recieved as a Python dictionary
            message = client.recvMessage()

            if (count % 100) == 0:
                print(count)

            # Checks if car is suck, resets position if it is
            if (count % 250) == 0:
                new_location = message['location']
	weathers = ["CLEAR", "EXTRASUNNY", "CLOUDS", "OVERCAST", "RAIN", "CLEARING", "THUNDER", "SMOG", "FOGGY", "XMAS", "SNOWLIGHT", "BLIZZARD", "NEUTRAL", "SNOW" ]
	hours = [0,4,8,12,16,20]
	## CREATE A REAL DATASET WITH WEATHER CONDITIONS IN DIRECTORY.
	for weather in weathers:
		# Creates a new connection to DeepGTAV using the specified ip and port. 
		# If desired, a dataset path and compression level can be set to store in memory all the data received in a gziped pickle file.
		for hour in hours:
			client = Client(ip=args.host, port=args.port, datasetPath=args.dataset_path, compressionLevel=9)
			infos = {}
			infos['weather'] = weather
			infos['hour'] = hour
			infos['time'] = int(time.time())

			# Configures the information that we want DeepGTAV to generate and send to us. 
			# See deepgtav/messages.py to see what options are supported
			dataset = Dataset(rate=4, frame=[1280,640], throttle=True, brake=True, steering=True, vehicles=True, peds=True, trafficSigns=True, reward=[15.0, 0.0], direction=None, speed=True, yawRate=True, location=True, time=True)
			# Send the Start request to DeepGTAV.
			scenario = Scenario(time=[hour,0],weather=weather,drivingMode=[786603,15.0]) # Driving style is set to normal, with a speed of 15.0 mph. All other scenario options are random.
			client.sendMessage(Start(dataset=dataset,scenario=scenario))
			stoptime = time.time() + 2*60
			while time.time() < stoptime:
				try:
					message = client.recvMessage(infos)	
				except KeyboardInterrupt:
				# We tell DeepGTAV to stop
					break
		# We tell DeepGTAV to stop
	client.sendMessage(Stop())
	client.close()
Exemple #9
0
    #See deepgtav/messages.py to see what options are supported
    dataset = Dataset(rate=30,
                      frame=[320, 160],
                      throttle=True,
                      brake=True,
                      steering=True,
                      vehicles=True,
                      peds=True,
                      reward=[15.0, 0.0],
                      direction=None,
                      speed=True,
                      yawRate=True,
                      location=True,
                      time=True)
    #Send the Start request to DeepGTAV. Scenario is set as default (random weather, position, time and driving style)
    client.sendMessage(Start(dataset=dataset))

    #Start listening for messages coming from DeepGTAV. We do it for 80 hours
    stoptime = time.time() + 80 * 3600
    while time.time() < stoptime:
        try:
            #We receive a message as a Python dictionary
            message = client.recvMessage()

            #The frame is a numpy array and can be displayed using OpenCV or similar
            #image = frame2numpy(message['frame'], (320,160))
            #cv2.imshow('img',image)
            #cv2.waitKey(-1)
        except KeyboardInterrupt:
            break
Exemple #10
0
def main():

    global client, scenario
    client = Client(ip='localhost', port=8000)  # Default interface
    scenario = Scenario(
        weather='EXTRASUNNY',
        vehicle='blista',
        time=[12, 0],
        drivingMode=-1,
        location=[-2583.6708984375, 3501.88232421875, 12.7711820602417])
    client.sendMessage(Start(scenario=scenario, dataset=dataset))
    print("load deepGTAV successfully! \nbegin")

    # load yolo v3
    classes = yolo_util.read_coco_names('./files/coco/coco.names')
    num_classes = len(classes)
    input_tensor, output_tensors = yolo_util.read_pb_return_tensors(
        tf.get_default_graph(), "./files/trained_models/yolov3.pb",
        ["Placeholder:0", "concat_9:0", "mul_6:0"])
    print("load yolo v3 successfully!")

    with tf.Session() as sess:
        model = load_model("files/trained_models/main_model.h5")
        print("load main_model successfully!")
        while True:
            fo = open(config_position, "r")  # 配置1
            txt = fo.read()
            fo.close()
            if txt == '0':
                set_gamepad(-1, -1, 0)
                time.sleep(0.7)
                print('=====================end=====================')
                exit(0)
            elif txt == '1':
                message = client.recvMessage()
                frame = frame2numpy(message['frame'], (CAP_IMG_W, CAP_IMG_H))
                image_obj = Image.fromarray(frame)

                speed = message['speed']

                boxes, scores = sess.run(output_tensors,
                                         feed_dict={
                                             input_tensor:
                                             np.expand_dims(
                                                 yolo_img_process(frame),
                                                 axis=0)
                                         })
                boxes, scores, labels = yolo_util.cpu_nms(boxes,
                                                          scores,
                                                          num_classes,
                                                          score_thresh=0.4,
                                                          iou_thresh=0.1)
                image, warning = yolo_util.draw_boxes(image_obj,
                                                      boxes,
                                                      scores,
                                                      labels,
                                                      classes,
                                                      (IMAGE_H, IMAGE_W),
                                                      show=False)

                control, throttle, breakk = drive(model=model,
                                                  image=frame,
                                                  speed=speed,
                                                  warning=warning)

                print(warning)

                set_gamepad(control, throttle, breakk)