Ejemplo n.º 1
0
def load_imgs():
    global imgs
    global wheels

    for p in purposes:
        for epoch_id in epochs[p]:
            print 'processing and loading "{}" datasets {} into memory, current num of imgs is {}...'.format(
                p, epoch_id, len(imgs[p]))
            vid_path = data_dir + "/dataset{0}/out-mencoder.avi".format(
                epoch_id)
            assert os.path.isfile(vid_path)

            frame_count = cm.frame_count(vid_path)
            cap = cv2.VideoCapture(vid_path)

            csv_path = data_dir + "/dataset%i/data.csv" % epoch_id
            assert os.path.isfile(csv_path)
            rows = cm.fetch_csv_data(csv_path)
            assert frame_count == len(rows)
            yy = [[float(row['angle'])] for row in rows]

            while True:
                ret, img = cap.read()
                if not ret:
                    break

                if img.any():
                    img = preprocess.preprocess(img)
                    imgs[p].append(img)

            wheels[p].extend(yy)
            assert len(imgs[p]) == len(wheels[p])

            cap.release()
Ejemplo n.º 2
0
def load_imgs():
    global imgs
    global wheels

    for p in purposes:
        for epoch_id in epochs[p]:
            print 'processing and loading "{}" epoch {} into memory, current num of imgs is {}...'.format(
                p, epoch_id, len(imgs[p]))

            vid_path = cm.jn(data_dir, 'epoch{:0>2}_front.mkv'.format(epoch_id))
            assert os.path.isfile(vid_path)
            frame_count = cm.frame_count(vid_path)
            cap = cv2.VideoCapture(vid_path)

            csv_path = cm.jn(data_dir, 'epoch{:0>2}_steering.csv'.format(epoch_id))
            assert os.path.isfile(csv_path)
            rows = cm.fetch_csv_data(csv_path)
            assert frame_count == len(rows)
            yy = [[float(row['wheel'])] for row in rows]

            while True:
                ret, img = cap.read()
                if not ret:
                    break

                img = preprocess.preprocess(img)
                imgs[p].append(img)

            wheels[p].extend(yy)
            assert len(imgs[p]) == len(wheels[p])

            cap.release()
Ejemplo n.º 3
0
def load_imgs():
    global imgs
    global wheels

    for p in purposes:
        for epoch_id in epochs[p]:
            print 'processing and loading "{}" datasets {} into memory, current num of imgs is {}...'.format(p, epoch_id, len(imgs[p]))
            vid_path = data_dir +"/dataset{0}/out-mencoder.avi".format(epoch_id) 
            assert os.path.isfile(vid_path)

            frame_count = cm.frame_count(vid_path)
            cap = cv2.VideoCapture(vid_path)

            csv_path = data_dir + "/dataset%i/data.csv" % epoch_id
            assert os.path.isfile(csv_path)
            rows = cm.fetch_csv_data(csv_path)
            assert frame_count == len(rows)
            yy = [[float(row['angle'])] for row in rows]

            while True:
                ret, img = cap.read()
                if not ret:
                    break

                if img.any():
                    img = preprocess.preprocess(img)
                    imgs[p].append(img)


            wheels[p].extend(yy)
            assert len(imgs[p]) == len(wheels[p])

            cap.release()
Ejemplo n.º 4
0
def get_human_steering(epoch_id):
    epoch_dir = params.data_dir
    assert os.path.isdir(epoch_dir)
    steering_path = epoch_dir + "/dataset%i/data.csv" % epoch_id
    assert os.path.isfile(steering_path)

    rows = cm.fetch_csv_data(steering_path)
    human_steering = [row['angle'] for row in rows]
    return human_steering
Ejemplo n.º 5
0
def get_human_steering(epoch_id):
    epoch_dir = params.data_dir
    assert os.path.isdir(epoch_dir)
    steering_path = epoch_dir + "/dataset%i/data.csv" % epoch_id 
    assert os.path.isfile(steering_path)
    
    rows = cm.fetch_csv_data(steering_path)
    human_steering = [row['angle'] for row in rows]
    return human_steering
def get_human_steering(epoch_id):
    epoch_dir = params.data_dir
    assert os.path.isdir(epoch_dir)
    steering_path = cm.jn(epoch_dir, 'epoch{:0>2}_steering.csv'.format(epoch_id))
    assert os.path.isfile(steering_path)
    
    rows = cm.fetch_csv_data(steering_path)
    human_steering = [row['wheel'] for row in rows]
    return human_steering
Ejemplo n.º 7
0
def load_imgs_v2():
    global imgs
    global wheels

    for epoch_id in epochs['all']:
        print('processing and loading epoch {} into memorys. train:{}, val:{}'.
              format(epoch_id, len(imgs['train']), len(imgs['val'])))

        # vid_path = cm.jn(data_dir, 'epoch{:0>2}_front.mkv'.format(epoch_id))
        vid_path = cm.jn(data_dir, 'out-video-{}.avi'.format(epoch_id))
        print("ppppppppppppppppp : data_dir : ", data_dir)
        print("ppppppppppppppppp : vid_path : ", vid_path)
        if not os.path.isfile(vid_path):
            continue

        frame_count = cm.frame_count(vid_path)
        cap = cv2.VideoCapture(vid_path)

        # csv_path = cm.jn(data_dir, 'epoch{:0>2}_steering.csv'.format(epoch_id))
        csv_path = cm.jn(data_dir, 'out-key-{}.csv'.format(epoch_id))
        assert os.path.isfile(csv_path)

        rows = cm.fetch_csv_data(csv_path)
        print("{}, {}".format(len(rows), frame_count))
        assert frame_count == len(rows)

        for row in rows:
            ret, img = cap.read()
            if not ret:
                break

            img = preprocess.preprocess(img)
            angle = float(row['wheel'])

            if random.random() < params.train_pct:
                imgs['train'].append(img)
                wheels['train'].append([angle])
            else:
                imgs['val'].append(img)
                wheels['val'].append([angle])

        cap.release()

    print('Total data: train:{}, val:{}'.format(len(imgs['train']),
                                                len(imgs['val'])))
def load_batch(purpose):
    global current_batch_id
    xx = []
    yy = []

    # fetch the batch definition
    batch_id = current_batch_id[purpose]
    assert batch_id < len(batches[purpose])
    batch = batches[purpose][batch_id]
    epoch_id, frame_start, frame_end = batch['epoch_id'], batch[
        'frame_start'], batch['frame_end']
    assert epoch_id is not None and frame_start is not None and frame_end is not None

    # update the current batch
    current_batch_id[purpose] = (current_batch_id[purpose] + 1) % len(
        batches[purpose])

    # fetch image and steering data
    vid_path = cm.jn(data_dir, 'epoch{:0>2}_front.mkv'.format(epoch_id))
    assert os.path.isfile(vid_path)
    frame_count = cm.frame_count(vid_path)
    cap = cv2.VideoCapture(vid_path)
    cm.cv2_goto_frame(cap, frame_start)

    csv_path = cm.jn(data_dir, 'epoch{:0>2}_steering.csv'.format(epoch_id))
    assert os.path.isfile(csv_path)
    rows = cm.fetch_csv_data(csv_path)
    assert frame_count == len(rows)
    yy = [[float(row['wheel'])] for row in rows[frame_start:frame_end + 1]]

    for frame_id in xrange(frame_start, frame_end + 1):
        ret, img = cap.read()
        assert ret

        img = preprocess.preprocess(img)

        #cv2.imwrite(os.path.abspath('output/sample_frame.jpg'), img)

        xx.append(img)

    assert len(xx) == len(yy)

    cap.release()

    return xx, yy
Ejemplo n.º 9
0
def load_batch(purpose):
    global current_batch_id
    xx = []
    yy = []

    # fetch the batch definition
    batch_id = current_batch_id[purpose]
    assert batch_id < len(batches[purpose])
    batch = batches[purpose][batch_id]
    epoch_id, frame_start, frame_end = batch['epoch_id'], batch['frame_start'], batch['frame_end']
    assert epoch_id is not None and frame_start is not None and frame_end is not None

    # update the current batch
    current_batch_id[purpose] = (current_batch_id[purpose] + 1) % len(batches[purpose])

    # fetch image and steering data
    vid_path = cm.jn(data_dir, 'epoch{:0>2}_front.mkv'.format(epoch_id))
    assert os.path.isfile(vid_path)
    frame_count = cm.frame_count(vid_path)
    cap = cv2.VideoCapture(vid_path)
    cm.cv2_goto_frame(cap, frame_start)

    csv_path = cm.jn(data_dir, 'epoch{:0>2}_steering.csv'.format(epoch_id))
    assert os.path.isfile(csv_path)
    rows = cm.fetch_csv_data(csv_path)
    assert frame_count == len(rows)
    yy = [[float(row['wheel'])] for row in rows[frame_start:frame_end+1]]

    for frame_id in xrange(frame_start, frame_end+1):
        ret, img = cap.read()
        assert ret

        img = preprocess.preprocess(img)
        
        #cv2.imwrite(os.path.abspath('output/sample_frame.jpg'), img)            

        xx.append(img)

    assert len(xx) == len(yy)

    cap.release()

    return xx, yy
Ejemplo n.º 10
0
def load_imgs():
    global imgs
    global wheels

    for p in purposes:
        for epoch_id in epochs[p]:

            print(
                'processing and loading "{}" epoch {} into memory, current num of imgs is {}...'
                .format(p, epoch_id, len(imgs[p])))

            # vid_path = cm.jn(data_dir, 'epoch{:0>2}_front.mkv'.format(epoch_id))
            data_dir = os.path.abspath('training_images{}'.format(epoch_id))

            assert os.path.isdir(data_dir)

            print("upload images from:", data_dir)

            # csv_path = cm.jn(data_dir, 'epoch{:0>2}_steering.csv'.format(epoch_id))
            csv_path = os.path.abspath('out-key{}.csv'.format(epoch_id))
            assert os.path.isfile(csv_path)

            print("upload ground truth from:", csv_path)
            rows = cm.fetch_csv_data(csv_path)
            print(len(rows), frame_count)
            assert frame_count == len(rows)
            yy = [[float(row['wheel'])] for row in rows]

            for image in data_dir:
                img = cv2.read(image)
                img = preprocess.preprocess(img)
                imgs[p].append(img)

            wheels[p].extend(yy)
            assert len(imgs[p]) == len(wheels[p])

            cap.release()
Ejemplo n.º 11
0
    sys.exit(1)

print("epoch_id: {}, skip_count: {}".format(epoch_id, skip_count))

assert os.path.isfile(vid_path)
assert os.path.isfile(csv_path)

frame_count = cm.frame_count(vid_path)
cap = cv2.VideoCapture(vid_path)
cam_width = int(cap.get(3))
cam_height = int(cap.get(4))
cam_fps = int(cap.get(5))

print("w: {}, h:{}, fps: {}".format(cam_width, cam_height, cam_fps))

rows = cm.fetch_csv_data(csv_path)
assert frame_count == len(rows)

# data files
# fourcc = cv2.cv.CV_FOURCC(*'XVID')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
vidfile = cv2.VideoWriter(conv_vid_path, fourcc, cam_fps,
                          (cam_width, cam_height))
keyfile = open(conv_csv_path, 'w+')
keyfile.write("ts_micro,frame,wheel\n")

# skip video frames
for i in range(skip_count):
    ret, img = cap.read()

# record adjusted data
Ejemplo n.º 12
0
def load_imgs():
    global imgs
    global wheels

    for p in purposes:
        print p
        for epoch_id in epochs[p]:
            print 'processing and loading "{}" epoch {} into memory, current num of imgs is {}...'.format(
                p, epoch_id, len(imgs[p]))

            # csv_path = cm.jn(data_dir, 'epoch{:0>2}_steering.csv'.format(epoch_id))
            csv_path = cm.jn(data_dir, 'data{}/output.txt'.format(epoch_id))
            assert os.path.isfile(csv_path)

            print "DBG:", csv_path
            rows = cm.fetch_csv_data(csv_path)

            # print len(rows)
            #print len(rows), frame_count
            #assert frame_count == len(rows)

            for row in rows:
                # print row
                yy = float(row['wheel'])
                # yy = yy / 22500.

                print yy, "before"
                yy = 1.0 * scale_down(yy, params.input_max,
                                      params.scale) / params.scale
                print yy, "after ==="

                img_path = row['img']
                # print "img"
                # print img_path
                # print yy

                ############ using opencv to read img here
                img_path = cm.jn(data_dir,
                                 'data{}/{}'.format(epoch_id, img_path))
                if not os.path.isfile(img_path):
                    continue
                img = cv2.imread(img_path)

                ########### doing data augmentation

                # move along height of photo
                # for i in range(-2,3,1):
                # for i in range(-1,2,1):
                for i in range(1):
                    i *= 2

                    # move along width of photo
                    # for j in range(-1,2,1):
                    for j in range(1):
                        j *= 2
                        crop = img[40 + i:200 + i, 50 + j:270 + j]

                        # resize to 200*66
                        rsz = cv2.resize(crop, (200, 66))
                        rsz = rsz / 255.
                        imgs[p].append(rsz)
                        wheels[p].append(yy)

                        # flip image and add again
                        flip = np.flip(rsz, 1)
                        imgs[p].append(flip)
                        wheels[p].append(-yy)

                # img = preprocess.preprocess(img)
                # imgs[p].append(img)
                # wheels[p].append(yy)
            # print "wheels"
            # print wheels
            # print imgs[p][0]
            assert len(imgs[p]) == len(wheels[p])