perfanalytics / pose2sim

Markerless kinematics with any cameras — From 2D Pose estimation to 3D OpenSim motion
https://perfanalytics.github.io/pose2sim/
BSD 3-Clause "New" or "Revised" License
244 stars 46 forks source link

Structure of a "Session" #112

Closed ANaaim closed 1 month ago

ANaaim commented 3 months ago

Some thought about what should be a Session after the discussion we had in the seminar :

Session_mesure (Generally a subject) │ ├──calibration │ ├── Config.toml │ ├── Calib_qualisys.toml (if calibration with qualysis) │ └── Calib_board.toml (if calibration with video) │ │ │
├── Acqusition_001 │ ├── heatmaps │ ├── pose │ ├── pose-3d │ └── videos │ ├── Acqusition_002 │ ├── heatmaps │ ├── pose │ ├── pose-3d │ └── videos
├──.....
  ├── Acqusition_XXX
  │    ├── heatmaps
  │    ├── pose
  │    ├── pose-3d
  │    └── videos
  │
  ├──Config.toml
  └──User (a folder for some logging)

Currently or we have everything in each acqusition or we have to have one folder supplementary above. To have such organisation it might be needed in some function to change the detection of the session from :

session_dir = os.path.realpath(os.path.join(project_dir, '..','..'))

to :

session_dir = os.path.realpath(os.path.join(project_dir, '..'))

Would you agree ?

ANaaim commented 3 months ago

Or we could directly add in the function that if the session folder is given no automatic detection is done ?

    if config.get('project').get('session_dir') is None:
        # if batch
        session_dir = os.path.realpath(os.path.join(project_dir, '..'))
        # if single trial
        session_dir = session_dir if 'Config.toml' in os.listdir(session_dir) else os.getcwd()
    else: 
        session_dir = config.get('project').get('session_dir')
ANaaim commented 3 months ago

Are you ok with it ? If yes I can do do a PR. :)

davidpagnon commented 3 months ago

Hi, thank you for the proposal!

Sorry, I could not find time to think about it before :/ My mind is not very sharp at that time of the night but it looks good, and I would be happy if you did a PR!

From what I can think of the top of my head, the last option looks like It's the most convenient in terms of coding and of keeping legacy functionalities.

Do we need a User folder though? The logs could stay in the session directory, couldn't they? Also, I'm not sure we need a Config.toml file in the calibration folder.

It would be nice if there was a Config.toml file in each Acquisition folder as well, that would be taken into account only if the parameters are uncommented.

We can always call each other to make sure we are on the same page.

davidpagnon commented 3 months ago

Also, note that @hunminkim98 and I are about to implement pose estimation. I'm running the last tests but it should be released sometime next week. We may run into some merge issues but it should not be too hard to solve.

ANaaim commented 3 months ago

From what you say, it also could be in option as an int. it would indicate what is the parent level. 0 : the acquisition itself 1 : the participant level 2 : the session level

?

davidpagnon commented 3 months ago

Do you mean adding the option in the Config file? If it could be determined automatically it would be even better :) (but I'm not sure I understood)

davidpagnon commented 3 months ago

Actually I think I understood, and I agree!

ANaaim commented 3 months ago

And if not given ==> the "legacy" behavior ?

davidpagnon commented 3 months ago

What I had in mind is that it would be cool if it could guess it automatically from the folder structure.

But honestly, it would be nice but I'm not sure we actually need the legacy option. The only thing is that it should be possible to run it from within the acquisition (single analysis) or from the session (batch analysis). And it would be nice to have a Config file in each acquisition session so that the user can uncomment and edit a parameter if they want to analyze this acquisition slightly differently.

Does it make sense?

davidpagnon commented 3 months ago

(I don't have your number but mine can be found on the Internet, so don't hesitate to give me a call :) )

davidpagnon commented 2 months ago

Hi, sorry for being so long; I made significant changes that would have been a pain to merge. But if you are still up for doing the folder architecture, it should be alright now! Now that I think about it, it is not worth keeping the complicated one for legacy, I don't think anyone actually found it convenient.

Note that Pose estimation is now available, but only if you build from source. I need to wait for the author of RTMlib to release the changes we made to his library in order to obtain feet keypoints along with body (and without all the face and finger ones):

git clone --depth 1 https://github.com/perfanalytics/pose2sim.git
cd pose2sim
pip install .
davidpagnon commented 2 months ago

(update: no need to install from source anymore, the author of RTMlib just pushed his last release on Pypi, which lets me push the last Pose2Sim release as well)

ANaaim commented 2 months ago

@hunminkim98 @davidpagnon thanks :)

ANaaim commented 2 months ago

Just to let you know I had to still do the following modification to make it work 👍 In triangulation.py line 333, the following line should be changed from :

    # if batch
    session_dir = os.path.realpath(os.path.join(project_dir, '..','..'))

to

    # if batch
    session_dir = os.path.realpath(os.path.join(project_dir, '..'))

and

line 727 should be changed from :

    # if batch
    session_dir = os.path.realpath(os.path.join(project_dir, '..','..'))

to

    # if batch
    session_dir = os.path.realpath(os.path.join(project_dir, '..'))

Similarly, in person association line 568 and 630 should be changed from :

    # if batch
    session_dir = os.path.realpath(os.path.join(project_dir, '..','..'))

to

    # if batch
    session_dir = os.path.realpath(os.path.join(project_dir, '..'))
davidpagnon commented 2 months ago

Okay, thanks! I only tested it for the "standard" structure:

Single session
├── calibration /
├── videos /
└── Config.toml

Do your modifications work for the batch structure without further change in Pose2Sim.py -> read_config_files()? (and is it equivalent to this one?)

Batch session
├──calibration /
├── acquisition_001 /
│    ├── videos /
│    └── Config.toml
├── acquisition_002
│    ├── videos /
│    └── Config.toml
└──Config.toml
ANaaim commented 2 months ago

You need to have a config file in each acquisiton to do the batch processing ? If yes that might come from this, but I doubt as in the code that i am modifying i am saying that it should only look 1 folder above instead of two

Thanks in advance.

davidpagnon commented 2 months ago

Hi, I just fixed batch processing, created a demo for it, and updated the documentation :)

ANaaim commented 2 months ago

Will try it on my example tomorrow !!

davidpagnon commented 2 months ago

Be aware that for now you need a Config.toml file in both root and trial levels, so that you can