예제 #1
0
파일: data.py 프로젝트: aizmeng/senstextile
def make_dataset_for_sock_calibration_withscale_touch_only(
        args, mask, touch_path, debug=0):

    # load data
    touch_raw, touch_fc, touch_ts = load_data_hdf5(touch_path, 'pressure')

    # do not filter the touch signal on sock as saturated signal is meaningful - body weight
    # only clip the base response
    touch_seq = clip_base_response(touch_raw, base_clip_percentile=5)

    if debug:
        plt.figure()

        idx = np.array([70, 98, 155])
        length = 1000

        plt.subplot(111)
        plt.plot(np.sum(touch_seq[:length], (1, 2)), 'b-')
        plt.plot(idx, np.sum(touch_seq[idx], (1, 2)), 'ro')

        plt.show()

        plt.close()

    # prepare training data according to observation window
    touch_raw_rec = []
    touch_rec = []
    touch_ts_rec = []

    touch_mean = 7.9329
    touch_std = 29.3390

    for i in range(touch_seq.shape[0]):
        touch_st_idx = i - args.obs_window // 2
        touch_ed_idx = i + args.obs_window // 2 + 1
        if touch_st_idx < 0 or touch_ed_idx > touch_seq.shape[0]:
            continue

        touch_raw_cur = touch_raw[i]
        touch_cur = (touch_seq[touch_st_idx:touch_ed_idx] -
                     touch_mean) / touch_std
        touch_ts_cur = touch_ts[i]

        touch_raw_rec.append(touch_raw_cur)
        touch_rec.append(touch_cur)
        touch_ts_rec.append(touch_ts_cur)

    touch_raw_rec = np.stack(touch_raw_rec)
    touch_rec = np.stack(touch_rec)
    touch_ts_rec = np.stack(touch_ts_rec)
    print(
        'touch_raw_rec', touch_raw_rec.shape,
        '%.4f %.4f %.4f %.4f' % (touch_raw_rec.mean(), touch_raw_rec.std(),
                                 touch_raw_rec.min(), touch_raw_rec.max()))
    print(
        'touch_rec', touch_rec.shape, '%.4f %.4f %.4f %.4f' %
        (touch_rec.mean(), touch_rec.std(), touch_rec.min(), touch_rec.max()))
    print()

    return touch_raw_rec, touch_rec, touch_ts_rec
예제 #2
0
def make_dataset_for_kuka_calibration_withglove(args,
                                                phase,
                                                data_path_prefix,
                                                mask_glove,
                                                mask_kuka,
                                                debug=0,
                                                max_length=-1):

    print("Loading data from %s ..." % data_path_prefix)

    # load data
    touch_glove_path = os.path.join(data_path_prefix, 'touch_1.hdf5')
    touch_kuka_path = os.path.join(data_path_prefix, 'touch_0.hdf5')

    touch_glove_raw, touch_glove_fc, touch_glove_ts = load_data_hdf5(
        touch_glove_path, 'pressure', max_length=max_length)
    touch_kuka_raw, touch_kuka_fc, touch_kuka_ts = load_data_hdf5(
        touch_kuka_path, 'pressure')

    # filter artifact in touch_glove
    touch_glove = filter_artifact_in_touch(touch_glove_raw,
                                           mask_glove,
                                           thresh=1000.,
                                           t_win=5,
                                           s_neighbor=1)

    # clip base response for touch_glove
    touch_glove_seq = clip_base_response(touch_glove, base_clip_percentile=50)

    # filter artifact in touch_kuka
    '''
    touch_kuka = filter_artifact_in_touch(
        touch_kuka_raw, mask_kuka, thresh=1000., t_win=5, s_neighbor=1)
    '''

    # clip base response in touch_kuka
    touch_kuka_seq = clip_base_response(touch_kuka_raw,
                                        base_clip_percentile=50)

    # synchronize touch_glove and touch_kuka
    touch_glove_idx_per_round, touch_kuka_idx_per_round = synchronize_touch_and_touch(
        touch_glove_seq,
        touch_kuka_seq,
        touch_glove_ts,
        touch_kuka_ts,
        offset=-1)

    if debug:
        plt.figure()

        idx = np.array([140, 162, 280, 375])
        length = 400

        plt.subplot(411)
        plt.plot(
            np.sum(touch_glove_raw[touch_glove_idx_per_round[:length]],
                   (1, 2)), 'r-')
        plt.plot(
            idx, np.sum(touch_glove_raw[touch_glove_idx_per_round[idx]],
                        (1, 2)), 'ro')

        plt.subplot(412)
        plt.plot(
            np.sum(touch_glove_seq[touch_glove_idx_per_round[:length]],
                   (1, 2)), 'b-')
        plt.plot(
            idx, np.sum(touch_glove_seq[touch_glove_idx_per_round[idx]],
                        (1, 2)), 'ro')

        plt.subplot(413)
        plt.plot(
            np.sum(touch_kuka_raw[touch_kuka_idx_per_round[:length]], (1, 2)),
            'r-')
        plt.plot(idx,
                 np.sum(touch_kuka_raw[touch_kuka_idx_per_round[idx]], (1, 2)),
                 'ro')

        plt.subplot(414)
        plt.plot(
            np.sum(touch_kuka_seq[touch_kuka_idx_per_round[:length]], (1, 2)),
            'b-')
        plt.plot(idx,
                 np.sum(touch_kuka_seq[touch_kuka_idx_per_round[idx]], (1, 2)),
                 'ro')

        plt.show()

        plt.close()

    # prepare training data according to observation window
    touch_glove_raw_rec = []
    touch_glove_rec = []
    touch_kuka_raw_rec = []
    touch_kuka_rec = []

    touch_glove_mean = 2.3655
    touch_glove_std = 14.1341

    touch_kuka_mean = 4.4101
    touch_kuka_std = 21.4518

    if phase == 'train':
        st_idx, ed_idx = 65, int(
            len(touch_glove_idx_per_round) * args.train_valid_ratio)
    else:
        st_idx = int(len(touch_glove_idx_per_round) * args.train_valid_ratio)
        ed_idx = len(touch_glove_idx_per_round)

    for i in range(st_idx, ed_idx):
        touch_glove_st_idx = touch_glove_idx_per_round[i] - args.obs_window // 2
        touch_glove_ed_idx = touch_glove_idx_per_round[
            i] + args.obs_window // 2 + 1
        if touch_glove_st_idx < 0 or touch_glove_ed_idx > touch_glove_raw.shape[
                0]:
            continue

        touch_kuka_st_idx = touch_kuka_idx_per_round[i] - args.obs_window // 2
        touch_kuka_ed_idx = touch_kuka_idx_per_round[
            i] + args.obs_window // 2 + 1
        if touch_kuka_st_idx < 0 or touch_kuka_ed_idx > touch_kuka_raw.shape[0]:
            continue

        touch_glove_raw_cur = touch_glove_raw[touch_glove_idx_per_round[i]]
        touch_kuka_raw_cur = touch_kuka_raw[touch_kuka_idx_per_round[i]]
        touch_glove_cur = (
            touch_glove_seq[touch_glove_st_idx:touch_glove_ed_idx] -
            touch_glove_mean) / touch_glove_std
        touch_kuka_cur = (touch_kuka_seq[touch_kuka_st_idx:touch_kuka_ed_idx] -
                          touch_kuka_mean) / touch_kuka_std

        touch_glove_raw_rec.append(touch_glove_raw_cur)
        touch_kuka_raw_rec.append(touch_kuka_raw_cur)
        touch_glove_rec.append(touch_glove_cur)
        touch_kuka_rec.append(touch_kuka_cur)

    touch_glove_raw_rec = np.stack(touch_glove_raw_rec)
    touch_glove_rec = np.stack(touch_glove_rec)
    touch_kuka_raw_rec = np.stack(touch_kuka_raw_rec)
    touch_kuka_rec = np.stack(touch_kuka_rec)

    return touch_glove_raw_rec, touch_glove_rec, touch_kuka_raw_rec, touch_kuka_rec
예제 #3
0
def make_dataset_for_kuka_calibration_withglove_touch_only(
        args, mask, touch_path, debug=0):

    # load data
    touch_raw, touch_fc, touch_ts = load_data_hdf5(touch_path, 'pressure')

    # filter artifact in touch
    '''
    touch = filter_artifact_in_touch(touch_raw, mask, thresh=1000., t_win=5, s_neighbor=1)
    '''

    # clip base response
    touch_seq = clip_base_response(touch_raw, base_clip_percentile=50)

    if debug:
        plt.figure()

        idx = np.array([70, 98, 155])
        length = 1000

        plt.subplot(111)
        plt.plot(np.sum(touch_seq[:length], (1, 2)), 'b-')
        plt.plot(idx, np.sum(touch_seq[idx], (1, 2)), 'ro')

        plt.show()

        plt.close()

    # prepare training data according to observation window
    touch_raw_rec = []
    touch_rec = []
    touch_ts_rec = []

    touch_mean = 4.4101
    touch_std = 21.4518

    for i in range(touch_seq.shape[0]):
        touch_st_idx = i - args.obs_window // 2
        touch_ed_idx = i + args.obs_window // 2 + 1
        if touch_st_idx < 0 or touch_ed_idx > touch_seq.shape[0]:
            continue

        touch_raw_cur = touch_raw[i]
        touch_cur = (touch_seq[touch_st_idx:touch_ed_idx] -
                     touch_mean) / touch_std
        touch_ts_cur = touch_ts[i]

        touch_raw_rec.append(touch_raw_cur)
        touch_rec.append(touch_cur)
        touch_ts_rec.append(touch_ts_cur)

    touch_raw_rec = np.stack(touch_raw_rec)
    touch_rec = np.stack(touch_rec)
    touch_ts_rec = np.stack(touch_ts_rec)
    print(
        'touch_raw_rec', touch_raw_rec.shape,
        '%.4f %.4f %.4f %.4f' % (touch_raw_rec.mean(), touch_raw_rec.std(),
                                 touch_raw_rec.min(), touch_raw_rec.max()))
    print(
        'touch_rec', touch_rec.shape, '%.4f %.4f %.4f %.4f' %
        (touch_rec.mean(), touch_rec.std(), touch_rec.min(), touch_rec.max()))
    print()

    return touch_raw_rec, touch_rec, touch_ts_rec
예제 #4
0
def make_dataset_for_glove_calibration_withscale(args,
                                                 phase,
                                                 data_path_prefix,
                                                 mask,
                                                 debug=0):
    print("Loading data from %s ..." % data_path_prefix)

    # load data
    scale_path = os.path.join(data_path_prefix, 'None.hdf5')
    touch_path = os.path.join(data_path_prefix, 'touch.hdf5')

    touch_raw, touch_fc, touch_ts = load_data_hdf5(touch_path, 'pressure')
    scale_raw, scale_fc, scale_ts = load_data_hdf5(scale_path, 'scale')

    # filter artifact in touch
    touch_seq = filter_artifact_in_touch(touch_raw,
                                         mask,
                                         thresh=1000,
                                         t_win=5,
                                         s_neighbor=1)
    touch_seq = clip_base_response(touch_seq, base_clip_percentile=50)

    # filter artifact in scale
    scale_seq = filter_artifact_in_scale(scale_raw, thresh=1e6)

    # synchronize touch and scale
    touch_idx_per_round, scale_per_round = synchronize_touch_and_scale(
        touch_seq, scale_seq, touch_ts, scale_ts, offset=2)

    scale_per_round -= np.mean(
        scale_per_round[:20])  # zero out the base weight

    if debug:
        plt.figure()

        length = 2000
        idx = np.array([210, 478, 646])

        plt.subplot(311)
        plt.plot(np.sum(touch_raw[touch_idx_per_round[:length]], (1, 2)), 'r-')
        plt.plot(idx, np.sum(touch_raw[touch_idx_per_round[idx]], (1, 2)),
                 'ro')

        plt.subplot(312)
        plt.plot(np.sum(touch_seq[touch_idx_per_round[:length]], (1, 2)), 'b-')
        plt.plot(idx, np.sum(touch_seq[touch_idx_per_round[idx]], (1, 2)),
                 'ro')

        plt.subplot(313)
        plt.plot(scale_per_round[:length], 'g-')
        plt.plot(idx, scale_per_round[idx], 'ro')

        plt.show()

        plt.close()

    # prepare training data according to observation window
    touch_raw_rec = []
    touch_rec = []
    scale_rec = []

    touch_mean = 2.3655
    touch_std = 14.1341
    scale_mean = 483543.7930
    scale_std = 413473.6322
    scale_min = -1.2061
    '''
    touch_mean = 0.
    touch_std = 1.
    scale_mean = 0.
    scale_std = 1.
    scale_min = 0.
    '''

    if phase == 'train':
        st_idx, ed_idx = 65, int(len(scale_per_round) * args.train_valid_ratio)
    elif phase == 'valid':
        st_idx, ed_idx = int(len(scale_per_round) *
                             args.train_valid_ratio), len(scale_per_round)
    elif phase == 'full':
        st_idx, ed_idx = 0, len(scale_per_round)

    for i in range(st_idx, ed_idx):
        touch_st_idx = touch_idx_per_round[i] - args.obs_window // 2
        touch_ed_idx = touch_idx_per_round[i] + args.obs_window // 2 + 1
        if touch_st_idx < 0 or touch_ed_idx > touch_raw.shape[0]:
            continue

        touch_raw_cur = touch_raw[touch_idx_per_round[i]]
        touch_cur = (touch_seq[touch_st_idx:touch_ed_idx] -
                     touch_mean) / touch_std
        scale_cur = (scale_per_round[i] - scale_mean) / scale_std
        scale_cur = scale_cur - scale_min
        # scale_cur = (scale_per_round[i + args.obs_window // 2] - scale_min) / (scale_max - scale_min)

        touch_raw_rec.append(touch_raw_cur)
        touch_rec.append(touch_cur)
        scale_rec.append(scale_cur)

    touch_raw_rec = np.stack(touch_raw_rec)
    touch_rec = np.stack(touch_rec)
    scale_rec = np.stack(scale_rec)

    return touch_raw_rec, touch_rec, scale_rec
예제 #5
0
파일: data.py 프로젝트: aizmeng/senstextile
def make_dataset_for_sock_calibration_withscale(args,
                                                phase,
                                                data_path_prefix,
                                                mask,
                                                debug=0):
    print("Loading data from %s ..." % data_path_prefix)

    # load data
    scale_path = os.path.join(data_path_prefix, 'None.hdf5')
    touch_path = os.path.join(data_path_prefix, 'touch1.hdf5')

    touch_raw, touch_fc, touch_ts = load_data_hdf5(touch_path, 'pressure')
    scale_raw, scale_fc, scale_ts = load_data_hdf5(scale_path, 'scale')

    # do not filter the touch signal on sock as saturated signal is meaningful - body weight
    # only clip the base response
    touch_seq = clip_base_response(touch_raw, base_clip_percentile=5)

    # filter artifact in scale
    scale_seq = filter_artifact_in_scale(scale_raw, thresh=2.5e5)

    # synchronize touch and scale
    offset = -1
    touch_idx_per_round, scale_per_round = synchronize_touch_and_scale(
        touch_seq, scale_seq, touch_ts, scale_ts, offset=offset)

    if debug:
        plt.figure()

        idx = np.array([794, 1376, 2483, 2710])
        length = 3000

        plt.subplot(311)
        plt.plot(np.sum(touch_raw[touch_idx_per_round[:length]], (1, 2)), 'r-')
        plt.plot(idx, np.sum(touch_raw[touch_idx_per_round[idx]], (1, 2)),
                 'ro')

        plt.subplot(312)
        plt.plot(np.sum(touch_seq[touch_idx_per_round[:length]], (1, 2)), 'b-')
        plt.plot(idx, np.sum(touch_seq[touch_idx_per_round[idx]], (1, 2)),
                 'ro')

        plt.subplot(313)
        plt.plot(scale_per_round[:length], 'g-')
        plt.plot(idx, scale_per_round[idx], 'ro')

        plt.show()

        plt.close()

    # prepare training data according to observation window
    touch_raw_rec = []
    touch_rec = []
    scale_rec = []

    touch_mean = 7.9329
    touch_std = 29.3390
    scale_mean = 593005.2296
    scale_std = 286031.0056
    scale_min = -0.9579

    if phase == 'train':
        st_idx, ed_idx = 65, int(len(scale_per_round) * args.train_valid_ratio)
    elif phase == 'valid':
        st_idx, ed_idx = int(len(scale_per_round) *
                             args.train_valid_ratio), len(scale_per_round)
    elif phase == 'full':
        st_idx, ed_idx = 0, len(scale_per_round)

    for i in range(st_idx, ed_idx):
        touch_st_idx = touch_idx_per_round[i] - args.obs_window // 2
        touch_ed_idx = touch_idx_per_round[i] + args.obs_window // 2 + 1
        if touch_st_idx < 0 or touch_ed_idx > touch_raw.shape[0]:
            continue

        touch_raw_cur = touch_raw[touch_idx_per_round[i]]
        touch_cur = (touch_seq[touch_st_idx:touch_ed_idx] -
                     touch_mean) / touch_std
        scale_cur = (scale_per_round[i] - scale_mean) / scale_std
        scale_cur = scale_cur - scale_min
        # scale_cur = (scale_per_round[i + args.obs_window // 2] - scale_min) / (scale_max - scale_min)

        touch_raw_rec.append(touch_raw_cur)
        touch_rec.append(touch_cur)
        scale_rec.append(scale_cur)

    touch_raw_rec = np.stack(touch_raw_rec)
    touch_rec = np.stack(touch_rec)
    scale_rec = np.stack(scale_rec)

    return touch_raw_rec, touch_rec, scale_rec