Skip to content

Commit 51bfa5b

Browse files
authored
[DLStreamer] Update license plate detection model and LPR sample (#681)
1 parent 450bfc6 commit 51bfa5b

3 files changed

Lines changed: 27 additions & 64 deletions

File tree

libraries/dl-streamer/samples/download_public_models.sh

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -690,38 +690,23 @@ done
690690
if [[ "$MODEL" == "yolov8_license_plate_detector" ]] || [[ "$MODEL" == "all" ]]; then
691691
MODEL_NAME="yolov8_license_plate_detector"
692692
MODEL_DIR="$MODELS_PATH/public/$MODEL_NAME"
693-
DST_FILE1="$MODEL_DIR/FP16/$MODEL_NAME.xml"
694-
DST_FILE2="$MODEL_DIR/FP32/$MODEL_NAME.xml"
693+
DST_FILE1="$MODEL_DIR/FP32/$MODEL_NAME.xml"
695694

696-
if [[ ! -f "$DST_FILE1" || ! -f "$DST_FILE2" ]]; then
695+
if [[ ! -f "$DST_FILE1" ]]; then
697696
echo "Downloading and converting: ${MODEL_DIR}"
698697
mkdir -p "$MODEL_DIR"
699698
cd "$MODEL_DIR"
700699

701-
curl -L -k -o ${MODEL_NAME}.pt 'https://drive.usercontent.google.com/uc?export=download&id=1Zmf5ynaTFhmln2z7Qvv-tgjkWQYQ9Zdw'
702-
703-
python3 - <<EOF "$MODEL_NAME"
704-
from ultralytics import YOLO
705-
import openvino, sys, shutil, os
706-
707-
model_name = sys.argv[1]
708-
weights = model_name + '.pt'
709-
710-
model = YOLO(weights)
711-
model.info()
712-
converted_path = model.export(format='openvino')
713-
converted_model = converted_path + '/' + model_name + '.xml'
714-
core = openvino.Core()
715-
ov_model = core.read_model(model=converted_model)
716-
717-
ov_model.set_rt_info('YOLOv8', ['model_info', 'model_type'])
718-
719-
openvino.save_model(ov_model, './FP32/' + model_name + '.xml', compress_to_fp16=False)
720-
openvino.save_model(ov_model, './FP16/' + model_name + '.xml', compress_to_fp16=True)
721-
shutil.rmtree(converted_path)
722-
os.remove(f"{model_name}.pt")
723-
EOF
700+
curl -L -k -o ${MODEL_NAME}.zip 'https://github.com/open-edge-platform/edge-ai-resources/raw/main/models/license-plate-reader.zip'
701+
unzip -o ${MODEL_NAME}.zip
702+
rm -f ${MODEL_NAME}.zip
724703

704+
mkdir -p FP32
705+
cp license-plate-reader/models/yolov8n/yolov8n_retrained.bin FP32/${MODEL_NAME}.bin
706+
cp license-plate-reader/models/yolov8n/yolov8n_retrained.xml FP32/${MODEL_NAME}.xml
707+
chmod -R u+w license-plate-reader
708+
rm -rf license-plate-reader
709+
cd ..
725710
else
726711
echo_color "\nModel already exists: $MODEL_DIR.\n" "yellow"
727712
fi
@@ -915,47 +900,23 @@ fi
915900
if [[ "$MODEL" == "ch_PP-OCRv4_rec_infer" ]] || [[ "$MODEL" == "all" ]]; then
916901
MODEL_NAME="ch_PP-OCRv4_rec_infer"
917902
MODEL_DIR="$MODELS_PATH/public/$MODEL_NAME"
918-
DST_FILE1="$MODEL_DIR/FP32/$MODEL_NAME.xml"
919-
DST_FILE2="$MODEL_DIR/FP16/$MODEL_NAME.xml"
903+
DST_FILE1="$MODEL_DIR/FP16/$MODEL_NAME.xml"
920904

921-
if [[ ! -f "$DST_FILE1" || ! -f "$DST_FILE2" ]]; then
922-
mkdir -p "$MODEL_DIR"
905+
if [[ ! -f "$DST_FILE1" ]]; then
923906
echo "Downloading and converting: ${MODEL_DIR}"
907+
mkdir -p "$MODEL_DIR"
924908
cd "$MODEL_DIR"
925-
curl -L -O "https://paddleocr.bj.bcebos.com/PP-OCRv4/chinese/$MODEL_NAME.tar"
926-
python3 - <<EOF "$MODEL_NAME" "$MODEL_DIR" "$DST_FILE1"
927-
import tarfile
928-
import openvino as ov
929-
import sys, os, shutil
930-
931-
model_name = sys.argv[1]
932-
model_dir = sys.argv[2]
933-
orig_model_path = sys.argv[1]
934-
935-
file = tarfile.open(f"{model_name}.tar")
936-
res = file.extractall(model_dir)
937-
file.close()
938-
if not res:
939-
print(f"Model Extracted to {model_dir}.")
940-
else:
941-
print("Error Extracting the model.")
942909

943-
ov_model = ov.convert_model("ch_PP-OCRv4_rec_infer/inference.pdmodel")
944-
ov_model.reshape({"x": [-1, 3, 48, 192]})
910+
curl -L -k -o ${MODEL_NAME}.zip 'https://github.com/open-edge-platform/edge-ai-resources/raw/main/models/license-plate-reader.zip'
911+
unzip -o ${MODEL_NAME}.zip
912+
rm -f ${MODEL_NAME}.zip
945913

946-
ov_model.set_rt_info("paddle_ocr", ['model_info', 'model_type'])
947-
ov_model.set_rt_info("58.395, 57.12, 57.375", ['model_info', 'scale_values']) #std = [0.229, 0.224, 0.225]
948-
ov_model.set_rt_info("123.675, 116.28, 103.53", ['model_info', 'mean_values']) #mean = [0.485, 0.456, 0.406]
949-
ov_model.set_rt_info("true", ['model_info', 'reverse_input_channels'])
950-
ov_model.set_rt_info("standard", ['model_info', 'resize_type'])
951-
952-
ov.save_model(ov_model, './FP32/' + 'ch_PP-OCRv4_rec_infer.xml', compress_to_fp16=False)
953-
ov.save_model(ov_model, './FP16/' + 'ch_PP-OCRv4_rec_infer.xml', compress_to_fp16=True)
954-
955-
shutil.rmtree(model_name)
956-
os.remove(f"{model_name}.tar")
957-
958-
EOF
914+
mkdir -p FP32
915+
cp license-plate-reader/models/ch_PP-OCRv4_rec_infer/ch_PP-OCRv4_rec_infer.bin FP32/${MODEL_NAME}.bin
916+
cp license-plate-reader/models/ch_PP-OCRv4_rec_infer/ch_PP-OCRv4_rec_infer.xml FP32/${MODEL_NAME}.xml
917+
chmod -R u+w license-plate-reader
918+
rm -rf license-plate-reader
919+
cd ..
959920
else
960921
echo_color "\nModel already exists: $MODEL_DIR.\n" "yellow"
961922
fi

libraries/dl-streamer/samples/gstreamer/gst_launch/license_plate_recognition/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ This sample builds a GStreamer pipeline of the following elements:
2323

2424
## Models
2525

26-
The sample uses the [`yolov8_license_plate_detector`](https://github.com/Muhammad-Zeerak-Khan/Automatic-License-Plate-Recognition-using-YOLOv8) model for license plate detection and the [`ch_PP-OCRv4_rec_infer`](https://github.com/PaddlePaddle/PaddleOCR) model for optical character recognition (OCR). The necessary conversion to the OpenVINO™ format is performed by the `download_public_models.sh` script located in the `samples` directory.
26+
The sample uses the [`yolov8_license_plate_detector`](https://github.com/open-edge-platform/edge-ai-resources/blob/main/models/license-plate-reader.zip) model for license plate detection and the [`ch_PP-OCRv4_rec_infer`](https://github.com/PaddlePaddle/PaddleOCR) model for optical character recognition (OCR). The necessary conversion to the OpenVINO™ format is performed by the `download_public_models.sh` script located in the `samples` directory.
27+
28+
The accuracy of license plate detection depends on whether the applied model has been trained using data representing license plates from a specific region. In addition to the default model used in this example, the same pipeline can be used with other license plate detectors, such as the one available [`here`](https://github.com/Muhammad-Zeerak-Khan/Automatic-License-Plate-Recognition-using-YOLOv8).
2729

2830
## Running
2931

libraries/dl-streamer/samples/gstreamer/gst_launch/license_plate_recognition/license_plate_recognition.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ else
1818
fi
1919

2020
# Command-line parameters
21-
INPUT=${1:-https://videos.pexels.com/video-files/30787543/13168475_1280_720_25fps.mp4}
21+
INPUT=${1:-https://github.com/open-edge-platform/edge-ai-resources/raw/main/videos/ParkingVideo.mp4}
2222
DEVICE=${2:-GPU} # Device for decode and inference in OpenVINO(TM) format, examples: AUTO, CPU, GPU, GPU.0
2323
OUTPUT=${3:-fps} # Output type, valid values: display, fps, json, display-and-json, file
2424

0 commit comments

Comments
 (0)