示例#1
0
def generate_thunderhill_batches(df, args):

    while True:
        batch_x = []
        batch_y = []

        for idx, row in df.iterrows():
            steering_angle = row['steering']
            speed = row['speed']
            brake = row['brake']
            throttle = row['throttle']
            img = ReadImg(row['center'])
            img, steering_angle = RandomShift(img, steering_angle,
                                              args.adjustement)
            img, steering_angle = RandomFlip(img, steering_angle)
            img, steering_angle = RandomBrightness(img, steering_angle)
            img, steering_angle = RandomRotation(img, steering_angle)
            img, steering_angle = RandomBlur(img, steering_angle)
            # Preproc is after ....
            img = Preproc(img)
            batch_x.append(np.reshape(img, (1, HEIGHT, WIDTH, DEPTH)))
            batch_y.append([steering_angle, throttle, brake])
            if len(batch_x) == args.batch:
                batch_x, batch_y = shuffle(batch_x, batch_y)
                yield np.vstack(batch_x), np.vstack(batch_y)
                batch_x = []
                batch_y = []
示例#2
0
def generate_batches(df, batch_size, basename='data'):

    while True:

        batch_x = []
        batch_y = []

        for idx, row in df.iterrows():
            camera = np.random.choice(['left', 'center', 'right'])
            img = ReadImg('{}/{}'.format(basename, row[camera].strip()))

            if camera == 'left':
                steering_angle = min(row['steering'] + .20, 1)
            elif camera == 'center':
                steering_angle = row['steering']
            elif camera == 'right':
                steering_angle = max(row['steering'] - .20, -1)

            img, steering_angle = RandomShift(img, steering_angle)
            img, steering_angle = RandomFlip(img, steering_angle)
            img, steering_angle = RandomBrightness(img, steering_angle)

            img = Preproc(img)
            batch_x.append(np.reshape(img, (1, 66, 200, 3)))
            batch_y.append([steering_angle])

            if len(batch_x) == batch_size:
                batch_x, batch_y = shuffle(batch_x, batch_y)
                yield np.vstack(batch_x), np.vstack(batch_y)
                batch_x = []
                batch_y = []
示例#3
0
def generate_thunderhill_batches(gen, batch_size):
    batch_x = []
    batch_y = []
    while True:
        for img, steering_angle in gen:
            for img1, steering_angle1 in RandomFlip(img, steering_angle):
                img1, steering_angle1 = RandomBrightness(img1, steering_angle1)
                img1, steering_angle1 = RandomShift(img1, steering_angle1)
                img1 = Preproc(img1)
                if steering_angle1 > 1:
                    steering_angle1 = 1
                if steering_angle1 < -1:
                    steering_angle1 = -1

                font = cv2.FONT_HERSHEY_SIMPLEX
                if show_images:
                    imgp = Preproc(img.copy())
                    imgshow = (np.concatenate((imgp, img1), axis=1) + 0.5)
                    cv2.putText(imgshow, '%.3f' % (steering_angle), (10, 50),
                                font, 1, (0, 0, 255), 1, cv2.LINE_AA)
                    cv2.putText(imgshow, '%.3f' % (steering_angle1), (330, 50),
                                font, 1, (0, 0, 255), 1, cv2.LINE_AA)
                    cv2.imshow('img', imgshow)
                    cv2.waitKey(0)
                batch_x.append(np.reshape(img1, (1, HEIGHT, WIDTH, DEPTH)))
                batch_y.append([steering_angle1])
                if len(batch_x) == batch_size:
                    batch_x, batch_y = shuffle(batch_x, batch_y)
                    yield np.vstack(batch_x), np.vstack(batch_y)
                    batch_x = []
                    batch_y = []
示例#4
0
def generate_thunderhill_batches(gen, batch_size):
    batch_x = []
    batch_x2 = []
    batch_y = []
    tasks=[]
    while True:
        for img, steering_angle, throttle, brake, speed in gen:
            for img1, steering_angle1 in RandomFlip(img, steering_angle):

                img1 = Preproc(img1)

                tasks.append((img1, steering_angle1, throttle, brake, speed))

                if len(tasks)==BATCH_SIZE:
                    results = dispatch_tasks(worker, tasks, multiprocessing.cpu_count())
                    tasks=[]
                    for i,result in enumerate(results):
                        res_list = result.get()

                        batch_x.append(res_list[0][0])
                        batch_x2.append(res_list[0][1])
                        batch_y.append(res_list[1])
                    print(len(batch_x))
                    if len(batch_x) == batch_size:
                        batch_x, batch_x2, batch_y = shuffle(batch_x, batch_x2, batch_y)
                        yield [np.vstack(batch_x), np.vstack(batch_x2)], np.vstack(batch_y)
                        batch_x = []
                        batch_x2 = []
                        batch_y = []
示例#5
0
def generate_thunderhill_batches(df, args):

    while True:
        batch_x = []
        batch_y = []
        sample_weights = []

        for idx, row in df.iterrows():
            steering_angle = row['steering']
            speed = row['speed']
            brake = row['brake']
            throttle = row['throttle']
            longitude = row['longitude']
            latitude = row['latitude']
            img = ReadImg(row['center'])
            img, steering_angle = RandomShift(img, steering_angle,
                                              args.adjustement)
            img, steering_angle = RandomFlip(img, steering_angle)
            img, steering_angle = RandomBrightness(img, steering_angle)
            img, steering_angle = RandomRotation(img, steering_angle)
            img, steering_angle = RandomBlur(img, steering_angle)
            # Preproc is after ....
            img = Preproc(img)
            batch_x.append(np.reshape(img, (1, HEIGHT, WIDTH, DEPTH)))

            # Lap Distance
            UTMp = LatLontoUTM(RadToDeg(longitude), RadToDeg(latitude))
            _, _, LapDistance = NearestWayPointCTEandDistance(UTMp)
            LapDistance = 2 * (LapDistance / total_lap_distance) - 1

            batch_y.append([steering_angle, LapDistance])

            sample_weights.append(row['norm'])

            if len(batch_x) == args.batch:
                yield (np.vstack(batch_x), np.vstack(batch_y),
                       np.array(sample_weights))
                batch_x = []
                batch_y = []
                sample_weights = []
示例#6
0
def generate_thunderhill_batches(df, batch_size):

    while True:

        batch_x = []
        batch_y = []

        for idx, row in df.iterrows():
            steering_angle = row['steering']
            # img = ReadImg('{}/{}'.format(basename, row['center'].strip()))
            img = ReadImg(row['center'])
            img, steering_angle = RandomShift(img, steering_angle)
            img, steering_angle = RandomFlip(img, steering_angle)
            img, steering_angle = RandomBrightness(img, steering_angle)
            img = Preproc(img)
            batch_x.append(np.reshape(img, (1, 66, 200, 3)))
            batch_y.append([steering_angle])

            if len(batch_x) == batch_size:
                batch_x, batch_y = shuffle(batch_x, batch_y)
                yield np.vstack(batch_x), np.vstack(batch_y)
                batch_x = []
                batch_y = []
示例#7
0
def generate_thunderhill_batches(gen, batch_size):
    batch_x = []
    batch_x2 = []
    batch_y = []
    while True:
        for img, steering_angle, throttle, brake, speed, longitude, latitude in gen:
            for img1, steering_angle1 in RandomFlip(img, steering_angle):
                img1, steering_angle1 = RandomBrightness(img1, steering_angle1)
                img1 = Preproc(img1)
                img1, steering_angle1, throttle1 = RandomShift(img1, steering_angle1,throttle)

                brake1=brake

                if steering_angle1>0.5:
                    brake1=1
                    throttle1=0
                if steering_angle1<-0.5:
                    brake1=1
                    throttle1=0

                if np.random.uniform() < 0.5:
                    speed1 = speed * np.random.uniform()
                else:
                    speed1 = speed

                # speed_cl=np.array(speedToClass(speed))
                # speed_cl1=np.array(speedToClass(speed1))

                if speed1 < 20*0.44704:
                    throttle1=1
                if speed1 > 50*0.44704:
                    throttle1=0
                if speed1 > 70*0.44704:
                    throttle1=0
                    brake=1

                if brake>0.7:
                    throttle=0

                # if speed_cl[-2]==1 and steering_angle1!=0:
                #     throttle1=0
                # if speed_cl[-1]==1 and steering_angle1!=0:
                #     brake1=1
                #     throttle1=0

                batch_x.append(np.reshape(img1, (1, HEIGHT, WIDTH, DEPTH)))

                spd1 = speed1/40 - 0.5
                batch_x2.append(spd1)

                font = cv2.FONT_HERSHEY_SIMPLEX
                if show_images:
                    imgp = Preproc(img.copy()[::-1,:,:])
                    imgshow=(np.concatenate((imgp,img1[::-1,:,:]),axis=0)+0.5)*0.5

                    imgshow = cv2.resize(imgshow,(0,0),fx=2,fy=2)
                    # cv2.putText(imgshow,'%s'%(str(list(speed_cl))),(10,30), font, 0.8,(0,0,255),2,cv2.LINE_AA)
                    # cv2.putText(imgshow,'%s'%(str(list(speed_cl1))),(10,190), font, 0.8,(0,0,255),2,cv2.LINE_AA)
                    cv2.putText(imgshow,'%.3f %.1f %.1f %.1f'%(steering_angle,throttle, brake,speed),(10,140), font, 0.8,(0,0,255),2,cv2.LINE_AA)
                    cv2.putText(imgshow,'%.3f %.1f %.1f %.1f'%(steering_angle1,throttle1, brake1,speed1),(10,300), font, 0.8,(0,0,255),2,cv2.LINE_AA)

                    cv2.putText(imgshow,'%.5f %.5f'%(longitude, latitude),(10,110), font, 0.8,(0,0,255),2,cv2.LINE_AA)
                    cv2.imshow('img',imgshow)
                    cv2.waitKey(0)


                batch_y.append([steering_angle1,throttle1, brake1])
                if len(batch_x) == batch_size:
                    batch_x, batch_x2, batch_y = shuffle(batch_x, batch_x2, batch_y)
                    yield [np.vstack(batch_x), np.vstack(batch_x2)], np.vstack(batch_y)
                    batch_x = []
                    batch_x2 = []
                    batch_y = []
示例#8
0
def generate_thunderhill_batches(gen, batch_size):
    batch_x = []
    batch_x2 = []
    batch_y = []
    while True:
        for img, steering_angle, throttle, brake, speed in gen:
            for img1, steering_angle1 in RandomFlip(img, steering_angle):
                img1, steering_angle1 = RandomBrightness(img1, steering_angle1)
                img1, steering_angle1, throttle1 = RandomShift(
                    img1, steering_angle1, throttle)
                img1 = Preproc(img1)
                if steering_angle1 > 1:
                    steering_angle1 = 1
                if steering_angle1 < -1:
                    steering_angle1 = -1

                brake1 = brake

                if steering_angle1 > 0.5:
                    brake1 = 1
                    throttle1 = 0
                if steering_angle1 < -0.5:
                    brake1 = 1
                    throttle1 = 0

                speed_cl = np.array(speedToClass(speed))

                if speed_cl[-2] == 1 and steering_angle1 != 0:
                    throttle1 = 0
                if speed_cl[-1] == 1 and steering_angle1 != 0:
                    brake1 = 1
                    throttle1 = 0

                font = cv2.FONT_HERSHEY_SIMPLEX
                if show_images:
                    imgp = Preproc(img.copy())
                    imgshow = (np.concatenate(
                        (imgp, img1), axis=0) + 0.5) * 0.5
                    cv2.putText(imgshow, '%s' % (str(list(speed_cl))),
                                (10, 30), font, 0.4, (0, 0, 255), 1,
                                cv2.LINE_AA)

                    cv2.putText(
                        imgshow, '%.3f %.1f %.1f %.1f' %
                        (steering_angle, throttle, brake, speed), (10, 70),
                        font, 0.4, (0, 0, 255), 1, cv2.LINE_AA)
                    cv2.putText(
                        imgshow, '%.3f %.1f %.1f' %
                        (steering_angle1, throttle1, brake1), (10, 150), font,
                        0.4, (0, 0, 255), 1, cv2.LINE_AA)
                    cv2.imshow('img', imgshow)
                    cv2.waitKey(0)
                batch_x.append(np.reshape(img1, (1, HEIGHT, WIDTH, DEPTH)))
                batch_x2.append(speed_cl)
                batch_y.append([steering_angle1, throttle1, brake1])
                if len(batch_x) == batch_size:
                    batch_x, batch_x2, batch_y = shuffle(
                        batch_x, batch_x2, batch_y)
                    yield [np.vstack(batch_x),
                           np.vstack(batch_x2)], np.vstack(batch_y)
                    batch_x = []
                    batch_x2 = []
                    batch_y = []
示例#9
0
def generate_thunderhill_batches(gen, batch_size):
    batch_x = []
    batch_x2 = []
    batch_x3 = []
    batch_y = []
    while True:
        for img, steering_angle, throttle, brake, speed, longitude, latitude in gen:
            for img1, steering_angle1 in RandomFlip(img, steering_angle):
                img1, steering_angle1 = RandomBrightness(img1, steering_angle1)
                img1 = Preproc(img1)
                img1, steering_angle1, throttle1 = RandomShift(
                    img1, steering_angle1, throttle)

                brake1 = brake

                if steering_angle1 > 0.5:
                    brake1 = 1
                    throttle1 = 0
                if steering_angle1 < -0.5:
                    brake1 = 1
                    throttle1 = 0

                if np.random.uniform() < 0.5:
                    speed1 = speed * np.random.uniform()
                else:
                    speed1 = speed

                speed_cl = np.array(speedToClass(speed))
                speed_cl1 = np.array(speedToClass(speed1))

                if speed1 < 20 * 0.44704:
                    throttle1 = 1
                if speed1 > 50 * 0.44704:
                    throttle1 = 0
                if speed1 > 70 * 0.44704:
                    throttle1 = 0
                    brake = 1

                if brake > 0.7:
                    throttle = 0

                # if speed_cl[-2]==1 and steering_angle1!=0:
                #     throttle1=0
                # if speed_cl[-1]==1 and steering_angle1!=0:
                #     brake1=1
                #     throttle1=0

                batch_x.append(np.reshape(img1, (1, HEIGHT, WIDTH, DEPTH)))
                batch_x2.append(speed_cl1)

                UTMp = LatLontoUTM(RadToDeg(longitude), RadToDeg(latitude))
                CTE, Distance2NextWaypoint, LapDistance = NearestWayPointCTEandDistance(
                    UTMp)

                CTE /= 5.0
                LapDistance = 2 * (LapDistance / total_lap_distance) - 1

                font = cv2.FONT_HERSHEY_SIMPLEX
                if show_images and (CTE > 100 or LapDistance > 2
                                    or LapDistance < -2):
                    imgp = Preproc(img.copy()[::-1, :, :])
                    imgshow = (np.concatenate(
                        (imgp, img1[::-1, :, :]), axis=0) + 0.5) * 0.5

                    imgshow = cv2.resize(imgshow, (0, 0), fx=2, fy=2)
                    cv2.putText(imgshow, '%s' % (str(list(speed_cl))),
                                (10, 30), font, 0.8, (0, 0, 255), 2,
                                cv2.LINE_AA)
                    cv2.putText(imgshow, '%s' % (str(list(speed_cl1))),
                                (10, 190), font, 0.8, (0, 0, 255), 2,
                                cv2.LINE_AA)
                    cv2.putText(
                        imgshow, '%.3f %.1f %.1f %.1f' %
                        (steering_angle, throttle, brake, speed), (10, 140),
                        font, 0.8, (0, 0, 255), 2, cv2.LINE_AA)
                    cv2.putText(
                        imgshow, '%.3f %.1f %.1f %.1f' %
                        (steering_angle1, throttle1, brake1, speed1),
                        (10, 300), font, 0.8, (0, 0, 255), 2, cv2.LINE_AA)

                    cv2.putText(imgshow, '%.5f %.5f' % (longitude, latitude),
                                (10, 110), font, 0.8, (0, 0, 255), 2,
                                cv2.LINE_AA)
                    cv2.putText(imgshow, '%.3f %.3f' % (CTE, LapDistance),
                                (10, 250), font, 0.8, (0, 0, 255), 2,
                                cv2.LINE_AA)
                    cv2.imshow('img', imgshow)
                    cv2.waitKey(0)

                batch_x3.append((CTE, LapDistance))

                batch_y.append([steering_angle1, throttle1, brake1])
                if len(batch_x) == batch_size:
                    batch_x, batch_x2, batch_x3, batch_y = shuffle(
                        batch_x, batch_x2, batch_x3, batch_y)
                    yield [
                        np.vstack(batch_x),
                        np.vstack(batch_x2),
                        np.vstack(batch_x3)
                    ], np.vstack(batch_y)
                    batch_x = []
                    batch_x2 = []
                    batch_x3 = []
                    batch_y = []