Beispiel #1
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()
Beispiel #2
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)
Beispiel #3
0
def reset():
    # Resets position of the car to the starting location
    dataset = Dataset(rate=30,
                      frame=frame,
                      throttle=True,
                      brake=True,
                      steering=True,
                      location=True,
                      drivingMode=True)
    scenario = Scenario(weather=weather,
                        vehicle=vehicle,
                        time=time,
                        drivingMode=drivingMode,
                        location=location)
    Client.sendMessage(Config(scenario=scenario, dataset=dataset))
Beispiel #4
0
    #,yawRate=True,time=True,vehicles=True, peds=True, trafficSigns=True, direction=True, reward=True
    #[-1917.06640625, 4595.87255859375, 56.853]
    #-737.1954345703125, 1975.72265625, 133.54100036621094
    #[2723.626953125, 3224.170654296875, 54.402042388916016]
    #827.8175659179688, -1201.2620849609375, 45.51389694213867 街头竞速 没车
    scenario = Scenario(weather='EXTRASUNNY',
                        vehicle='blista',
                        time=[12, 0],
                        drivingMode=-1,
                        location=location)
    client.sendMessage(Config(scenario=scenario, dataset=dataset))


if image_source == USE_GTAV:
    client = Client(
        ip='localhost', port=8000
    )  #, datasetPath="self_driving.pz", compressionLevel=9) # Default interface
    '''
    try:
        #client.sendMessage(Stop()) # Stops DeepGTAV
        client.close()
    except Exception as e:
        pass

    client = Client(ip='localhost', port=8000, datasetPath="self_driving.pz", compressionLevel=9) # Default interface
    '''
    dataset = Dataset(rate=FPS,
                      frame=[show_imgwidth, show_imgheight],
                      throttle=True,
                      brake=True,
                      steering=True,
Beispiel #5
0
    port = 8000
    dataset_path = 'dataset.pz'
    log_freq = 10  # in minute
    max_stop_time = 10  # in second
    max_wall_time = 10  # in hour
    max_speed = 120  # in km
    rate = 30  # in HZ
    frame = [350, 205 + 20]

    logger.info(
        'Rate %s hz, frame %s, max_stop_time %s, max_wall_time %s, max_speed %s, dataset_path %s.'
        % (str(rate), str(frame), str(max_stop_time), str(max_wall_time),
           str(max_speed), str(dataset_path)))

    client = Client(ip=host,
                    port=port,
                    datasetPath=dataset_path,
                    compressionLevel=0)

    dataset = Dataset(rate=rate,
                      frame=frame,
                      throttle=True,
                      brake=True,
                      steering=True,
                      speed=True,
                      drivingMode=True,
                      location=True)

    scenario = Scenario(weather='EXTRASUNNY',
                        vehicle='voltic',
                        time=[12, 0],
                        drivingMode=[1074528293, max_speed / 1.6],
Beispiel #6
0
    return bgr


print("Loading Model...")
model = load_model(model_path)
print("Model Loaded. Compiling...")
sgd = SGD(lr=1e-3, decay=1e-4, momentum=0.9, nesterov=True)  # SGD Optimizer 사용
model.compile(optimizer=sgd, loss="mse")  # loss function 은 논문을 따라 "mean squared error"
model.summary()

if input("Continue?") == "y":  # Wait until you load GTA V to continue, else can't connect to DeepGTAV
    print("Conintuing...")

# Loads into a consistent starting setting
print("Loading Scenario...")
client = Client(ip='localhost', port=8000)  # Default interface
scenario = Scenario(weather=weather, vehicle=vehicle, time=time, drivingMode=-1, location=location)
client.sendMessage(Start(scenario=scenario))

hwnd_list = _get_windows_bytitle("Grand Theft Auto V", exact=True)  # window 를 받아온다.

count = 0
print("Starting Loop...")
while True:
    try:
        # Collect and preprocess image
        # message = client.recvMessage()
        # window title 을 이용해 받아온 window 에서 frame 을 따온다.
        # 기존의 기능에서 이를 제대로 지원하지 않는듯 하기 때문에 추가로 작성함.
        frame_image = screenshot(hwnd=hwnd_list[0])
        # frame_image = normalize(frame_image)
Beispiel #7
0
    def __call__(self, v):
        return UNIT(self.tpe, v)

    def __rmul__(self, o):
        from numbers import Number
        assert isinstance(o, Number), "Can only specify numeric unit types"
        return UNIT(self.tpe, o * self.value)


MS = UNIT(0)  # Milliseconds
FRAMES = UNIT(1)  # Frames

if __name__ == "__main__":
    from time import time, sleep

    c = Client(('localhost', 8766))
    print(c)
    if not c.control():
        print("Failed to gain control over game, just watching then ...")
    c.reset()
    t0 = time()
    #for i in range(100):
    target_list = c.listTargets()
    print(target_list)

    c.startScenarios()

    #c.interceptKeys(print)
    c.fetchGameState(print, 1 * FRAMES)

    import matplotlib
Beispiel #8
0
                        '--host',
                        default='localhost',
                        help='The IP where DeepGTAV is running')
    parser.add_argument('-p',
                        '--port',
                        default=8000,
                        help='The port where DeepGTAV is running')
    parser.add_argument('-d',
                        '--dataset_path',
                        default='dataset_test.pz',
                        help='Place to store the dataset')
    args = parser.parse_args()

    # Creates a new connection to DeepGTAV using the specified ip and port
    client = Client(ip=args.host,
                    port=args.port,
                    datasetPath=args.dataset_path,
                    compressionLevel=9)
    # 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],
# Stores a dataset file with data coming from DeepGTAV
if __name__ == '__main__':
	parser = argparse.ArgumentParser(description=None)
	parser.add_argument('-l', '--host', default='localhost', help='The IP where DeepGTAV is running')
	parser.add_argument('-p', '--port', default=8000, help='The port where DeepGTAV is running')
	parser.add_argument('-d', '--dataset_path', default='dataset.pz', help='Place to store the dataset')
	args = parser.parse_args()

	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)	
Beispiel #10
0
# Stores a pickled dataset file with data coming from DeepGTAV
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=None)
    parser.add_argument('-l', '--host', default='10.60.124.42',
                     help='The IP where DeepGTAV is running')
    parser.add_argument('-p', '--port', default=8000,
                     help='The port where DeepGTAV is running')
    parser.add_argument('-d', '--dataset_path', default='dataset.pz',
                     help='Place to store the dataset')
    parser.add_argument('-s', '--save_data', default=False,
                     help='Record data?')
    args = parser.parse_args()

    # Creates a new connection to DeepGTAV using the specified ip and port

    client = Client(ip=args.host, port=args.port)
    # Dataset options
    dataset = Dataset(
            rate=10, 
            frame=[640, 320],
            throttle=True, 
            brake=True, 
            steering=True,
            location=True, 
            speed=True, 
            yawRate=True,
            vehicles=True,
            direction=[-2573.13916015625, 2000, 13.241103172302246]
            )

    # Automatic driving scenario
Beispiel #11
0
json_file = open(NAME + '.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
# load weights into new model
model.load_weights(NAME + ".h5")
print("Loaded model from disk")
print("Model Loaded. Compiling...")
model.compile(optimizer='Adadelta', loss='mean_squared_error')
'''
if input("Continue?") == "y": # Wait until you load GTA V to continue, else can't connect to DeepGTAV
    print("Conintuing...")
'''
# Loads into a consistent starting setting
print("Loading Scenario...")
client = Client(ip='localhost', port=8000)  # Default interface
dataset = Dataset(rate=60,
                  frame=[800, 600],
                  throttle=True,
                  brake=True,
                  steering=True,
                  location=True,
                  drivingMode=True)
scenario = Scenario(
    weathers='EXTRASUNNY', vehicle='blista', times=[12, 0], drivingMode=-1
)  #, location=[-2573.13916015625, 3292.256103515625, 13.241103172302246])
client.sendMessage(Start(scenario=scenario))

count = 0
print("Starting Loop...")
while True:
Beispiel #12
0
    parser.add_argument(
        '-vl',
        '--video_len',
        default=300,
        type=int,
        help='Length of video to record in seconds, default 0.42*3600')

    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.

    client = Client(
        ip=args.host,
        port=args.port,
        datasetPath="tmp.gz",
        compressionLevel=0)
    for i_trial in range(args.n_trials):
        # Scenario parameters: time, weather, location
        # with open("highway.np", "rb") as f:
        #     x_list, y_list, _ = np.load(f)
        # args.time[0] = np.random.randint(5, 18)
        # args.time[1] = np.random.randint(0, 60)
        # weather = weather_list[np.random.randint(0, len(weather_list))]
        # rand_loc_idx = np.random.randint(len(x_list))
        # while not (args.loc_x_range[0] < x_list[rand_loc_idx] <
        #                args.loc_x_range[1] and
        #                        args.loc_y_range[0] < y_list[rand_loc_idx] <
        #                    args.loc_y_range[1]):
        #     rand_loc_idx = np.random.randint(len(x_list))
Beispiel #13
0
 def __init_client(self):
     self.__client = Client(
         ip=self.__args['host'], port=self.__args['port'])
Beispiel #14
0
class Data_Generator:

    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 = []
        

    def __build_env(self):
        self.__init_scenairo()
        self.__prepare_datasets(open_=False)
        self.__client.sendMessage(Config(scenario=self.__scenario, dataset=self.__dataset))
        
    def __init_scenairo(self):
        self.__scenario = Scenario(drivingMode=self.__driving_mode, vehicle=self.__driving_vehicle,
                                   time=self.__starting_time, weather=self.__starting_weather, location=self.__starting_location)

    def __init_client(self):
        self.__client = Client(
            ip=self.__args['host'], port=self.__args['port'])

    def __prepare_datasets(self, open_=True, fps=20, throttle_=True, brake_=True, steering_=True, vehicles_=True, peds_=True, speed_=True, location_=True, detection_file_name_='detection1.pickle'):
        self.__dataset = Dataset(rate=fps, frame=self.__frame_size, throttle=throttle_, brake=brake_,
                          steering=steering_, vehicles=vehicles_, time=True, peds=peds_, speed=speed_, location=location_)
        if open_:
            self.__detection_pickleFile = open(detection_file_name_, mode='wb')
            self.__labels_csv = open('labels.csv', 'wb')
    
    def __save_image(self, image):
        cv2.imwrite(self.__save_dir +str(self.__total_written_images)+'.png', image)

    def __process_image(self, image, up_crop=110, down_crop=40 ):
        return cv2.resize(image[up_crop:-down_crop, :], dsize=self.__target_shape)
        

    def __recv_message(self):
        message = self.__client.recvMessage()
        image = frame2numpy(message['frame'], (self.__frame_size[0], self.__frame_size[1]))
        detect = dict()
        detect['peds'] = message['peds']
        detect['vehicles'] = message['vehicles']
        recv_labels = [message['steering'],
                           message['throttle'], message['brake'], message['speed'], message['time']]

        return message, self.__process_image(image= image), recv_labels, detect
    
    def __close_all(self):
        self.__detection_pickleFile.close()
        self.__labels_csv.close()
        self.__client.sendMessage(Stop())
        self.__client.close()

    def __dump_all(self, labels, detect_list):
        np.savetxt(self.__labels_csv, labels, delimiter=',')
        for object_ in detect_list:
            pickle.dump(object_, self.__detection_pickleFile)

    def generate_dataset(self):
        reset_images = 0
        counter = 0
        reset_threshold = 6000
        labels = np.zeros((1000,5), dtype=np.float32)
        detect_list = []

        for i in tqdm(np.arange(self.__images_to_capture - self.__total_written_images)):
            try:
                message, image, labels[counter], detect = self.__recv_message()
                self.__save_image(image)
                detect_list.append(detect)
                self.__total_written_images += 1
                reset_images += 1
                counter += 1
                if ((counter) % 1000 == 0 and counter > 0) or ((counter) % 1000 == 0 and counter > 0 and reset_images >= reset_threshold):
                    if (counter) % 1000 == 0 or reset_images >= reset_threshold:
                        #                 print ('Saved : ',total_images)
                        self.__dump_all(labels, detect_list)
                    else:
                        self.__total_written_images -= 1000
                        self.__build_env()

                    if reset_images >= reset_threshold:
                        reset_images = 0
                        self.__build_env()

                    counter = 0
                    detect_list = []

                # We send the commands predicted by the agent back to DeepGTAV to control the vehicle
            except KeyboardInterrupt:
                self.__close_all()
                break
        self.__close_all()
        print(self.__total_written_images)
Beispiel #15
0
    parser.add_argument('-sp', '--speed', default=True, help='speed')
    parser.add_argument('-y', '--yawRate', default=True, help='yawRate')
    parser.add_argument('-il', '--if_location', default=True, help='location')
    parser.add_argument(
        '-nw',
        '--n_workers',
        default=4,
        help='Number of workers to receive messages in parallel')

    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.

    client = Client(ip=args.host, port=args.port)
    with open("road.np", "rb") as f:
        x_list, y_list, z_list = np.load(f)
    args.time[0] = np.random.randint(8, 20)
    args.time[1] = np.random.randint(0, 60)
    weather = 'EXTRASUNNY'
    rand_loc_idx = np.random.randint(len(x_list))
    while not (x_list[rand_loc_idx] > args.loc_x_range[0]
               and x_list[rand_loc_idx] < args.loc_x_range[1]
               and y_list[rand_loc_idx] > args.loc_y_range[0]
               and y_list[rand_loc_idx] < args.loc_y_range[1]):
        rand_loc_idx = np.random.randint(len(x_list))
    args.location[0] = x_list[rand_loc_idx]
    args.location[1] = y_list[rand_loc_idx]
    args.des = [0, 0, 0]
    with open("path.np", "rb") as f:
Beispiel #16
0
        '--video_len',
        default=1200,
        type=int,
        help='Length of video to record in seconds, default 0.42*3600')

    args = parser.parse_args()
    args.driving_mode = [args.policy, args.maxspeed]
    print(args.driving_mode)

    # 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.

    client = Client(
        ip=args.host,
        port=args.port,
        datasetPath="tmp.gz",
        compressionLevel=0)
    for i_trial in range(args.n_trials):
        # Scenario parameters: time, weather, location
        with open("highway.np", "rb") as f:
            x_list, y_list, _ = np.load(f)
        # with open("road.np", "rb") as f:
        #     x_list_, y_list_, z_list_ = np.load(f)
        # x_list, y_list, z_list = np.hstack((x_list,x_list_)), np.hstack((y_list, y_list_)), np.hstack((z_list, z_list_))
        # with open("sampled_path_points.np", "rb") as f:
        #     x_list, y_list = np.load(f)
        args.time[0] = 12#np.random.randint(8, 20)
        args.time[1] = 51#np.random.randint(0, 60)
        weather = 'EXTRASUNNY'#weather_list[np.random.randint(0, len(weather_list))]
        rand_loc_idx = np.random.randint(len(x_list))
Beispiel #17
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=None)
    parser.add_argument('-l',
                        '--host',
                        default='localhost',
                        help='The IP where DeepGTAV is running')
    parser.add_argument('-p',
                        '--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
    Route0 = [
        -1989.000000, -468.250000, 10.562500, 1171.351563, -1925.791748,
        36.220097
    ]

    Route1 = [
        -1889.000000, -368.250000, 10.562500, 1171.351563, -1925.791748,
        36.220097
    ]

    Route2 = [
    hdr.setFormatter(formatter)
    logger.addHandler(hdr)

    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    new_settings = old_settings
    new_settings[3] = new_settings[3] & ~termios.ICANON
    new_settings[3] = new_settings[3] & ~termios.ECHONL
    #print("old setting %s" %(repr(old_settings)))
    termios.tcsetattr(fd, termios.TCSAFLUSH, new_settings)

    # 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.
    #client = Client(ip=args.host, port=args.port, datasetPath=args.dataset_path, compressionLevel=9)
    #client = Client(ip=args.host, port=args.port, compressionLevel=9)
    client = Client(ip="10.29.1.135", port=args.port, compressionLevel=9)

    # Configures the information that we want DeepGTAV to generate and send to us.
    # See deepgtav/messages.py to see what options are supported
    #rate = 30 kong
    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,
Beispiel #19
0
import cv2
import numpy as np

print("Loading Model...")
model = load_model('sample_model.h5')  # Load trained model
print("Model Loaded. Compiling...")
model.compile(optimizer='Adadelta', loss='mean_squared_error')

if input(
        "Continue?"
) == "y":  # Wait until you load GTA V to continue, else can't connect to DeepGTAV
    print("Conintuing...")

# Loads into a consistent starting setting
print("Loading Scenario...")
client = Client(ip='localhost', port=8000)  # Default interface
scenario = Scenario(
    weather='EXTRASUNNY',
    vehicle='blista',
    time=[12, 0],
    drivingMode=-1,
    location=[-2573.13916015625, 3292.256103515625, 13.241103172302246])
client.sendMessage(Start(scenario=scenario))

count = 0
print("Starting Loop...")
while True:
    try:
        # Collect and preprocess image
        message = client.recvMessage()
        image = frame2numpy(message['frame'], (320, 160))
Beispiel #20
0
    weatherCount = 0
    to_remove = []
    speed = []
    direction = []
    pred_speed = None
    pred_dir = None

    # how much data to collect
    data_to_collect_per_weather = 20000
    rep_per_weather = 4
    reset_every = int(data_to_collect_per_weather / rep_per_weather)

    # Creates a new connection to DeepGTAV using the specified ip and port
    client = Client(ip=args.host,
                    port=args.port,
                    datasetPath=args.dataset_path,
                    compressionLevel=9,
                    frame_capture_size=frame_capture_size,
                    frame_save_size=frame_save_size)
    reset(weatherCount)

    print('Data to collect per weather:', data_to_collect_per_weather)
    print('Reset every:', reset_every, 'frames in each weather\n')
    print('{:>15} | {:^16} | {:^21} | {:^8} | {}'.format(
        "Weather", "Progress", "[str, thtl, brk]", "Speed", "Direction"))

    while True:  # Main loop
        try:
            # Message recieved as a Python dictionary
            message = client.recvMessage(pre_count + 1 >= 0)
            if message is None:
                print('Message Error')
Beispiel #21
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=None)
    parser.add_argument('-l',
                        '--host',
                        default='localhost',
                        help='The IP where DeepGTAV is running')
    parser.add_argument('-p',
                        '--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:
Beispiel #22
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)