Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FLiTrak3D
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cribellier, Antoine
FLiTrak3D
Commits
78d4adaf
Commit
78d4adaf
authored
3 years ago
by
Antoine
Browse files
Options
Downloads
Patches
Plain Diff
Renamed to main_process_mating.py
parent
a3291fa6
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Development
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main_process_mating.py
+113
-113
113 additions, 113 deletions
main_process_mating.py
with
113 additions
and
113 deletions
process_mating.py
→
main_
process_mating.py
+
113
−
113
View file @
78d4adaf
import
os
,
time
from
core.images_processing
import
ImagesProcessing
#import deeplabcut
start
=
time
.
time
()
xyz_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
calib_files/xyz_calibration_device_small.csv
'
)
#xy_path = os.path.join(os.getcwd(), 'calib_files/20200615_xypts-rot.csv')
xy_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
calib_files/20200615_xypts.csv
'
)
dlt_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
calib_files/20200615_DLTcoefs-py.csv
'
)
dlc_cfg_path
=
'
/home/user/Desktop/Antoine/_DLC/config.yaml
'
img_size
=
(
896
,
896
)
# Generate dlt coefficients
#gen_dlt(3, img_size, xyz_path, xy_path, dlt_path)
img_process
=
ImagesProcessing
(
3
,
dlt_path
)
img_process
.
cam_paths
=
{
1
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron1/_MatingKinematics
'
,
2
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron2/_MatingKinematics
'
,
3
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron3/_MatingKinematics
'
}
img_process
.
cam_save_paths
=
{
1
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron1/_MatingKinematics/_Process
'
,
2
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron2/_MatingKinematics/_Process
'
,
3
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron3/_MatingKinematics/_Process
'
}
img_process
.
update_leading_zero
=
False
img_process
.
init_paths_names
()
img_process
.
max_diff_date_s
=
90
img_process
.
show_plot
=
False
# # Fill dict with name of recordings to process
# # > either all recordings from a given date
# date_to_process = '20200303'
# rec_names_to_process = {}
# for camn in range(1, img_process.nb_cam + 1):
# rec_names_to_process[camn] = [s for s in img_process.all_folders_rec_cam[camn] if date_to_process in s]
# > all recordings
rec_names_to_process
=
{}
for
camn
in
range
(
1
,
img_process
.
nb_cam
+
1
):
rec_names_to_process
[
camn
]
=
img_process
.
all_folders_rec_cam
[
camn
]
# # Keep only rec_names that haven't been processed yet
# non_processed_rec_names = {1: [], 2: [], 3: []}
# for camn in range(1, img_process.nb_cam + 1):
# for i, rec_name in enumerate(rec_names_to_process[camn]):
# if not os.path.exists(os.path.join(img_process.cam_save_paths[camn], '_Avi', rec_name)):
# non_processed_rec_names[camn].append(rec_names_to_process[camn][i])
#
# rec_names_to_process = non_processed_rec_names
# -----------------------------------------------------------------------------------------------------------------------
# Will prepare recordings to be used by Deeplabcut
# > do everything automatically use 'multi_processes'
# Do cropping, rotating, stitching, etc at once and save as .avi (save much time and space)
img_process
.
do_batch
(
'
multi_processes
'
,
rec_names
=
rec_names_to_process
,
yaml_path
=
'
processes.yaml
'
,
delete_previous
=
True
)
# > OR do each step separately
# Convert image to 8 bits and reduce framerate (save in cam_save_paths/_Sample)
# img_process.do_batch('sample', rec_names=rec_names_to_process, step_frame=50, delete_previous=True)
#
# # Do 2d tracking (blob detection) on images in cam_save_paths/_Sample
# img_process.do_batch('track2d', rec_names=rec_names_to_process, from_fn_name='sample')
#
# # Do 3d reconstruction of tracks
# img_process.do_batch('recon3d', rec_names=rec_names_to_process, from_fn_name='sample')
#
# # Crop all frames and save in cam_save_paths/_Cropped
# img_process.do_batch('crop', rec_names=rec_names_to_process, from_fn_name='sample', height_crop=200, width_crop=200, delete_previous=True)
#
# # Rotate view 2 (to always have piston coming from right side)
# img_process.do_batch('rotate', rec_names=rec_names_to_process, from_fn_name='crop', camns=[2], degrees=270)
#
# # Stitch all views together and save in cam_save_paths/_Stitched
# img_process.do_batch('stitch', rec_names=rec_names_to_process, from_fn_name='crop', delete_previous=True)
# -----------------------------------------------------------------------------------------------------------------------
# Run Deeplabcut analysis + Fit 3D skeleton to 2D coordinate from Deeplabcut
dlc_cfg_path
=
'
/home/user/Desktop/Antoine/_maDLC/config.yaml
'
shuffle
=
31
iteration
=
70000
model_name
=
'
DLC_resnet50_MatingKinematicsshuffle{0}_{1}
'
.
format
(
shuffle
,
iteration
)
res_method
=
'
3d
'
# '2d', '3d' or '2d_geo'
opt_method
=
'
leastsq
'
# 'powell' or 'leastsq' or 'least_squares'
body_param_names
=
[
'
yaw_a
'
,
'
pitch_a
'
,
'
roll_a
'
,
'
x_com
'
,
'
y_com
'
,
'
z_com
'
]
wing_param_names
=
[
'
stroke_a
'
,
'
deviation_a
'
,
'
rotation_a
'
]
# # Track features using DeepLabCut
# img_process.do_batch('analyse_dlc', rec_names=rec_names_to_process, from_fn_name='save_avi', cfg_path=dlc_cfg_path,
# shuffle=shuffle, trainingsetindex=0, batchsize=5, save_avi=False, model_name=model_name, delete_previous=True)
# # Load (+ filtering and unscrambling) 2d coords from DLC + Reverse processes (unstitch, rotate back, uncrop) + Reconstruct 3d coord
# img_process.do_batch('load_dlc', rec_names=rec_names_to_process, from_fn_name='analyse_dlc', model_name=model_name,
# tracker_method='skeleton')
# # Optimize fit of skeleton to find body and wings angles
# img_process.multiprocessing = True
# img_process.threshold_likelihood = 0.85
# img_process.do_batch('fit_skeleton', rec_names=rec_names_to_process, from_fn_name='load_dlc', model_name=model_name,
# csv_path=csv_wings_geo_path, body_param_names=body_param_names, wing_param_names=wing_param_names,
# res_method=res_method, opt_method=opt_method)
import
os
,
time
from
core.images_processing
import
ImagesProcessing
#import deeplabcut
start
=
time
.
time
()
xyz_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
calib_files/xyz_calibration_device_small.csv
'
)
#xy_path = os.path.join(os.getcwd(), 'calib_files/20200615_xypts-rot.csv')
xy_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
calib_files/20200615_xypts.csv
'
)
dlt_path
=
os
.
path
.
join
(
os
.
getcwd
(),
'
calib_files/20200615_DLTcoefs-py.csv
'
)
dlc_cfg_path
=
'
/home/user/Desktop/Antoine/_DLC/config.yaml
'
img_size
=
(
896
,
896
)
# Generate dlt coefficients
#gen_dlt(3, img_size, xyz_path, xy_path, dlt_path)
img_process
=
ImagesProcessing
(
3
,
dlt_path
)
img_process
.
cam_paths
=
{
1
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron1/_MatingKinematics
'
,
2
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron2/_MatingKinematics
'
,
3
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron3/_MatingKinematics
'
}
img_process
.
cam_save_paths
=
{
1
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron1/_MatingKinematics/_Process
'
,
2
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron2/_MatingKinematics/_Process
'
,
3
:
'
/media/user/MosquitoLanding_Photron3_Backup/Photron3/_MatingKinematics/_Process
'
}
img_process
.
update_leading_zero
=
False
img_process
.
init_paths_names
()
img_process
.
max_diff_date_s
=
90
img_process
.
show_plot
=
False
# # Fill dict with name of recordings to process
# # > either all recordings from a given date
# date_to_process = '20200303'
# rec_names_to_process = {}
# for camn in range(1, img_process.nb_cam + 1):
# rec_names_to_process[camn] = [s for s in img_process.all_folders_rec_cam[camn] if date_to_process in s]
# > all recordings
rec_names_to_process
=
{}
for
camn
in
range
(
1
,
img_process
.
nb_cam
+
1
):
rec_names_to_process
[
camn
]
=
img_process
.
all_folders_rec_cam
[
camn
]
# # Keep only rec_names that haven't been processed yet
# non_processed_rec_names = {1: [], 2: [], 3: []}
# for camn in range(1, img_process.nb_cam + 1):
# for i, rec_name in enumerate(rec_names_to_process[camn]):
# if not os.path.exists(os.path.join(img_process.cam_save_paths[camn], '_Avi', rec_name)):
# non_processed_rec_names[camn].append(rec_names_to_process[camn][i])
#
# rec_names_to_process = non_processed_rec_names
# -----------------------------------------------------------------------------------------------------------------------
# Will prepare recordings to be used by Deeplabcut
# > do everything automatically use 'multi_processes'
# Do cropping, rotating, stitching, etc at once and save as .avi (save much time and space)
img_process
.
do_batch
(
'
multi_processes
'
,
rec_names
=
rec_names_to_process
,
yaml_path
=
'
processes.yaml
'
,
delete_previous
=
True
)
# > OR do each step separately
# Convert image to 8 bits and reduce framerate (save in cam_save_paths/_Sample)
# img_process.do_batch('sample', rec_names=rec_names_to_process, step_frame=50, delete_previous=True)
#
# # Do 2d tracking (blob detection) on images in cam_save_paths/_Sample
# img_process.do_batch('track2d', rec_names=rec_names_to_process, from_fn_name='sample')
#
# # Do 3d reconstruction of tracks
# img_process.do_batch('recon3d', rec_names=rec_names_to_process, from_fn_name='sample')
#
# # Crop all frames and save in cam_save_paths/_Cropped
# img_process.do_batch('crop', rec_names=rec_names_to_process, from_fn_name='sample', height_crop=200, width_crop=200, delete_previous=True)
#
# # Rotate view 2 (to always have piston coming from right side)
# img_process.do_batch('rotate', rec_names=rec_names_to_process, from_fn_name='crop', camns=[2], degrees=270)
#
# # Stitch all views together and save in cam_save_paths/_Stitched
# img_process.do_batch('stitch', rec_names=rec_names_to_process, from_fn_name='crop', delete_previous=True)
# -----------------------------------------------------------------------------------------------------------------------
# Run Deeplabcut analysis + Fit 3D skeleton to 2D coordinate from Deeplabcut
dlc_cfg_path
=
'
/home/user/Desktop/Antoine/_maDLC/config.yaml
'
shuffle
=
31
iteration
=
70000
model_name
=
'
DLC_resnet50_MatingKinematicsshuffle{0}_{1}
'
.
format
(
shuffle
,
iteration
)
res_method
=
'
3d
'
# '2d', '3d' or '2d_geo'
opt_method
=
'
leastsq
'
# 'powell' or 'leastsq' or 'least_squares'
body_param_names
=
[
'
yaw_a
'
,
'
pitch_a
'
,
'
roll_a
'
,
'
x_com
'
,
'
y_com
'
,
'
z_com
'
]
wing_param_names
=
[
'
stroke_a
'
,
'
deviation_a
'
,
'
rotation_a
'
]
# # Track features using DeepLabCut
# img_process.do_batch('analyse_dlc', rec_names=rec_names_to_process, from_fn_name='save_avi', cfg_path=dlc_cfg_path,
# shuffle=shuffle, trainingsetindex=0, batchsize=5, save_avi=False, model_name=model_name, delete_previous=True)
# # Load (+ filtering and unscrambling) 2d coords from DLC + Reverse processes (unstitch, rotate back, uncrop) + Reconstruct 3d coord
# img_process.do_batch('load_dlc', rec_names=rec_names_to_process, from_fn_name='analyse_dlc', model_name=model_name,
# tracker_method='skeleton')
# # Optimize fit of skeleton to find body and wings angles
# img_process.multiprocessing = True
# img_process.threshold_likelihood = 0.85
# img_process.do_batch('fit_skeleton', rec_names=rec_names_to_process, from_fn_name='load_dlc', model_name=model_name,
# csv_path=csv_wings_geo_path, body_param_names=body_param_names, wing_param_names=wing_param_names,
# res_method=res_method, opt_method=opt_method)
print
(
'
> All processes as been processed (total time elapsed: {0:.4f} s)
'
.
format
(
time
.
time
()
-
start
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment