Những lệnh chạy và cấu hình cho mô hình nhận dạng chữ viết (OCR) và ngôn ngữ

Cấu hình môi trường và kiểm tra GPU:

nvidia-smi

Các thư mục chứa dữ liệu:

  • /data1/xyj/datasets/suzhou/images/ocr_en_422k
  • /data1/xyj/datasets/suzhou/images/ocr_zh_230920_381k
  • /data1/xyj/datasets/en_test/
  • /data1/xyj/datasets/zh_test/

Đo thời gian thực thi bằng Python:

start_time = time.time()
print(f"\ntempo_carga: {time.time() - start_time:.2f}s\n")

start_time = time.time()
print(f"\ntempo_processamento: {time.time() - start_time:.2f}s\n")

Chạy mô hình trên thiết bị GPU cụ thể:

CUDA_VISIBLE_DEVICES=1 python chat_qwen_en.py
CUDA_VISIBLE_DEVICES=1 python inference.py

Chạy mô hình DeepSolo (OCR tiếng Anh):

python demo/demo.py \
  --config-file configs/ViTAEv2_S/TotalText/finetune_150k_tt_mlt_13_15_textocr.yaml \
  --input /data1/xyj/datasets/en_test \
  --output output \
  --opts MODEL.WEIGHTS work_dirs/tt_vitaev2-s_finetune_synth-tt-mlt-13-15-textocr.pth

Chạy mô hình DeepSolo (OCR tiếng Trung — ReCTS):

CUDA_VISIBLE_DEVICES=2 python demo/demo.py \
  --config-file configs/ViTAEv2_S/ReCTS/finetune.yaml \
  --input /data1/xyj/datasets/suzhou/images/ocr_zh_230920_381k \
  --output output \
  --opts MODEL.WEIGHTS work_dirs/rects_vitaev2-s_finetune.pth

Chạy mô hình cơ sở ResNet-50 (OCR tiếng Trung — ReCTS):

CUDA_VISIBLE_DEVICES=2 python demo/demo.py \
  --config-file configs/R_50/ReCTS/finetune.yaml \
  --input /data1/xyj/datasets/suzhou/images/ocr_zh_230920_381k \
  --output output \
  --opts MODEL.WEIGHTS work_dirs/rects_res50_finetune.pth

Chạy mô hình trên tập dữ liệu kiểm tra tiếng Trung (DeepSolo):

CUDA_VISIBLE_DEVICES=2 python demo/demo.py \
  --config-file configs/ViTAEv2_S/TotalText/finetune_150k_tt_mlt_13_15_textocr.yaml \
  --input /data1/xyj/datasets/zh_test \
  --output output \
  --opts MODEL.WEIGHTS work_dirs/tt_vitaev2-s_finetune_synth-tt-mlt-13-15-textocr.pth

Chạy mô hình ResNet-50 trên tập kiểm tra tiếng Trung:

CUDA_VISIBLE_DEVICES=2 python demo/demo.py \
  --config-file configs/R_50/ReCTS/finetune.yaml \
  --input /data1/xyj/datasets/zh_test \
  --output output \
  --opts MODEL.WEIGHTS work_dirs/rects_res50_finetune.pth

Cài đặt môi trường DeepSolo:

git clone https://github.com/NanjunGao/DeepSolo.git && mv DeepSolo DeepSolo-main
cd DeepSolo-main
conda create -n deepsolo python=3.8 -y
conda activate deepsolo
pip install torch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt
python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu118/torch2.2/index.html
python setup.py build develop

Thư mục cần tạo thêm:

  • work_dirs: lưu trọng số mô hình
  • output: lưu kết quả đầu ra

Sao chép các thành phần cần thiết:

  • Trọng số mô hình từ đường dẫn gốc vào work_dirs
  • File font chữ SimSun:
  • Danh sách ký tự Trung Quốc (chn_cls_list)

Đoạn mã cần hiệu chỉnh trong các file sau:

  • demo/demo.py
  • demo/predictor.py
  • adet/utils/visualizer.py
  • adet/data/__init__.py

Chạy ứng dụng DeepSolo từiya:

python demo/demo.py \
  --config-file configs/ViTAEv2_S/TotalText/finetune_150k_tt_mlt_13_15_textocr.yaml \
  --input /data1/xyj/datasets/en_test \
  --output output \
  --opts MODEL.WEIGHTS work_dirs/tt_vitaev2-s_finetune_synth-tt-mlt-13-15-textocr.pth

Các phụ kiện cần cài đặt cho Flask và cấu hình Docker:

pip install portalocker omegaconf antlr4-python3-runtime blinker flask

Tạo Docker container với môi trường DeepSolo:

docker run --name deepsolo-env -idt continuumio/anaconda3
docker cp /home/appadmin/miniconda3/envs/deepsolo deepsolo-env:/opt/conda/envs/
docker cp ./DeepSolo deepsolo-env:/root/
docker commit -a 'author' -m 'cấu hình DeepSolo' deepsolo-env deepsolo:v1

Hoặc xây dựng Docker image từ Dockerfile:

sudo docker build -t deepsolo:v2 .
sudo docker run -d -p 5021:5021 --gpus 'device=2' \
  -v /data1/congd/shared_data:/root/DeepSolo/shared_data \
  --name DeepsoloContainer deepsolo:v2

Mô hình ConZIC

Tạo môi trường Python cho ConZIC:

conda create -n ConZIC python=3.8 -y
conda activate ConZIC
pip install torch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt

Chạy mô hình sinh mô tả ảnh:

python demo.py \
  --run_type "caption" \
  --order "sequential" \
  --sentence_len 10 \
  --caption_img_path "./examples/girl.jpg" \
  --samples_num 1 \
  --lm_model "bert-base-uncased" \
  --match_model "openaiclip-vit-base-patch32" \
  --alpha 0.02 \
  --beta 2.0

Thẻ: OCR DeepSolo ViTAEv2 Detectron2 ReCTS

Đăng vào ngày 16 tháng 05 lúc 19:50