Ejemplo n.º 1
0
def get_actual_odom(image1_path,image2_path):
    '''Get actual relative odometry.'''
    image1_seq_id, image1_frame=parse_path(image1_path)
    image2_seq_id, image2_frame=parse_path(image2_path)
    
    image1_odom=read_odom(sequence_id=image1_seq_id,desired_frame=image1_frame)
    image2_odom=read_odom(sequence_id=image2_seq_id,desired_frame=image2_frame)
    
    odom_dt_actual=image1_odom-image2_odom

    return odom_dt_actual
Ejemplo n.º 2
0
def _valBatchGenerator(X_val_filelist, y_val_filelist, batchSize):
    """
    Yield X and Y data when the batch is filled.
    """
    #Sort filelists to confirm they are same order
    X_val_filelist.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))
    y_val_filelist.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))

    #Do not shuffle!

    while True:
        idx = 1  #Skip first image since we need t-1

        while idx + (batchSize - 1) < len(X_val_filelist):
            X_val_1 = np.zeros((batchSize, 192, 640, 3),
                               dtype=np.uint8)  #time=t
            X_val_2 = np.zeros((batchSize, 192, 640, 3),
                               dtype=np.uint8)  #time=t-1
            # y_val_depth=np.zeros((batchSize,192,640),dtype=np.uint8)   #time=t depth
            y_val_odom = np.zeros((batchSize, 6), dtype=np.float64)  #dt odom
            y_val_rpy = np.zeros((batchSize, 3), dtype=np.float64)
            y_val_xyz = np.zeros((batchSize, 3), dtype=np.float64)
            y_val_rpyxyz = np.zeros((batchSize, 6), dtype=np.float64)

            for i in range(batchSize):
                #Load images
                X_val_1[i] = rgb_read(X_val_filelist[idx + i])  #time=t
                X_val_2[i] = rgb_read(X_val_filelist[idx - 1 + i])  #time=t-1
                # y_val_depth[i]=depth_read(y_val_filelist[idx+i])   #time=t

                #Calculate change in odometry
                current_filename = X_val_filelist[idx + i]  #time=t
                prev_filename = X_val_filelist[idx - 1 + i]  #time=t-1

                sequence_id, frame_id = basename(current_filename).split(
                    '_sync_')
                prev_sequence_id, prev_frame_id = basename(
                    prev_filename).split('_sync_')

                #print('original:' + frame_id)
                frame_id = int(frame_id.split('.')[0])
                prev_frame_id = int(prev_frame_id.split('.')[0])

                #print('converted:' + str(frame_id))
                #prev_frame_id=frame_id-1

                current_odom = read_odom(sequence_id, frame_id)
                prev_odom = read_odom(prev_sequence_id, prev_frame_id)
                #print('Val: '+f'{frame_id}, {prev_frame_id}')

                y_val_odom[i] = normalize(current_odom - prev_odom)
                # y_val_odom[i]=current_odom-prev_odom
                y_val_rpy[i] = y_val_odom[i][0:3]
                y_val_xyz[i] = y_val_odom[i][3:6]
                y_val_rpyxyz[i] = y_val_odom[i]

            #Reshape [samples][width][height][pixels]
            X_val_1 = X_val_1.reshape(X_val_1.shape[0], X_val_1.shape[1],
                                      X_val_1.shape[2],
                                      X_val_1.shape[3]).astype(np.uint8)
            X_val_2 = X_val_2.reshape(X_val_2.shape[0], X_val_2.shape[1],
                                      X_val_2.shape[2],
                                      X_val_2.shape[3]).astype(np.uint8)

            # y_val_depth = y_val_depth.reshape((y_val_depth.shape[0],1,-1)).astype(np.uint8)
            # y_val_depth = y_val_depth.squeeze()

            # normalize inputs and outputs from 0-255 to 0-1
            X_val_1 = np.divide(X_val_1, 255).astype(np.float16)
            X_val_2 = np.divide(X_val_2, 255).astype(np.float16)
            # y_val_depth=np.divide(y_val_depth,255).astype(np.float16)

            # if (idx % 68)==0: #1024
            # print(str(idx)+'/'+str(len(X_val_filelist)))

            idx += batchSize

            #y_val_depth=y_val_depth.reshape((batchSize,len(y_val_depth)))
            # y_val_depth=y_val_depth.reshape((batchSize,y_val_depth[0].size))

            #Provide both images [time=t, time(t-1)]
            X_val = [X_val_1, X_val_2]

            #Provide depth and odom
            y_val = [y_val_rpy, y_val_xyz]
            # y_val=[y_val_rpyxyz]

            # print('Val:', y_val)
            #print('Val: '+str(y_val_depth.shape)+','+str(y_val_odom.shape))

            yield X_val, y_val
if __name__ == '__main__':
    model = models.mock_undeepvo_withflow
    model_name = 'mock_undeepvo_withflow'
    model = main(model_name=model_name,
                 model=model,
                 num_epochs=80,
                 batch_size=32)
    show_test_image = True

    if show_test_image:
        #"data\train\X\2011_09_30_drive_0016_sync_0000000006.png"
        #"data\val\X\2011_09_30_drive_0018_sync_0000000135.png"
        image1_path = r"data\val\X\2011_09_30_drive_0018_sync_0000000135.png"
        image2_path = r"data\val\X\2011_09_30_drive_0018_sync_0000000134.png"
        flow_path = r"data\val\flow\2011_09_30_drive_0018_sync_0000000135_flow.png"
        image1_odom = read_odom(sequence_id="2011_09_30_drive_0018",
                                desired_frame=135)
        image2_odom = read_odom(sequence_id="2011_09_30_drive_0018",
                                desired_frame=134)

        #Read test image
        image1 = rgb_read(image1_path)  #640x480, 1242x375
        image1 = image1.reshape(1, 192, 640, 3)
        image1 = np.divide(image1, 255).astype(np.float16)

        #Read test image
        image2 = rgb_read(image2_path)  #640x480
        image2 = image2.reshape(1, 192, 640, 3)
        image2 = np.divide(image2, 255).astype(np.float16)

        #Read test image
        flow = rgb_read(flow_path)  #640x480