DLC2Kinematics icon indicating copy to clipboard operation
DLC2Kinematics copied to clipboard

Number of frames different for DLC2 and DLC

Open sp17bs opened this issue 1 year ago • 3 comments

Hello,

I have my DLC coordinates saved in a .csv file. I have then ran the compute joint angles function on DLC2Kinematics.

When I have gone to add them to the same worksheet I have noticed a few instances where the number of frames analysed in the DLC file is different for the same file analysed by DLC2Kinematics, only by a small number of frames. The DLC2 will have less than the DLC.

I have checked that I have loaded the correct csv file in. I don't seem to have any missing values either.

I am therefore wondering, if DLC2kinematics is only analysing the coordinates when the likelihood is over a certain threshold? Or whether there would likely be any other explantaion?

Thank you,

Ben

sp17bs avatar Sep 23 '24 09:09 sp17bs

Hi Ben, can you be more specific about what function you are using, and I assume you mean H5, correct? We don't recommend using the CSV files

MMathisLab avatar Sep 23 '24 10:09 MMathisLab

Hello,

Thank you for your quick response.

Yes, sorry I meant the .h5 file.

I have done all of the training, plotted the coordinates and created the videos. I then take the saved .h5 file for each animal and using DLC2Kinematics I create the joint dictionary and then compute the joint angles. This works well.

However, when I go to combine the DLC data with the Angle data from DLC2Kinematics, there have been instances where the number of frames analysed is not the same. For example, one particular animal the video has 495 frames. The angle data only has 470 data points. However, the angle data is continuous, and isn't missing when there are instances of lower likelihood.

I was therefore wondering if there was an explanation for this?

The compute angles code is:

FileType = ".h5" rat = 53 File = f'/content/drive/My Drive/Exp2-2DKinematics3-Ben-2024-09-09/videos/Rat{rat}-35-1-IPDLC_resnet50_Exp2-2DKinematics3Sep9shuffle1_600000'

df, bodyparts, scorer = dlc2kinematics.load_data(f'/content/drive/My Drive/Exp2-2DKinematics3-Ben-2024-09-09/videos/Rat{rat}-35-1-IPDLC_resnet50_Exp2-2DKinematics3Sep9shuffle1_600000.h5')

print(bodyparts) # Display the list of body parts print(scorer) # Display the scorer information print(df.shape) print(type(df))

df[1:]

joints_dict={}

joints_dict['Hip'] = ['IliacCrest', 'Hip','Knee'] joints_dict['Knee'] = ['Hip', 'Knee','Ankle'] joints_dict['Ankle'] = ['Knee', 'Ankle','MTP'] joints_dict['MTP'] = ['Ankle', 'MTP','Toe']

print(joints_dict)

Compute joint angles:

joint_angles = dlc2kinematics.compute_joint_angles(df, joints_dict, dropnan=True, smooth=True, save=False) #do I want smoothing?

Plot the joint angles:

dlc2kinematics.plot_joint_angles(joint_angles)

Save the joint angles to a CSV file:

joint_angles.to_csv(f'/content/drive/My Drive/Exp2-2DKinematics3-Ben-2024-09-09/videos/Rat{rat}JointAngles.csv', index=False)

Many thanks,

Ben

sp17bs avatar Sep 23 '24 10:09 sp17bs

I have added two images of the excel sheet which may be more clear to see the issue:

DLC DLC2 Excel Top rows DLC DLC2 Excel Bottom rows

sp17bs avatar Sep 23 '24 10:09 sp17bs

Hi, I think I’ve figured it out.

The missing values were due to dropnan=True.

To retain 'null' values (e.g., when angles can't be computed due to low likelihoods from blocked joint views), it's essential to set dropnan=False.

Keeping it as True can make it hard to accurately time-align the DLC and DLC2kinematic data in a combined sheet.

sp17bs avatar Nov 07 '24 14:11 sp17bs