Commit
·
e9a4aaa
1
Parent(s):
59d116a
GPU parameter tuning
Browse files- modules/maskrcnn_train.sh +34 -4
modules/maskrcnn_train.sh
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
#!/bin/bash
|
2 |
|
|
|
|
|
|
|
3 |
# Get script dir
|
4 |
SCRIPT_DIR=$(cd $(dirname $0); pwd)
|
5 |
|
@@ -29,7 +32,7 @@ if [ ! -f "$COCO_CONFIG_FILE" ]; then
|
|
29 |
fi
|
30 |
|
31 |
# Download the base config file if it doesn't exist
|
32 |
-
if [ ! -f "$BASE_CONFIG_FILE" ];
|
33 |
echo "Downloading Base-RCNN-FPN.yaml configuration file..."
|
34 |
wget $BASE_CONFIG_URL -O $BASE_CONFIG_FILE
|
35 |
fi
|
@@ -39,6 +42,33 @@ if [ ! -f "$TRAIN_NET_FILE" ]; then
|
|
39 |
echo "Downloading train_net.py file..."
|
40 |
wget $TRAIN_NET_URL -O $TRAIN_NET_FILE
|
41 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Function to extract the number of classes from COCO annotation and run training
|
43 |
python3 - <<END
|
44 |
import os
|
@@ -77,10 +107,10 @@ cfg = get_cfg()
|
|
77 |
cfg.merge_from_file("$COCO_CONFIG_FILE")
|
78 |
cfg.DATASETS.TRAIN = ("coco_roboone_train",)
|
79 |
cfg.DATASETS.TEST = ("coco_roboone_val",)
|
80 |
-
cfg.SOLVER.IMS_PER_BATCH =
|
81 |
-
cfg.SOLVER.BASE_LR =
|
82 |
cfg.SOLVER.MAX_ITER = 1000
|
83 |
-
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE =
|
84 |
cfg.MODEL.ROI_HEADS.NUM_CLASSES = num_classes # Automatically set based on dataset
|
85 |
cfg.OUTPUT_DIR = "$OUTPUT_DIR"
|
86 |
|
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
+
# Set whether to use GPU tuning or not
|
4 |
+
USE_GPU_TUNING=true
|
5 |
+
|
6 |
# Get script dir
|
7 |
SCRIPT_DIR=$(cd $(dirname $0); pwd)
|
8 |
|
|
|
32 |
fi
|
33 |
|
34 |
# Download the base config file if it doesn't exist
|
35 |
+
if [ ! -f "$BASE_CONFIG_FILE" ];then
|
36 |
echo "Downloading Base-RCNN-FPN.yaml configuration file..."
|
37 |
wget $BASE_CONFIG_URL -O $BASE_CONFIG_FILE
|
38 |
fi
|
|
|
42 |
echo "Downloading train_net.py file..."
|
43 |
wget $TRAIN_NET_URL -O $TRAIN_NET_FILE
|
44 |
fi
|
45 |
+
|
46 |
+
# Default values
|
47 |
+
IMS_PER_BATCH=2
|
48 |
+
BATCH_SIZE_PER_IMAGE=512
|
49 |
+
BASE_LR=0.00025
|
50 |
+
|
51 |
+
# If USE_GPU_TUNING is true, adjust parameters based on GPU memory
|
52 |
+
if [ "$USE_GPU_TUNING" = true ]; then
|
53 |
+
# Get the GPU memory in MB
|
54 |
+
GPU_MEMORY=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits | head -n 1)
|
55 |
+
|
56 |
+
# Set the batch size and learning rate based on GPU memory
|
57 |
+
if [ "$GPU_MEMORY" -ge 24576 ]; then
|
58 |
+
IMS_PER_BATCH=8 # For 24GB+ GPUs
|
59 |
+
BATCH_SIZE_PER_IMAGE=512
|
60 |
+
elif [ "$GPU_MEMORY" -ge 12288 ]; then
|
61 |
+
IMS_PER_BATCH=4 # For 12GB+ GPUs
|
62 |
+
BATCH_SIZE_PER_IMAGE=256
|
63 |
+
else
|
64 |
+
IMS_PER_BATCH=2 # For smaller GPUs
|
65 |
+
BATCH_SIZE_PER_IMAGE=128
|
66 |
+
fi
|
67 |
+
|
68 |
+
# Adjust learning rate based on batch size
|
69 |
+
BASE_LR=$(echo "0.00025 * $IMS_PER_BATCH / 2" | bc -l)
|
70 |
+
fi
|
71 |
+
|
72 |
# Function to extract the number of classes from COCO annotation and run training
|
73 |
python3 - <<END
|
74 |
import os
|
|
|
107 |
cfg.merge_from_file("$COCO_CONFIG_FILE")
|
108 |
cfg.DATASETS.TRAIN = ("coco_roboone_train",)
|
109 |
cfg.DATASETS.TEST = ("coco_roboone_val",)
|
110 |
+
cfg.SOLVER.IMS_PER_BATCH = $IMS_PER_BATCH
|
111 |
+
cfg.SOLVER.BASE_LR = $BASE_LR
|
112 |
cfg.SOLVER.MAX_ITER = 1000
|
113 |
+
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = $BATCH_SIZE_PER_IMAGE
|
114 |
cfg.MODEL.ROI_HEADS.NUM_CLASSES = num_classes # Automatically set based on dataset
|
115 |
cfg.OUTPUT_DIR = "$OUTPUT_DIR"
|
116 |
|