I have this function in case to load IMU data : def loaddatafromdirectories(directory):…
- User
I have this function in case to load IMU data : def load_data_from_directories(directory):
data_type_folders = ['IMU_Data'] # , 'Vicon_Data', 'EMG_Data' all_data = {} for i in range(5, 6): # (1, N) for all participants for data_type_folder in data_type_folders: participant_directory = os.path.join(directory, f'Participant{i:03d}', 'Raw', data_type_folder) if os.path.exists(participant_directory): for root, dirs, files in os.walk(participant_directory): for file in files: parts = file.split('_') # Extracting participant_prefix, activity_name, data_type, and trial_number participant_prefix = parts[0] activity_name = parts[1] data_type = parts[2] trial_number = "_".join(parts[3:]) original_filename = f'{os.path.splitext(file)[0]}.csv' key = (activity_name, data_type_folder) with open(os.path.join(root, file), 'r') as f: file_contents = f.read() if key not in all_data: all_data[key] = [] all_data[key].append(file_contents) return all_data - Assistant
- User
and this for EMG data: def load_data_from_directories(directory):
data_type_folders = ['EMG_Data'] # , 'Vicon_Data', 'EMG_Data' all_data = {} for i in range(2, 4): # (1, 8) for all participants for data_type_folder in data_type_folders: participant_directory = os.path.join(directory, f'Participant{i:03d}', 'Raw', data_type_folder) if os.path.exists(participant_directory): for root, dirs, files in os.walk(participant_directory): for file in files: parts = file.split('_') # Extracting participant_prefix, activity_name, data_type, and trial_number participant_prefix = parts[0] activity_name = parts[1] data_type = parts[2] trial_number = "_".join(parts[3:]) original_filename = f'{os.path.splitext(file)[0]}.csv' key = (activity_name, data_type_folder) with open(os.path.join(root, file), 'r') as f: file_contents = f.read() if key not in all_data: all_data[key] = [] all_data[key].append(file_contents) return all_data - Assistant
- User
However, now i need to load both in order to have a fusion data to train a model
- Assistant
- User
- Assistant
- User
multi_data_directory = '/kaggle/input/multimodaldataset-har/Participants'
loaded_data_IMU_Data = load_data_from_directories_IMU_Data(multi_data_directory) loaded_data_EMG_Data = load_data_from_directories_EMG_Data(multi_data_directory) data_type_folder_IMU_Data = "IMU_Data" data_type_folder_EMG_Data = "EMG_Data" separated_sensor_data_IMU_Data = separate_data_by_type(loaded_data_IMU_Data, data_type_folder_IMU_Data) separated_sensor_data_EMG_Data = separate_data_by_type(loaded_data_EMG_Data, data_type_folder_EMG_Data) combined_data = load_combined_data(separated_sensor_data_IMU_Data, separated_sensor_data_EMG_Data) train_model_with_sensor_data(combined_data) - Assistant
- User
is this correct: # This should already be combined following the earlier guideline def load_combined_data(imu_data, emg_data): combined_data = {} for key in imu_data: if key in emg_data: # Ensure you find matching data combined_data[key] = { 'IMU_Data': imu_data[key], 'EMG_Data': emg_data[key] } return combined_data
- Assistant
- User
print frist imu data
- Assistant
To print the first entry of your IMU data after loading it, you'll first need to access the relevant data structure returned by your function (assuming you've already implemented the loading function correctly).
Assuming You Have Loaded the Data
Here’s how you might implement the printing of the first IMU data entry:
- User
improve the merge
- Assistant
- User
Warning: Missing EMG data for key: ('Walking', 'IMU_Data') Warning: Missing IMU data for key: ('Fetch', 'EMG_Data') Warning: Missing IMU data for key: ('KitchenMakingTea', 'EMG_Data') Warning: Missing IMU data for key: ('OpenSpaceWaterCollection', 'EMG_Data') Warning: Missing IMU data for key: ('Walking', 'EMG_Data') Warning: Missing EMG data for key: ('KitchenWaterCollection', 'IMU_Data')
- Assistant
- User
how the data combined
- Assistant
- User
is the best way to fuse data for model training
- Assistant
- User
give the fusion function
- Assistant
- User
in the prevouis example
- Assistant
- User
but need to use the prevouis functions of loading
- Assistant
- User
which type of fusion this
- Assistant
- User
give an example of data how it looks
- Assistant
- User
fuse_sensor_data keep the data similar no need to extract labels
- Assistant
- User
why if len(imu_sample) == len(emg_sample): # Simple check that samples can be concatenated
- Assistant
- User
give the complete code
- Assistant
- User
to check in the fuse function by printing soe data fro; imu and emg
- Assistant
- User
print just first samples
- Assistant
- User
Correct this :def fuse_sensor_data(imu_data, emg_data):
combined_data = {} # Get all unique activity names from both datasets all_activities = set(imu_data.keys()).union(set(emg_data.keys())) print(len(all_activities)) for activity in all_activities: imu_features = imu_data.get(activity, []) # Get IMU features or an empty list emg_features = emg_data.get(activity, []) # Get EMG features or an empty list #print(len(imu_features)) # Combine features for the activity combined_activity_features = [] # Print only the first samples print(f"First IMU Sample for {activity}: {imu_features[0]}") '''if emg_features: print(f"First EMG Sample for {activity}: {emg_features[0]}") else: print(f"No EMG samples for {activity}.")''' for imu_sample in imu_features: for emg_sample in emg_features: # Assuming we want to concatenate the features, we'll handle alignment based on the index. if len(imu_sample) == len(emg_sample): # Simple check that samples can be concatenated combined_sample = imu_sample + emg_sample # Concatenating the feature vectors combined_activity_features.append(combined_sample) # Store combined data combined_data[(activity[0], 'Combined_Data')] = combined_activity_features return combined_data - Assistant