推理代码该模型当前使用的是默认介绍模版,处于“预发布”阶段,页面仅限所有者可见。
请根据模型贡献文档说明,及时完善模型卡片内容。ModelScope平台将在模型卡片完善后展示。谢谢您的理解。
Cloe with HTTP
git cloe https://www.modelscope.c/copperfield/cv_tiyas_fishig-dectectio_damoyalo.git
from modelscope.pipelies import pipelie
from modelscope.utils.costat import Tasks
import cv2
import umpy as p
import os
# Iitialize the object detectio pipelie
object_detect = pipelie(Tasks.image_object_detectio, model='copperfield/cv_tiyas_fishig-dectectio_damoyalo')
# Directory paths
iput_dir = './test'
output_dir = './test_res'
# Create the output directory if it does't exist
if ot os.path.exists(output_dir):
os.makedirs(output_dir)
# Process each image i the iput directory
for fileame i os.listdir(iput_dir):
if fileame.lower().edswith(('.pg', '.jpg', '.jpeg')):
img_path = os.path.joi(iput_dir, fileame)
# Perform object detectio
result = object_detect(img_path)
image = cv2.imread(img_path)
# Parse detectio results
scores = result['scores']
labels = result['labels']
boxes = result['boxes']
# Draw boudig boxes ad labels
for i i rage(le(boxes)):
box = boxes[i]
label = labels[i]
score = scores[i]
# Extract boudig box coordiates
x_mi, y_mi, x_max, y_max = box.astype(p.it32)
# Draw the boudig box
cv2.rectagle(image, (x_mi, y_mi), (x_max, y_max), (0, 255, 0), 2)
# Label ad cofidece
label_text = f'{label}: {score:.2f}'
cv2.putText(image, label_text, (x_mi, y_mi - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
# Save the processed image
output_img_path = os.path.joi(output_dir, fileame)
cv2.imwrite(output_img_path, image)
点击空白处退出提示
评论