Skip to content

Commit

Permalink
fix tipc
Browse files Browse the repository at this point in the history
  • Loading branch information
LokeZhou committed May 29, 2023
1 parent 5e76dc4 commit bd89865
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 101 deletions.
22 changes: 0 additions & 22 deletions configs/yolov5/_base_/yolov5_reader.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@ input_width: &input_width 640
input_size: &input_size [*input_height, *input_width]
mosaic_epoch: &mosaic_epoch 300


# worker_num: 4
# TrainReader:
# sample_transforms:
# - Decode: {}
# - MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size}
# - RandomHSV: {hgain: 0.015, sgain: 0.7, vgain: 0.4}
# - RandomFlip: {}
# - BboxXYXY2XYWH: {}
# - NormalizeBox: {}
# batch_transforms:
# - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none}
# - Permute: {}
# - PadGT: {}
# batch_size: 8
# shuffle: True
# drop_last: False
# use_shared_memory: True
# collate_batch: True
# mosaic_epoch: *mosaic_epoch


worker_num: 4
TrainReader:
sample_transforms:
Expand Down
21 changes: 0 additions & 21 deletions configs/yolov5/_base_/yolov5_reader_high_aug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@ input_width: &input_width 640
input_size: &input_size [*input_height, *input_width]
mosaic_epoch: &mosaic_epoch 300

# worker_num: 4
# TrainReader:
# sample_transforms:
# - Decode: {}
# - MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size, scale: 0.9, mixup_prob: 0.1, copy_paste_prob: 0.1}
# - RandomHSV: {hgain: 0.015, sgain: 0.7, vgain: 0.4}
# - RandomFlip: {}
# - BboxXYXY2XYWH: {}
# - NormalizeBox: {}
# batch_transforms:
# - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none}
# - Permute: {}
# - PadGT: {}
# batch_size: 8
# shuffle: True
# drop_last: False
# use_shared_memory: True
# collate_batch: True
# mosaic_epoch: *mosaic_epoch


worker_num: 4
TrainReader:
sample_transforms:
Expand Down
23 changes: 1 addition & 22 deletions configs/yolov7/_base_/yolov7_reader.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,11 @@ input_width: &input_width 640
input_size: &input_size [*input_height, *input_width]
mosaic_epoch: &mosaic_epoch 300

# worker_num: 4
# TrainReader:
# sample_transforms:
# - Decode: {}
# - MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size, mixup_prob: 0.15, paste_in_prob: 0.15, translate: 0.2, scale: 0.9}
# - RandomHSV: {hgain: 0.015, sgain: 0.7, vgain: 0.4}
# - RandomFlip: {}
# - BboxXYXY2XYWH: {}
# - NormalizeBox: {}
# batch_transforms:
# - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none}
# - Permute: {}
# - PadGT: {}
# batch_size: 32
# shuffle: True
# drop_last: False
# use_shared_memory: True
# collate_batch: True
# mosaic_epoch: *mosaic_epoch


worker_num: 4
TrainReader:
sample_transforms:
- DecodeNormResize: {target_size: *input_size, mosaic: True}
- MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size, mixup_prob: 0.15, paste_in_prob: 0.15, translate: 0.2, scale: 0.9}
- MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size, scale: 0.9, mixup_prob: 0.1, copy_paste_prob: 0.1}
- RandomHSV: {hgain: 0.015, sgain: 0.7, vgain: 0.4}
- RandomFlip: {}
- BboxXYXY2XYWH: {}
Expand Down
21 changes: 0 additions & 21 deletions configs/yolov7/_base_/yolov7_tiny_reader.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@ input_width: &input_width 640
input_size: &input_size [*input_height, *input_width]
mosaic_epoch: &mosaic_epoch 300

# worker_num: 4
# TrainReader:
# sample_transforms:
# - Decode: {}
# - MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size, mixup_prob: 0.05, paste_in_prob: 0.05, translate: 0.1, scale: 0.5}
# - RandomHSV: {hgain: 0.015, sgain: 0.7, vgain: 0.4}
# - RandomFlip: {}
# - BboxXYXY2XYWH: {}
# - NormalizeBox: {}
# batch_transforms:
# - NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none}
# - Permute: {}
# - PadGT: {}
# batch_size: 32
# shuffle: True
# drop_last: False
# use_shared_memory: True
# collate_batch: True
# mosaic_epoch: *mosaic_epoch


worker_num: 4
TrainReader:
sample_transforms:
Expand Down
64 changes: 51 additions & 13 deletions test_tipc/benchmark_train.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ lines=(${dataline})
model_name=$(func_parser_value "${lines[1]}")

# 获取benchmark_params所在的行数
line_num=`grep -n "train_benchmark_params" $FILENAME | cut -d ":" -f 1`
line_num=`grep -n -w "train_benchmark_params" $FILENAME | cut -d ":" -f 1`
# for train log parser
batch_size=$(func_parser_value "${lines[line_num]}")
line_num=`expr $line_num + 1`
Expand Down Expand Up @@ -144,6 +144,14 @@ if [ ! -n "$PARAMS" ] ;then
device_num="N1C4"
device_num_list=($device_num)
run_mode="DP"
elif [[ ${PARAMS} = "dynamicTostatic" ]] ;then
IFS="|"
model_type=$PARAMS
batch_size_list=(${batch_size})
fp_items_list=(${fp_items})
device_num="N1C4"
device_num_list=($device_num)
run_mode="DP"
else
# parser params from input: modeltype_bs${bs_item}_${fp_item}_${run_mode}_${device_num}
IFS="_"
Expand All @@ -165,17 +173,47 @@ else
device_num_list=($device_num)
fi

if [[ ${model_name} =~ "higherhrnet" ]] || [[ ${model_name} =~ "hrnet" ]] || [[ ${model_name} =~ "tinypose" ]];then
if [[ ${model_name} =~ "yolov5" ]];then
echo "${model_name} run unset MosaicPerspective and RandomHSV"
eval "sed -i '10c 10c - MosaicPerspective: {mosaic_prob: 0.0, target_size: *input_size, scale: 0.9, mixup_prob: 0.1, copy_paste_prob: 0.1}' configs/yolov5/_base_/yolov5_reader_high_aug.yml"
eval "sed -i 's/10c//' configs/yolov5/_base_/yolov5_reader_high_aug.yml"
eval "sed -i 's/^ - RandomHSV: /#&/' configs/yolov5/_base_/yolov5_reader_high_aug.yml"
fi

if [[ ${model_name} =~ "yolov7" ]];then
echo "${model_name} run unset MosaicPerspective and RandomHSV"
eval "sed -i '10c 10c - MosaicPerspective: {mosaic_prob: 0.0, target_size: *input_size, scale: 0.9, mixup_prob: 0.1, copy_paste_prob: 0.1}' configs/yolov7/_base_/yolov7_reader.yml"
eval "sed -i 's/10c//' configs/yolov7/_base_/yolov7_reader.yml"
eval "sed -i 's/^ - RandomHSV: /#&/' configs/yolov7/_base_/yolov7_reader.yml"
fi

# for log name
to_static=""
# parse "to_static" options and modify trainer into "to_static_trainer"
if [[ ${model_type} = "dynamicTostatic" ]];then
to_static="d2sT_"
sed -i 's/trainer:norm_train/trainer:to_static_train/g' $FILENAME
#yolov5 and yolov7 static need MosaicPerspective
eval "sed -i '10c 10c - MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size, scale: 0.9, mixup_prob: 0.1, copy_paste_prob: 0.1}' configs/yolov5/_base_/yolov5_reader_high_aug.yml"
eval "sed -i 's/10c//' configs/yolov5/_base_/yolov5_reader_high_aug.yml"
eval "sed -i '10c 10c - MosaicPerspective: {mosaic_prob: 1.0, target_size: *input_size, scale: 0.9, mixup_prob: 0.1, copy_paste_prob: 0.1}' configs/yolov7/_base_/yolov7_reader.yml"
eval "sed -i 's/10c//' configs/yolov7/_base_/yolov7_reader.yml"
fi



if [[ ${model_name} =~ "higherhrnet" ]] || [[ ${model_name} =~ "hrnet" ]] || [[ ${model_name} =~ "tinypose" ]] || [[ ${model_name} =~ "ppyoloe_r_crn_s_3x_spine_coco" ]] ;then
echo "${model_name} run on full coco dataset"
epoch=$(set_dynamic_epoch $device_num $epoch)
else
epoch=1
repeat=$(set_dynamic_epoch $device_num $repeat)
eval "sed -i '10c\ repeat: ${repeat}' configs/datasets/coco_detection.yml"
eval "sed -i '10c\ repeat: ${repeat}' configs/datasets/coco_instance.yml"
eval "sed -i '10c\ repeat: ${repeat}' configs/datasets/mot.yml"
eval "sed -i '10c\ repeat: ${repeat}' configs/datasets/coco_detection.yml"
eval "sed -i '10c\ repeat: ${repeat}' configs/datasets/coco_instance.yml"
eval "sed -i '10c\ repeat: ${repeat}' configs/datasets/mot.yml"
fi


IFS="|"
for batch_size in ${batch_size_list[*]}; do
for precision in ${fp_items_list[*]}; do
Expand All @@ -189,7 +227,7 @@ for batch_size in ${batch_size_list[*]}; do
if [ ${#gpu_id} -le 1 ];then
log_path="$SAVE_LOG/profiling_log"
mkdir -p $log_path
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_profiling"
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}profiling"
func_sed_params "$FILENAME" "${line_gpuid}" "0" # sed used gpu_id
# set profile_option params
tmp=`sed -i "${line_profile}s/.*/${profile_option}/" "${FILENAME}"`
Expand All @@ -205,8 +243,8 @@ for batch_size in ${batch_size_list[*]}; do
speed_log_path="$SAVE_LOG/index"
mkdir -p $log_path
mkdir -p $speed_log_path
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_log"
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_speed"
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}log"
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}speed"
func_sed_params "$FILENAME" "${line_profile}" "null" # sed profile_id as null
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "
echo $cmd
Expand All @@ -225,7 +263,7 @@ for batch_size in ${batch_size_list[*]}; do
--run_mode ${run_mode} \
--fp_item ${precision} \
--keyword ips: \
--skip_steps 2 \
--skip_steps 4 \
--device_num ${device_num} \
--speed_unit images/s \
--convergence_key loss: "
Expand All @@ -240,8 +278,8 @@ for batch_size in ${batch_size_list[*]}; do
speed_log_path="$SAVE_LOG/index"
mkdir -p $log_path
mkdir -p $speed_log_path
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_log"
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_speed"
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}log"
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}speed"
func_sed_params "$FILENAME" "${line_gpuid}" "$gpu_id" # sed used gpu_id
func_sed_params "$FILENAME" "${line_profile}" "null" # sed --profile_option as null
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "
Expand All @@ -261,7 +299,7 @@ for batch_size in ${batch_size_list[*]}; do
--run_mode ${run_mode} \
--fp_item ${precision} \
--keyword ips: \
--skip_steps 2 \
--skip_steps 4 \
--device_num ${device_num} \
--speed_unit images/s \
--convergence_key loss: "
Expand All @@ -272,4 +310,4 @@ for batch_size in ${batch_size_list[*]}; do
fi
done
done
done
done
16 changes: 14 additions & 2 deletions test_tipc/test_train_inference_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ LOG_PATH="./test_tipc/output/${model_name}/${MODE}"
mkdir -p ${LOG_PATH}
status_log="${LOG_PATH}/results_python.log"

line_num=`grep -n -w "to_static_train_benchmark_params" $FILENAME | cut -d ":" -f 1`
to_static_key=$(func_parser_key "${lines[line_num]}")
to_static_trainer=$(func_parser_value "${lines[line_num]}")


function func_inference(){
IFS='|'
Expand Down Expand Up @@ -256,6 +260,10 @@ else
elif [ ${trainer} = "${trainer_key2}" ]; then
run_train=${trainer_value2}
run_export=${export_value2}
elif [ ${trainer} = "${to_static_key}" ]; then
run_train=${norm_trainer}
run_export=${norm_export}
set_to_static=${to_static_trainer}
else
continue
fi
Expand Down Expand Up @@ -303,7 +311,11 @@ else
fi
# run train
train_log_path="${LOG_PATH}/${trainer}_gpus_${gpu}_autocast_${autocast}_nodes_${nodes}.log"
eval "${cmd} > ${train_log_path} 2>&1"
if [ ${MODE} = "benchmark_train" ]; then
eval "timeout 5m ${cmd} > ${train_log_path} 2>&1"
else
eval "${cmd} > ${train_log_path} 2>&1"
fi
last_status=$?
cat ${train_log_path}
status_check $last_status "${cmd}" "${status_log}" "${model_name}" "${train_log_path}"
Expand Down Expand Up @@ -354,4 +366,4 @@ else
done # done with: for trainer in ${trainer_list[*]}; do
done # done with: for autocast in ${autocast_list[*]}; do
done # done with: for gpu in ${gpu_list[*]}; do
fi # end if [ ${MODE} = "infer" ]; then
fi # end if [ ${MODE} = "infer" ]; then

0 comments on commit bd89865

Please sign in to comment.