#环境配置（每次启动都运行一遍）
conda deactivate
conda activate pdr
source ~/.profile
nvcc -V
cd /home/wuzekai/PaddleOCR-2.9
export WANDB_MODE=offline

#模型训练指令
python tools/train.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml
python tools/train.py -c configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_teacher.yml
python tools/train.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml
python tools/train.py -c configs/rec/PP-OCRv4/ch_PP-OCRv4_rec_hgnet.yml

#训练模型导出为推理模型指令
python tools/export_model.py -c "./configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml" -o Global.pretrained_model="./output/ch_db_res18/best_accuracy.pdparams" Global.save_inference_dir="./inference_model/det_v2/"
python tools/export_model.py -c "./configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_teacher.yml" -o Global.pretrained_model="./output/ch_PP-OCRv4/best_accuracy.pdparams" Global.save_inference_dir="./inference_model/det_v4/"
python tools/export_model.py -c "./configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml" -o Global.pretrained_model="./output/rec_chinese_common_v2.0/best_accuracy.pdparams" Global.save_inference_dir="./inference_model/rec_v2/"
python tools/export_model.py -c "./configs/rec/PP-OCRv4/ch_PP-OCRv4_rec_hgnet.yml" -o Global.pretrained_model="./output/rec_ppocr_v4_hgnet/best_accuracy.pdparams" Global.save_inference_dir="./inference_model/rec_v4/"

#训练模型进行测试集评估指标指令
python tools/eval.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml -o Global.pretrained_model=output/ch_db_res18/best_accuracy.pdparams -o Eval.dataset.label_file_list=["./train_data/det/test.txt"]
python tools/eval.py -c configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_teacher.yml -o Global.pretrained_model=output/ch_PP-OCRv4/best_accuracy.pdparams -o Eval.dataset.label_file_list=["./train_data/det/test.txt"]
python tools/eval.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml -o Global.pretrained_model=output/rec_chinese_common_v2.0/best_accuracy.pdparams -o Eval.dataset.label_file_list=["./train_data/rec/test.txt"]
python tools/eval.py -c configs/rec/PP-OCRv4/ch_PP-OCRv4_rec_hgnet.yml -o Global.pretrained_model=output/rec_ppocr_v4_hgnet/best_accuracy.pdparams -o Eval.dataset.label_file_list=["./train_data/rec/test.txt"]

#训练模型进行测试集评估结果指令
python tools/infer_det.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml -o Global.pretrained_model=output/ch_db_res18/best_accuracy.pdparams Global.infer_img_folder="/home/wuzekai/PaddleOCR-2.9/train_data/det/test"
python tools/infer_det.py -c configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_teacher.yml -o Global.pretrained_model=output/ch_PP-OCRv4/best_accuracy.pdparams Global.infer_img_folder="/home/wuzekai/PaddleOCR-2.9/train_data/det/test"
python tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml -o Global.pretrained_model=output/rec_chinese_common_v2.0/best_accuracy.pdparams Global.infer_list="/home/wuzekai/PaddleOCR-2.9/train_data/rec/test.txt"
python tools/infer_rec.py -c configs/rec/PP-OCRv4/ch_PP-OCRv4_rec_hgnet.yml -o Global.pretrained_model=output/rec_ppocr_v4_hgnet/best_accuracy.pdparams Global.infer_list="/home/wuzekai/PaddleOCR-2.9/train_data/rec/test.txt"

#推理模型进行预测
python tools/infer/predict_system.py --image_dir="./test_img/.jpg" --det_model_dir="./inference_model/det_v2" --rec_model_dir="./inference_model/rec_v2"
python tools/infer/predict_system.py --image_dir="./test_img/.jpg" --det_model_dir="./inference_model/det_v4" --rec_model_dir="./inference_model/rec_v4"
paddleocr --image_dir=./test_img/55.jpg --det_model_dir="./inference_model/det_v4" --rec_model_dir="./inference_model/rec_v4" --type=structure --recovery=true --lang='ch' --output="./inference_results/table"

#图片表格识别
python ppstructure/table/predict_table.py
    --det_model_dir=./inference_model/det_v4
    --rec_model_dir=./inference_model/rec_v4
    --table_model_dir=./inference_model/ch_ppstructure_mobile_v2.0_SLANet_infer
    --rec_char_dict_path=./ppocr/utils/ppocr_keys_v1.txt
    --table_char_dict_path=./ppocr/utils/dict/table_structure_dict_ch.txt
    --image_dir=./test_img/1.jpg
    --output=./inference_results/table
    
#接口1的部署和调试指令
python app.py
curl -X POST http://localhost:8019/ocr/process -F "file=@./test_img/1.jpg"
curl -X GET http://localhost:8019/ocr/text/
curl -X GET http://localhost:8019/ocr/download/ --output output.jpg
curl -X DELETE http://localhost:8019/ocr/delete/

#接口2的部署和调试指令
export CUDA_VISIBLE_DEVICES=0
hub serving start -c deploy/hubserving/ocr_system/config.json
python tools/test_hubserving.py --server_url http://localhost:8021/predict/ocr_system --image_dir ./test_img/1.jpg
curl -H "Content-Type:application/json" -X POST --data "{\"images\": [\"……\"]}" http://localhost:8021/predict/ocr_system
