-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from UoA-CARES/Import-model-back
Import model back
- Loading branch information
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
# Ctrl + C to exit the program | ||
function cleanup() { | ||
exit 1 | ||
} | ||
|
||
trap cleanup SIGINT SIGTERM | ||
|
||
# Time limit for training | ||
if [ -z "$1" ]; then | ||
echo "Please enter the time limit for training" | ||
echo "Usage: ./retrain.sh <time_limit> [<partition_number>]" | ||
echo "Eg: 10s, 6h" | ||
echo "Usage: ./retrain.sh 10s" | ||
exit 1 | ||
fi | ||
|
||
# Set the partition number | ||
if [ -n "$2" ]; then | ||
export GZ_PARTITION="$2" | ||
else | ||
export GZ_PARTITION=150 | ||
fi | ||
|
||
. install/setup.bash | ||
|
||
# Rerun every $1 time | ||
while true; do | ||
colcon build | ||
timeout "$1" gz sim -g & | ||
timeout "$1" ros2 launch reinforcement_learning train.launch.py | ||
|
||
# Get the latest folder in rl_logs | ||
latest_folder=$(ls -lt ./rl_logs | grep '^d' | head -n 1 | awk '{print $NF}') | ||
|
||
# Set the new paths for actor_path and critic_path | ||
new_actor_path="rl_logs/$latest_folder/models/actor_checkpoint.pht" | ||
new_critic_path="rl_logs/$latest_folder/models/critic_checkpoint.pht" | ||
|
||
# Check if the new paths exist | ||
if [ ! -e "$new_actor_path" ] || [ ! -e "$new_critic_path" ]; then | ||
echo "Error: $new_actor_path or $new_critic_path does not exist" | ||
exit 1 | ||
fi | ||
|
||
# Use sed to update the actor_path and critic_path in the YAML file | ||
sed -i "s#actor_path: '.*'#actor_path: '$new_actor_path'#g" src/reinforcement_learning/config/train.yaml | ||
sed -i "s#critic_path: '.*'#critic_path: '$new_critic_path'#g" src/reinforcement_learning/config/train.yaml | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters