该模型当前使用的是默认介绍模版,处于“预发布”阶段,页面仅限所有者可见。
请根据模型贡献文档说明,及时完善模型卡片内容。ModelScope平台将在模型卡片完善后展示。谢谢您的理解。
Clone with HTTP
git clone https://www.modelscope.cn/copperfield/cv_tinynas_fishing-dectection_damoyalo.git
推理代码
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
import cv2
import numpy as np
import os
# Initialize the object detection pipeline
object_detect = pipeline(Tasks.image_object_detection, model='copperfield/cv_tinynas_fishing-dectection_damoyalo')
# Directory paths
input_dir = './test'
output_dir = './test_res'
# Create the output directory if it doesn't exist
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Process each image in the input directory
for filename in os.listdir(input_dir):
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
img_path = os.path.join(input_dir, filename)
# Perform object detection
result = object_detect(img_path)
image = cv2.imread(img_path)
# Parse detection results
scores = result['scores']
labels = result['labels']
boxes = result['boxes']
# Draw bounding boxes and labels
for i in range(len(boxes)):
box = boxes[i]
label = labels[i]
score = scores[i]
# Extract bounding box coordinates
x_min, y_min, x_max, y_max = box.astype(np.int32)
# Draw the bounding box
cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 255, 0), 2)
# Label and confidence
label_text = f'{label}: {score:.2f}'
cv2.putText(image, label_text, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
# Save the processed image
output_img_path = os.path.join(output_dir, filename)
cv2.imwrite(output_img_path, image)
评论