Example #1
0
assert len(idp_data_dir) == len(num_repeats) == len(
    sample_classes)  # check the consistency of zip variables
assert set(classes) == set([
    item for sublist in sample_classes for item in sublist
])  # check categorical consistency
########################################################################################################################

interval_duration = 4.0  # how long does one writing take
period = 33.45  # ms

# classes = set([item for sublist in sample_classes for item in sublist])  # reduce to categorical classes
ls_dicts = \
    [idp_preprocess_legacy(dr, interval_duration, classes=cs, num_repeat=nr, period=period)
     for dr, nr, cs in zip(idp_data_dir, num_repeats, sample_classes)]
points_per_sample = int(resolve_points_per_sample(period, interval_duration))
'''
This implementation accepts two branches of input: range doppler and range azimuth. Each are put
through feature extractors on their branch respectively.
The flattened output from the two branch meets and are concatenated together then put in LSTM, 
the network is concluded by FC layers. 
'''

# creates the Time Distributed CNN for range Doppler heatmap ##########################
model = make_model_individual(classes,
                              points_per_sample,
                              channel_mode='channels_first')
# create input features
Y = []
X_mmw_rD = []
X_mmw_rA = []
# idp_complete_classes = ['A', 'B', 'C', 'D', 'E',
#                         'F', 'G', 'H', 'I', 'J',
#                         'K', 'L', 'M', 'N', 'O',
#                         'P', 'Q', 'R', 'S', 'T',
#                         'U', 'V', 'W', 'X', 'Y',
#                         'Z', 'Spc', 'Bspc', 'Ent', 'Act']

idp_complete_classes = ['A', 'B', 'C', 'D', 'E']

# idp_complete_classes = ['A', 'B', 'C', 'D', 'E']

sensor_feature_dict = {'mmw': ('range_doppler', 'range_azi')}
sensor_period_dict = {'mmw': 33.45}
input_interval = 4.0
sensor_sample_points_dict = dict([
    (key, (resolve_points_per_sample(value, input_interval)))
    for key, value in sensor_period_dict.items()
])

encoder = OneHotEncoder(categories='auto')
encoder.fit(np.reshape(idp_complete_classes, (-1, 1)))
X_dict, Y = load_idp('D:\PcProjects\mGesf\data\data_ev1',
                     sensor_feature_dict=sensor_feature_dict,
                     complete_class=idp_complete_classes,
                     encoder=encoder,
                     sensor_sample_points_dict=sensor_sample_points_dict)

#####################################################################################
X_mmw_rD = X_dict['range_doppler']
X_mmw_rA = X_dict['range_azi']
experiment_root = 'E:/data/mGesf/091020/'
scenario = 'Watch'
subjects = ['ag', 'hw']
test_cases = ['A-Act', 'Nois_Act_HelloWorld_Act_Nois', 'Pangram']
reload_data = False

data_suffix = '_data.mgesf'
label_suffix = '_label.mgesf'

sensor_feature_dict = {'mmw': ('range_doppler', 'range_azi')}
sensor_period_dict = {'mmw': 33.45}  # period in milliseconds
input_interval = 4.0
encoder = OneHotEncoder(categories='auto')
encoder.fit(np.reshape(idp_complete_classes, (-1, 1)))
sensor_sample_points_dict = dict(
    [(key, (resolve_points_per_sample(value, input_interval))) for key, value in sensor_period_dict.items()])
print('loading original data for normalization')
rD_max, rD_min = pickle.load(open('D:/PcProjects/mGesf/data/rD_max.p', 'rb')), pickle.load(
    open('D:/PcProjects/mGesf/data/rD_min.p', 'rb'))
rA_max, rA_min = pickle.load(open('D:/PcProjects/mGesf/data/rA_max.p', 'rb')), pickle.load(
    open('D:/PcProjects/mGesf/data/rA_min.p', 'rb'))

print('loading model')
model_dir = os.path.join(experiment_root, '0' + scenario, 'model')
model = load_model(os.path.join(model_dir, 'model.h5'))
data_dir = os.path.join(experiment_root, '0' + scenario)
if reload_data:
    X_mmw_rD, X_mmw_rA, Y = load_idp_new_and_legacy(data_dir,
                                                    sensor_feature_dict=sensor_feature_dict,
                                                    complete_class=idp_complete_classes, encoder=encoder,
                                                    sensor_sample_points_dict=sensor_sample_points_dict
#                         'K', 'L', 'M', 'N', 'O',
#                         'P', 'Q', 'R', 'S', 'T',
#                         'U', 'V', 'W', 'X', 'Y',
#                         'Z', 'Spc', 'Bspc', 'Ent', 'Act']

idp_complete_classes = ['A', 'B', 'C', 'D', 'E']
# idp_complete_classes = ['A', 'B', 'C', 'D', 'E']

sensor_feature_dict = {
    'mmw': ('range_doppler', 'range_azi'),
    'xethrux4': ('clutter_removal_baseband_frame', )
}
period = 33.45
input_interval = 4.0

points_per_sample = round(resolve_points_per_sample(period, input_interval))
encoder = OneHotEncoder(categories='auto')
encoder.fit(np.reshape(idp_complete_classes, (-1, 1)))
X_dict, Y = load_idp('D:\PcProjects\mGesf\data\data_ev1',
                     sensor_feature_dict=sensor_feature_dict,
                     complete_class=idp_complete_classes,
                     encoder=encoder)

#####################################################################################
X_mmw_rD = X_dict['range_doppler']
X_mmw_rA = X_dict['range_azi']

X_mmw_rD_train, X_mmw_rD_test, Y_train, Y_test = train_test_split(
    X_mmw_rD, Y, test_size=0.20, random_state=3, shuffle=True)
X_mmw_rA_train, X_mmw_rA_test, Y_train, Y_test = train_test_split(
    X_mmw_rA, Y, test_size=0.20, random_state=3, shuffle=True)