Skip to content

Commit

Permalink
download models
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkosm committed Dec 27, 2024
1 parent df63e02 commit ba811a5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
12 changes: 1 addition & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ RUN python3.10 download_models.py
#serverless
# CMD ["sh", "-c", "ls && python3.10 serverless.py"]

# Download and set up models
RUN mkdir -p models && \
# Download PP Detect Model
curl -L -o models/det_model.tar paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_det_infer.tar && \
tar -xvf models/det_model.tar -C models/ && \
rm models/det_model.tar && \
\
# Download PP Rec Model
curl -L -o models/rec_model.tar paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_rec_infer.tar && \
tar -xvf models/rec_model.tar -C models/ && \
rm models/rec_model.tar
RUN sh download_model.sh

CMD ["python3.10", "-m", "app.serverless"]

Expand Down
45 changes: 45 additions & 0 deletions download_model.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -e

# Define log file location
LOG_FILE="/var/log/model_download.log"

echo "Starting model downloads at $(date)" | tee -a "$LOG_FILE"

# Function to download and extract models
download_and_extract() {
local url=$1
local destination_path=$2
local output_tar="$destination_path.tar"
local model_name=$3

echo "Downloading ${model_name} from ${url}" | tee -a "$LOG_FILE"
curl -L -o "${output_tar}" "${url}" 2>&1 | tee -a "$LOG_FILE"

echo "Extracting ${model_name}" | tee -a "$LOG_FILE"
mkdir -p "$(dirname "${destination_path}")"
tar -xvf "${output_tar}" -C "$(dirname "${destination_path}")" 2>&1 | tee -a "$LOG_FILE"

echo "Removing archive for ${model_name}" | tee -a "$LOG_FILE"
rm "${output_tar}" | tee -a "$LOG_FILE"

echo "${model_name} download and extraction completed." | tee -a "$LOG_FILE"
echo "----------------------------------------" | tee -a "$LOG_FILE"
}

# Download PP Detect Model to /root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer/
download_and_extract "https://paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_det_infer.tar" \
"/root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer/ch_ppocr_mobile_v2.0_cls_infer.tar" \
"PP Detect Model"

# Download PP Rec Model to /root/.paddleocr/whl/rec/ch_ppocr_mobile_v2.0_rec_infer/
download_and_extract "https://paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_rec_infer.tar" \
"/root/.paddleocr/whl/rec/ch_ppocr_mobile_v2.0_rec_infer/ch_ppocr_mobile_v2.0_rec_infer.tar" \
"PP Rec Model"

# **New Addition**: Download PP Rec Model to /root/.paddleocr/whl/rec/ch/ch_PP-OCRv4_rec_infer/
download_and_extract "https://paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_rec_infer.tar" \
"/root/.paddleocr/whl/rec/ch/ch_PP-OCRv4_rec_infer/ch_PP-OCRv4_rec_infer.tar" \
"PP Rec Model Additional Path"

echo "All model downloads completed at $(date)" | tee -a "$LOG_FILE"

0 comments on commit ba811a5

Please sign in to comment.