M2cai16-tool-locations Page

path: ./m2cai16-tool-locations train: images/train val: images/val nc: 16 names: ['grasper','scissors','hook','clipper','irrigator','specimen_bag','bipolar','hook_electrode','trocars','stapler','suction','clip_applier','vessel_sealer','ligasure','ultrasonic','other'] This guide gives you a production‑ready starting point for loading, visualizing, converting, and training on the dataset. Adjust class names and annotation JSON structure based on your exact dataset version.

def __len__(self): return len(self.samples)

import matplotlib.pyplot as plt from torchvision.utils import draw_bounding_boxes from torchvision.transforms import ToTensor def show_annotations(dataset, idx=0): img, target = dataset[idx] if isinstance(img, torch.Tensor): img = (img * 255).byte() if img.max() <= 1 else img else: img = ToTensor()(img).byte()

def __init__(self, root_dir, transform=None): self.root_dir = root_dir self.transform = transform self.samples = [] # Collect all (frame_path, annotation_path) pairs ann_dir = os.path.join(root_dir, 'annotations') for ann_file in os.listdir(ann_dir): if not ann_file.endswith('.json'): continue ann_path = os.path.join(ann_dir, ann_file) video_id = ann_file.replace('.json', '') frame_dir = os.path.join(root_dir, 'frames', video_id) with open(ann_path, 'r') as f: annotations = json.load(f) for frame_name, boxes_info in annotations.items(): frame_path = os.path.join(frame_dir, frame_name) if os.path.exists(frame_path): self.samples.append((frame_path, boxes_info))

yolo detect train data=m2cai16.yaml model=yolov8n.pt epochs=100 imgsz=640 Example m2cai16.yaml :

boxes = target['boxes'].int() labels = target['labels'] class_names = dataset.CLASSES

import json import os from PIL import Image import torch from torch.utils.data import Dataset from torchvision.ops import box_convert class M2CAI16ToolLocations(Dataset): """Dataset for m2cai16-tool-locations bounding box annotations."""

# 16 tool classes (example; adjust to your annotation file) CLASSES = [ 'background', 'grasper', 'scissors', 'hook', 'clipper', 'irrigator', 'specimen_bag', 'bipolar', 'hook_electrode', 'trocars', 'stapler', 'suction', 'clip_applier', 'vessel_sealer', 'ligasure', 'ultrasonic', 'other' ]

Web-faqja jonë përdor Cookies për të përmirësuar eksperiencën tuaj në shfletimin e faqes. Duke klikuar "Unë pajtohem" ose duke vazhduar me përdorimin e web-faqes, ju pajtoheni me përdorimin e Cookies. Nëse ju nuk pajtoheni, ju mund t'i ndryshoni parametrat e kërkimit në shfletuesin tuaj.

Më shumë informacione