python评估图像边缘检测模型性能--segment_anything模型

import time
import psutil
import cv2
from segment_anything import sam_model_registry, SamPredictor

# 模拟图像数据
image_paths = ['notebooks/images/dog.jpg', 'notebooks/images/groceries.jpg', 'notebooks/images/truck.jpg']
total_prediction_time = 0.0

# 加载SAM预训练模型
sam_checkpoint = "./models/sam_vit_b_01ec64.pth"
model_type = "vit_b"    
device = "cpu"  # 或者 "cuda",取决于你的设备

sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
sam.to(device=device)

predictor = SamPredictor(sam)

# 对每张图片进行预测
for image_path in image_paths:
    start_time = time.time()

    # 读取图像
    image = cv2.imread(image_path)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    # 设置待预测的图像
    predictor.set_image(image)

    # 执行预测操作
    masks, scores, logits = predictor.predict(
        multimask_output=True,
    )

    end_time = time.time()

    # 计算每张图片的预测时间
    prediction_time = end_time - start_time
    total_prediction_time += prediction_time
    print(f"Prediction time for {image_path}: {prediction_time} seconds")

# 计算平均预测时间
average_prediction_time = total_prediction_time / len(image_paths)
print(f"Average prediction time: {average_prediction_time} seconds")

# 获取系统资源占用情况
memory_percent = psutil.virtual_memory().percent
cpu_percent = psutil.cpu_percent(interval=1)

print(f"Memory percent: {memory_percent}%")
print(f"CPU percent: {cpu_percent}%")




  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值