YOLOv3的dectect.py文件在服务器上保存结果图片

部署运行你感兴趣的模型镜像
from __future__ import division

from models import *
from utils.utils import *
from utils.datasets import *

import os
import sys
import time
import datetime
import argparse

from PIL import Image

import torch
from torch.utils.data import DataLoader
from torchvision import datasets
from torch.autograd import Variable

import cv2

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--image_folder", type=str, default="data/samples", help="path to dataset")
    parser.add_argument("--model_def", type=str, default="config/yolov3.cfg", help="path to model definition file")
    parser.add_argument("--weights_path", type=str, default="weights/yolov3.weights", help="path to weights file")
    parser.add_argument("--class_path", type=str, default="data/coco.names", help="path to class label file")
    parser.add_argument("--conf_thres", type=float, default=0.8, help="object confidence threshold")
    parser.add_argument("--nms_thres", type=float, default=0.4, help="iou thresshold for non-maximum suppression")
    parser.add_argument("--batch_size", type=int, default=1, help="size of the batches")
    parser.add_argument("--n_cpu", type=int, default=0, help="number of cpu threads to use during batch generation")
    parser.add_argument("--img_size", type=int, default=416, help="size of each image dimension")
    parser.add_argument("--checkpoint_model", type=str, help="path to checkpoint model")
    opt = parser.parse_args()
    print(opt)

    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

    os.makedirs("output", exist_ok=True)

    # Set up model
    model = Darknet(opt.model_def, img_size=opt.img_size).to(device)

    if opt.weights_path.endswith(".weights"):
        # Load darknet weights
        model.load_darknet_weights(opt.weights_path)
    else:
        # Load checkpoint weights
        model.load_state_dict(torch.load(opt.weights_path))

    model.eval()  # Set in evaluation mode

    dataloader = DataLoader(
        ImageFolder(opt.image_folder, img_size=opt.img_size),
        batch_size=opt.batch_size,
        shuffle=False,
        num_workers=opt.n_cpu,
    )

    classes = load_classes(opt.class_path)  # Extracts class labels from file

    Tensor = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor

    imgs = []  # Stores image paths
    img_detections = []  # Stores detections for each image index

    print("\nPerforming object detection:")
    prev_time = time.time()
    for batch_i, (img_paths, input_imgs) in enumerate(dataloader):
        # Configure input
        input_imgs = Variable(input_imgs.type(Tensor))

        # Get detections
        with torch.no_grad():
            detections = model(input_imgs)
            detections = non_max_suppression(detections, opt.conf_thres, opt.nms_thres)

        # Log progress
        current_time = time.time()
        inference_time = datetime.timedelta(seconds=current_time - prev_time)
        prev_time = current_time
        print("\t+ Batch %d, Inference Time: %s" % (batch_i, inference_time))

        # Save image and detections
        imgs.extend(img_paths)
        img_detections.extend(detections)

    # Bounding-box colors
    cmap = plt.get_cmap("tab20b")
    colors = [cmap(i) for i in np.linspace(0, 1, 20)]

    print("\nSaving images:")
    # Iterate through images and save plot of detections
    for img_i, (path, detections) in enumerate(zip(imgs, img_detections)):

        print("(%d) Image: '%s'" % (img_i, path))

        # Create plot
        img = np.array(Image.open(path))

        # Draw bounding boxes and labels of detections
        if detections is not None:
            # Rescale boxes to original image
            detections = rescale_boxes(detections, opt.img_size, img.shape[:2])
            unique_labels = detections[:, -1].cpu().unique()
            n_cls_preds = len(unique_labels)
            for x1, y1, x2, y2, conf, cls_conf, cls_pred in detections:
#                 if(cls_conf<0.8):
#                     continue

                box_w = x2 - x1
                box_h = y2 - y1

                if(cls_pred==0):
                    color = (0,0,255)
                else:
                    color = (0,255,255)
                # Create a Rectangle patch
                img = cv2.rectangle(img,(x1,y1),(x2,y2),color,2)

        filename = path.split("/")[-1].split(".")[0]
        cv2.imwrite('./output/'+filename+'.png',img)

 

您可能感兴趣的与本文相关的镜像

Yolo-v5

Yolo-v5

Yolo

YOLO(You Only Look Once)是一种流行的物体检测和图像分割模型,由华盛顿大学的Joseph Redmon 和Ali Farhadi 开发。 YOLO 于2015 年推出,因其高速和高精度而广受欢迎

<think> 我们正在分析`PowerManagerService`中的一条日志:"Face Dectect wakeUpInternal type:invokeDeviceAndGetNewOrder#10408" 其中: - "Face Dectect" 可能指人脸检测(Face Detection) - "wakeUpInternal" 是PowerManagerService内部唤醒设备的方法 - "type:invokeDeviceAndGetNewOrder" 表示唤醒类型 - "#10408" 是用户ID(uid),代表发起唤醒请求的应用 根据Android源码(以Android 10为例): - `PowerManagerService`的`wakeUpInternal`方法负责唤醒设备,调用栈通常来自系统服务或应用通过Binder发起的请求。 - 该日志打印于`PowerManagerService`中,表明设备因人脸检测功能而被唤醒。 分析: 1. **唤醒来源**:`invokeDeviceAndGetNewOrder`这个类型字符串很可能是一个自定义的唤醒原因(WakeReason),由人脸检测服务设置。 2. **人脸检测唤醒**:在Android设备上,人脸检测唤醒通常与智能解锁(Smart Lock)相关,例如:当检测到已注册的人脸时,设备从休眠状态唤醒。 3. **UID 10408**:通过`adb shell cmd package list packages -U | grep 10408`可以查询该UID对应的应用包名。例如,如果该UID对应的是华为的人脸解锁服务,则包名可能为`com.huawei.faceunlock`。 源码定位(以AOSP为例): - 在`PowerManagerService.java`中,`wakeUpInternal`方法会记录唤醒原因: ```java private void wakeUpInternal(long eventTime, String reason, int uid, String opPackageName, int opUid) { ... Slog.i(TAG, "Wakeup from: " + reason + " by uid=" + uid); ... } ``` 但日志中打印的是“Face Dectect wakeUpInternal type:...”,说明可能被定制修改(如华为的EMUI)。因此,实际代码可能为: ```java Slog.i(TAG, "Face Dectect wakeUpInternal type:" + reason + "#" + uid); ``` 结论: - 该日志表明设备因人脸检测功能被唤醒,唤醒原因为`invokeDeviceAndGetNewOrder`,发起唤醒请求的应用UID为10408。 - `invokeDeviceAndGetNewOrder`可能是华为或设备制造商自定义的唤醒原因字符串,用于标识人脸检测唤醒流程中的某个特定步骤(例如:调用设备传感器获取新的人脸数据顺序)。 扩展信息: - 如果频繁出现此唤醒事件,可能影响设备续航(因为从休眠状态唤醒设备会消耗较多电量)。 - 可以通过以下命令检查该UID对应的应用: ```bash adb shell cmd package list packages --uid 10408 ``` 相关问题: 1. 如何查询Android设备上UID对应的应用包名? 2. 人脸检测唤醒在Android系统中的工作原理是什么? 3. 如何减少因人脸检测导致的设备唤醒次数? </think> ### `PowerManagerService`中`Face Dectect wakeUpInternal type:invokeDeviceAndGetNewOrder#10408`的深入解析 #### 一、日志含义分解 1. **核心组件** ```plaintext PowerManagerService: Face Dectect wakeUpInternal type:invokeDeviceAndGetNewOrder#10408 ``` - **`PowerManagerService`**:Android系统电源管理核心服务 - **`Face Dectect`**:人脸检测唤醒功能(华为/荣耀设备常见) - **`wakeUpInternal`**:系统内部唤醒设备的底层方法 - **`invokeDeviceAndGetNewOrder`**:唤醒操作标识符(字面含义:调用设备并获取新指令) - **`#10408`**:发起唤醒请求的应用UID(用户标识符) #### 二、技术原理 1. **唤醒流程** $$ \text{人脸检测模块} \xrightarrow{\text{锁定目标}} \text{wakeUpInternal} \xrightarrow{\text{唤醒屏幕}} \text{PowerManagerService} $$ - 当人脸检测模块识别到已注册用户时,会触发`invokeDeviceAndGetNewOrder`指令 - `wakeUpInternal`方法强制设备退出休眠状态(即使屏幕关闭) - UID `10408`代表发起请求的系统级人脸识别服务 2. **华为定制实现** 在EMUI/HarmonyOS中,该功能涉及: - **`HwPowerManagerService`**:华为扩展的电源服务 - **`dubaid`守护进程**:负责唤醒延迟统计(日志中的`PowerStats.cpp`) - **SCREEN_DIM_WAKE_LOCK**:唤醒锁类型,保持屏幕微亮状态等待用户交互[^1] #### 三、UID 10408的关联应用 通过ADB命令查询: ```bash adb shell cmd package list packages --uid 10408 ``` 典型结果可能是: ```plaintext package:com.huawei.faceunlock uid:10408 ``` 表明这是**华为人脸解锁服务**的系统进程[^2]。 #### 四、问题诊断 当此日志频繁出现时(如您提供的日志中多次出现),可能表示: 1. **人脸误触发**:环境光线/物体误识别为人脸 2. **唤醒锁泄漏**:`SCREEN_DIM_WAKE_LOCK`未及时释放 3. **传感器故障**:ToF/IR摄像头响应异常 ##### 验证命令 ```bash # 检查唤醒锁持有情况 adb shell dumpsys power | grep "invokeDeviceAndGetNewOrder" # 查看人脸服务状态 adb shell dumpsys face_service ``` ---
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值