Проблема фрагментации маски во время отслеживания SAM2Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Проблема фрагментации маски во время отслеживания SAM2

Сообщение Anonymous »

Я сейчас работаю над отслеживанием объектов. Я использую moondream2 , чтобы идентифицировать объекты в сцене, отфильтровать дублированные ограничительные коробки, а затем использовать sam2 для отслеживания объектов. Во время процесса отслеживания начальная маска может быть неполной, что может привести к фрагментированным маскам. Чтобы повысить точность отслеживания, я хочу реализовать метод в моем коде, чтобы определить, является ли маска непрерывной или фрагментированной. Как я могу этого добиться? < /P>

Код: Выделить всё

start_flag = time.time()
# Visual Querying
scan_text_prompt2 = 'Can you describe the cash register screen and everything on the counter? Please list all the items on the counter, excluding the screen.'
scan_ans2:str = model.query(crop_PIL, f"{scan_text_prompt2}")["answer"]
print(f"\nVisual query: '{scan_text_prompt2}'")
print(scan_ans2)
title_text += f'{scan_text_prompt2} {scan_ans2}\n'

end_flag = time.time()
print('Process time: ' + str(round(end_flag - start_flag, 3)) + 'seconds')

title_text = ''
start_flag = time.time()

locate_text_prompt = scan_ans2
print(f"\nObject detection: {locate_text_prompt}")

detect_prompts = [prompt.strip() for prompt in locate_text_prompt.split(',')]

objects = []

for prompt in detect_prompts:
print(f"Detecting: {prompt}")
detection_result = model.detect(crop_PIL, prompt)["objects"]
print(f"Found {len(detection_result)} product(s) for '{prompt}'")

objects.extend(detection_result)

title_text += f'{prompt}:\n'

print("Final detected objects:", objects)

end_flag = time.time()
print('Process time: ' + str(round(end_flag - start_flag, 3)) + ' seconds')

filtered_boxes = remove_overlapping_boxes(objects, iou_threshold=0.3)

print(filtered_boxes)

for i, box in enumerate(filtered_boxes):
print(f"Box {i}: {box}")
image_np = cv2.cvtColor(np.array(crop_PIL.copy()), cv2.COLOR_BGR2RGB)

for bbox in filtered_boxes:
result = draw_bbox(image_np, bbox)

try:
for bbox in filtered_boxes:
result = draw_bbox(image_np, bbox)
plt.imshow(cv2.cvtColor(np.array(result), cv2.COLOR_BGR2RGB))
#plt.title(title_text)
except:
plt.imshow(cv2.cvtColor(np.array(image_np), cv2.COLOR_BGR2RGB))
#plt.title(title_text)
print("error")

filtered_boxes_np = []
for bbox in filtered_boxes:
result = box_dict_to_array(image_np, filtered_boxes)
filtered_boxes_np.append(result)
print(filtered_boxes_np)

ann_frame_idx = 0

prompts = {}

plt.figure(figsize=(9, 6))
plt.title(f"frame {ann_frame_idx}")
plt.imshow(Image.open(os.path.join(video_dir, frame_names[ann_frame_idx])))

for i, box in enumerate(filtered_boxes_np):
ann_obj_id = i

points = get_two_pt(box)
labels = np.array([1, 1], np.int32)

prompts[ann_obj_id] = points, labels

_, out_obj_ids, out_mask_logits = predictor.add_new_points_or_box(
inference_state=inference_state,
frame_idx=ann_frame_idx,
obj_id=ann_obj_id,
points=points,
labels=labels,
)

show_points(points, labels, plt.gca())
for j, out_obj_id in enumerate(out_obj_ids):
show_points(*prompts[out_obj_id], plt.gca())
show_mask((out_mask_logits[j] > 0.0).cpu().numpy(), plt.gca(), obj_id=out_obj_id)

plt.axis('off')
plt.tight_layout()
plt.show()
< /code>
После этого < /p>
print(out_mask_logits[0])
plt.imshow(out_mask_logits[0][0].cpu().numpy(), cmap='viridis')
plt.colorbar()
plt.title("Logit Heatmap")
plt.show()
< /code>
Я получил < /p>
tensor([[[-13.0000, -13.0000, -13.0000,  ..., -16.2500, -16.2500, -16.2500],
[-13.1292, -13.1292, -13.1292,  ..., -16.0312, -16.0312, -16.0312],
[-14.5069, -14.5069, -14.5069,  ..., -13.6979, -13.6979, -13.6979],
...,
[-12.0451, -12.0451, -12.0451,  ..., -11.9167, -11.9167, -11.9167],
[-11.4896, -11.4896, -11.4896,  ..., -11.2500, -11.2500, -11.2500],
[-11.4375, -11.4375, -11.4375,  ..., -11.1875, -11.1875, -11.1875]]],
device='cuda:0')

Как я могу решить ситуацию
at inte "at inte». src = "https://i.sstatic.net/iybm1yfw.png" title = "Seperate Mask Secue"/>
Я хотел бы иметь условие или метод, чтобы помочь мне различить сломанные (отключенные) маски, вместо использования цикла, чтобы проверить их один.>

Подробнее здесь: https://stackoverflow.com/questions/795 ... 2-tracking
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»