Replies: 1 comment
-
为了减少显存占用,让模型能在8G显存上运行,可以从以下几个方面修改配置文件:
Train:
loader:
batch_size_per_card: 2 # 从原来的64降到2
Eval:
loader:
batch_size_per_card: 2 # 从原来的128降到2
Architecture:
Backbone:
name: SVTRv2
dims: [64, 128, 192] # 降低维度 [128, 256, 384] -> [64, 128, 192]
depths: [3, 3, 3] # 减少层数 [6, 6, 6] -> [3, 3, 3]
num_heads: [2, 4, 6] # 减少注意力头数 [4, 8, 12] -> [2, 4, 6]
Train:
sampler:
scales: [[160, 32], [160, 48], [160, 16]] # 从320降到160
Eval:
dataset:
transforms:
- RecResizeImg:
image_shape: [3, 48, 160] # 从320降到160
Global:
max_text_length: 15 # 从25降到15
save_epoch_step: 20 # 降低保存频率以节省磁盘空间
print_batch_step: 20 # 降低打印频率
Architecture:
Head:
- CTCHead:
Neck:
dims: 128 # 从256降到128
hidden_dims: 128 # 从256降到128
- NRTRHead:
nrtr_dim: 192 # 从384降到192
Train:
loader:
num_workers: 2 # 从8降到2
Eval:
loader:
num_workers: 2 # 从4降到2 这些修改主要通过以下方式减少显存占用:
注意这些修改可能会影响模型的性能,你可以根据实际需求调整这些参数,在显存占用和模型性能之间找到平衡点。 上述修改组合使用后,应该可以显著降低显存占用,使模型能在8G显存上运行。建议先应用这些修改,然后根据实际运行情况进行微调。 Response generated by feifei-bot | claude-3-5-sonnet-latest |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Global:
debug: false
use_gpu: true
epoch_num: 200
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output/rec_svtrv2_ch
save_epoch_step: 10
eval_batch_step: [0, 1000]
cal_metric_during_train: false
pretrained_model:
checkpoints:
save_inference_dir:
use_visualdl: false
infer_img: doc/imgs_words/ch/word_1.jpg
character_dict_path: ppocr/utils/ppocr_keys_v1.txt
max_text_length: &max_text_length 25
infer_mode: false
use_space_char: true
#distributed: true
distributed: false
save_res_path: ./output/rec/predicts_svrtv2.txt
Optimizer:
name: AdamW
beta1: 0.9
beta2: 0.999
epsilon: 1.e-8
weight_decay: 0.05
no_weight_decay_name: norm
one_dim_param_no_weight_decay: True
lr:
name: Cosine
learning_rate: 0.001 # 8gpus 192bs
warmup_epoch: 5
Architecture:
model_type: rec
algorithm: SVTR_HGNet
Transform:
Backbone:
name: SVTRv2
use_pos_embed: False
dims: [128, 256, 384]
depths: [6, 6, 6]
num_heads: [4, 8, 12]
mixer: [['Conv','Conv','Conv','Conv','Conv','Conv'],['Conv','Conv','Global','Global','Global','Global'],['Global','Global','Global','Global','Global','Global']]
local_k: [[5, 5], [5, 5], [-1, -1]]
sub_k: [[2, 1], [2, 1], [-1, -1]]
last_stage: False
use_pool: True
Head:
name: MultiHead
head_list:
- CTCHead:
Neck:
name: svtr
dims: 256
depth: 2
hidden_dims: 256
kernel_size: [1, 3]
use_guide: True
Head:
fc_decay: 0.00001
- NRTRHead:
nrtr_dim: 384
max_text_length: *max_text_length
num_decoder_layers: 2
Loss:
name: MultiLoss
loss_config_list:
- CTCLoss:
- NRTRLoss:
PostProcess:
name: CTCLabelDecode
Metric:
name: RecMetric
main_indicator: acc
Train:
dataset:
name: MultiScaleDataSet
ds_width: false
data_dir: ./train_data/
ext_op_transform_idx: 1
label_file_list:
- ./train_data/train_list.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- RecAug:
- MultiLabelEncode:
gtc_encode: NRTRLabelEncode
- KeepKeys:
keep_keys:
- image
- label_ctc
- label_gtc
- length
- valid_ratio
sampler:
name: MultiScaleSampler
#scales: [[320, 32], [320, 48], [320, 64]]
scales: [[320, 32], [320, 48], [320, 16]]
first_bs: &bs 2
fix_bs: false
divided_factor: [8, 16] # w, h
is_training: True
loader:
shuffle: true
batch_size_per_card: *bs
drop_last: true
num_workers: 8
Eval:
dataset:
name: SimpleDataSet
data_dir: ./train_data
label_file_list:
- ./train_data/val_list.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- MultiLabelEncode:
gtc_encode: NRTRLabelEncode
- RecResizeImg:
image_shape: [3, 48, 320]
- KeepKeys:
keep_keys:
- image
- label_ctc
- label_gtc
- length
- valid_ratio
loader:
shuffle: false
drop_last: false
#batch_size_per_card: 128
batch_size_per_card: 2
num_workers: 4
Beta Was this translation helpful? Give feedback.
All reactions