예제 #1
0
파일: driveGUI.py 프로젝트: jfjensen/VPilot
    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)
예제 #2
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
예제 #3
0
    # 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)
            # We send the commands predicted by the agent back to DeepGTAV to control the vehicle
            client.sendMessage(Commands(commands[0], commands[1], commands[2]))
        except KeyboardInterrupt:
            break

    # We tell DeepGTAV to stop
    client.sendMessage(Stop())
    client.close()
예제 #4
0
count = 0
print("Starting Loop...")
while True:
    try:
        # Collect and preprocess image
        message = client.recvMessage()
        image = frame2numpy(message['frame'], (320, 160))
        image = ((image / 255) - .5) * 2

        # Corrects for model input shape
        model_input = []
        model_input.append(image)

        # Converts classification to float for steering input
        category_prediction = np.argmax(model.predict(np.array(model_input)))
        decimal_prediction = (category_prediction - 500) / 500
        print('Category: ' + str(category_prediction) + '     Decimal: ' +
              str(decimal_prediction))

        client.sendMessage(Commands(
            0.0, 0.0, decimal_prediction *
            3))  # Mutiplication scales decimal prediction for harder turning
        count += 1
    except Exception as e:
        print("Excepted as: " + str(e))
        continue

client.sendMessage(Stop())  # Stops DeepGTAV
client.close()
예제 #5
0
 def __close_all(self):
     self.__detection_pickleFile.close()
     self.__labels_csv.close()
     self.__client.sendMessage(Stop())
     self.__client.close()