Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paddleOCR在Linux下自动中断程序 #13941

Open
3 tasks done
Boom-Wang opened this issue Oct 5, 2024 · 2 comments
Open
3 tasks done

paddleOCR在Linux下自动中断程序 #13941

Boom-Wang opened this issue Oct 5, 2024 · 2 comments

Comments

@Boom-Wang
Copy link

Boom-Wang commented Oct 5, 2024

🔎 Search before asking

  • I have searched the PaddleOCR Docs and found no similar bug report.
  • I have searched the PaddleOCR Issues and found no similar bug report.
  • I have searched the PaddleOCR Discussions and found no similar bug report.

🐛 Bug (问题描述)

碰到了一个问题:代码在本地Windows环境下运行的时候可以正常运行,并且在测试了一个视频后可以继续测试下一个,不会自动中断。

但是当我把代码放到Linux环境中,测试完一个视频后会自动中断,需要我通过手动启动代码的方式才能继续测试下一个视频

这个问题是当我将LPRNet识别车牌模型换成PaddleOCR模型之后才出现的,之前我用LPRNet来进行车牌识别没有这个问题,但是由于LPRNet识别车牌效果很差,所以换成效果更好的PaddleOCR。

Windows环境下的cuda为11.8,Linux为11.3

🏃‍♂️ Environment (运行环境)

OS Ubuntu 18
Python 3.8
PaddleOCR 2.8.1
CUDA 11.3

🌰 Minimal Reproducible Example (最小可复现问题的Demo)

def recognize_plate_single_image(plate_img):
ocr = get_ocr()
result = ocr.ocr(plate_img, det=False, cls=True)
if result:
text = result[0][0][0]
confidence = result[0][0][1]
return text, confidence
else:
return "未检测到", 0

@app.route('/car/recognize', methods=['POST'])
def recognize_car():

model = get_model()
data = request.get_json()
video_url = data.get('videoUrl')
final_results = []
for track_id, data in vehicle_detections.items():
    carType = Counter(data["carTypes"]).most_common(1)[0][0]
    
    license_plate_groups = {}
    for idx, (num, conf) in enumerate(zip(data["carNums"], data["carNumConfs"])):
        if num not in license_plate_groups:
            license_plate_groups[num] = {'confs': [conf], 'indices': [idx]}
        else:
            license_plate_groups[num]['confs'].append(conf)
            license_plate_groups[num]['indices'].append(idx)

    valid_license_plates = []
    for num, info in license_plate_groups.items():
        confs = info['confs']
        min_conf = min(confs)
        max_conf = max(confs)
        # 判断置信度差异是否小于 0.1
        if max_conf >= 0.95:
            valid_license_plates.append((num, len(confs), info['indices']))
    
    if valid_license_plates:
        # 选择出现次数最多的车牌号
        valid_license_plates.sort(key=lambda x: x[1], reverse=True)
        carNum = valid_license_plates[0][0]
        selected_indices = valid_license_plates[0][2]
        
        # 根据选定的车牌号,获取对应的车牌颜色
        carNumColors_filtered = [data["carNumColors"][i] for i in selected_indices]
        if carNumColors_filtered:
            carNumColor = Counter(carNumColors_filtered).most_common(1)[0][0]
        else:
            carNumColor = "unknown"
    else:
        carNum = "未检测到"
        carNumColor = "unknown"
    
    # 车辆颜色直接统计出现次数最多的
    carColor = Counter(data["carColors"]).most_common(1)[0][0]
    
    result = {
        "carType": carType,
        "carNum": carNum,
        "carColor": carColor,
        "carNumColor": carNumColor,
    }
    final_results.append(result)

vehicle_frames.clear()
vehicle_positions.clear()
return jsonify(final_results)
@Boom-Wang
Copy link
Author

Boom-Wang commented Oct 5, 2024

在第二次启动测试时,Linux环境下会自动杀死程序且无任何报错,终端仅有“已杀死”显示

@Gmgge
Copy link
Contributor

Gmgge commented Oct 8, 2024

缺乏部分细节目前很难确定到具体的原因,这边建议是:请确定get_ocr函数是否会重复加载推理模型,一般来说ocr推理会话只建议构建一次。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants