Skip to content

Commit

Permalink
Adding experiment settings to folder
Browse files Browse the repository at this point in the history
Added a src module because I was needing to strip suffixes in both files
so it made sense to create a file for folder handling functions
  • Loading branch information
brunofavs committed May 10, 2024
1 parent be9f9bf commit 6d2230d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
2 changes: 2 additions & 0 deletions atom_batch_execution/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.0.2)
project(atom_batch_execution)

catkin_python_setup()

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

Expand Down
19 changes: 19 additions & 0 deletions atom_batch_execution/scripts/batch_execution
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ from atom_core.system import resolvePath, execute
from atom_core.utilities import atomWarn
from atom_core.naming import generateCollectionKey

from atom_batch_execution.folder_io import stripAutomaticSuffixes


def bprint(text):
"""bprint (batch print) will always print in blue color with yellow background """
Expand Down Expand Up @@ -68,6 +70,10 @@ def main():
required=False, action='store_true')
ap.add_argument("-dr", "--dry_run", help="Run without actually executing the processes.",
required=False, action='store_true')
ap.add_argument("-rs", "--run_suffix", help="Suffix used to signal multiple runs of the same experiment.",
required=False, default='_run', type=str)
ap.add_argument("-fs", "--fold_suffix", help="Suffix used to signal multiple folds of the same run.",
required=False, default='_fold', type=str)

args = vars(ap.parse_args())

Expand Down Expand Up @@ -169,6 +175,7 @@ def main():
bprint('Executing command:\n' + experiment['cmd'])



if args['dry_run']:
bprint('Running in dry run mode...')
continue
Expand All @@ -183,6 +190,14 @@ def main():
# Start executing command.
execute(experiment['cmd'], verbose=args['verbose'], save_path=experiment_folder)

# Save experiment settings
for experiment_type in data['experiments']:
if experiment_type["name"] == stripAutomaticSuffixes(experiment_key,args):
print("WRITING")

settings_file_path = f"{experiment_folder}/{experiment_type['name']}_settings.yml"
yaml.dump(experiment_type, open(settings_file_path, 'w'), sort_keys=False)

# Collect stdout_data files
for file in experiment['files_to_collect']:
if file is None:
Expand All @@ -197,6 +212,10 @@ def main():
filename_out = experiment_folder + '/' + os.path.basename(resolved_file)
print(Fore.BLUE + Back.YELLOW + 'Copying file ' + resolved_file + ' to ' + filename_out + Style.RESET_ALL)
execute('cp ' + resolved_file + ' ' + filename_out, verbose=False)







Expand Down
10 changes: 2 additions & 8 deletions atom_batch_execution/scripts/process_results
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ from colorama import Fore, Style
from atom_core.system import resolvePath
import pandas as pd

from atom_batch_execution.folder_io import stripAutomaticSuffixes

def averageCsvFiles(filenames, average_row):

Expand Down Expand Up @@ -73,14 +74,7 @@ def main():
# Create a list of experiments
files_and_folders = os.listdir(args['results_folder'])
folders = [x for x in files_and_folders if os.path.isdir(args['results_folder'] + '/' + x)]
fold_suffix_size = len(args['fold_suffix']) + 3 # because the suffix is complemented by the run number as in 001
run_suffix_size = len(args['run_suffix']) + 3 # because the suffix is complemented by the run number as in 001
suffix_size = 0
if args['fold_suffix'] in folders[0]:
suffix_size += fold_suffix_size
if args['run_suffix'] in folders[0]:
suffix_size += run_suffix_size
experiments = list(set([x[:-suffix_size] for x in folders])) # Remove the "_foldXX" suffix
experiments = stripAutomaticSuffixes(folders,args)

# files_to_process = ['comparison_to_ground_truth_transforms.csv', 'comparison_to_ground_truth_joints.csv']
# files_to_process = ['single_rgb_evaluation.csv']
Expand Down
12 changes: 12 additions & 0 deletions atom_batch_execution/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values from package.xml
setup_args = generate_distutils_setup(
packages=['atom_batch_execution'],
package_dir={'': 'src'},
)

setup(**setup_args)
Empty file.
40 changes: 40 additions & 0 deletions atom_batch_execution/src/atom_batch_execution/folder_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import copy

# Standard imports
import json
import os
from os.path import exists

import numpy as np

# Opencv imports
import cv2
from atom_core.joint_models import getTransformationFromJoint
from atom_core.utilities import atomError, atomWarn

# Ros imports
import rospy
import tf

def stripAutomaticSuffixes(folders,args):
fold_suffix_size = len(args['fold_suffix']) + 3 # because the suffix is complemented by the run number as in 001
run_suffix_size = len(args['run_suffix']) + 3 # because the suffix is complemented by the run number as in 001
suffix_size = 0

if isinstance(folders,list):

if args['fold_suffix'] in folders[0]:
suffix_size += fold_suffix_size
if args['run_suffix'] in folders[0]:
suffix_size += run_suffix_size
experiments = list(set([x[:-suffix_size] for x in folders])) # Remove the "_foldXX" suffix

elif isinstance(folders,str):

if args['fold_suffix'] in folders:
suffix_size += fold_suffix_size
if args['run_suffix'] in folders:
suffix_size += run_suffix_size
experiments = folders[:-suffix_size] # Remove the "_foldXX" suffix

return experiments

0 comments on commit 6d2230d

Please sign in to comment.