diff --git a/ultralytics/data/converter.py b/ultralytics/data/converter.py index 239bdb89c..0ee390877 100644 --- a/ultralytics/data/converter.py +++ b/ultralytics/data/converter.py @@ -329,8 +329,7 @@ def convert_coco( if lvis: with open((Path(save_dir) / json_file.name.replace("lvis_v1_", "").replace(".json", ".txt")), "a") as f: - for l in image_txt: - f.write(f"{l}\n") + f.writelines(f"{line}\n" for line in image_txt) LOGGER.info(f"{'LVIS' if lvis else 'COCO'} data converted successfully.\nResults saved to {save_dir.resolve()}") @@ -534,25 +533,25 @@ def yolo_bbox2segment(im_dir, save_dir=None, sam_model="sam_b.pt"): LOGGER.info("Detection labels detected, generating segment labels by SAM model!") sam_model = SAM(sam_model) - for l in tqdm(dataset.labels, total=len(dataset.labels), desc="Generating segment labels"): - h, w = l["shape"] - boxes = l["bboxes"] + for label in tqdm(dataset.labels, total=len(dataset.labels), desc="Generating segment labels"): + h, w = label["shape"] + boxes = label["bboxes"] if len(boxes) == 0: # skip empty labels continue boxes[:, [0, 2]] *= w boxes[:, [1, 3]] *= h - im = cv2.imread(l["im_file"]) + im = cv2.imread(label["im_file"]) sam_results = sam_model(im, bboxes=xywh2xyxy(boxes), verbose=False, save=False) - l["segments"] = sam_results[0].masks.xyn + label["segments"] = sam_results[0].masks.xyn save_dir = Path(save_dir) if save_dir else Path(im_dir).parent / "labels-segment" save_dir.mkdir(parents=True, exist_ok=True) - for l in dataset.labels: + for label in dataset.labels: texts = [] - lb_name = Path(l["im_file"]).with_suffix(".txt").name + lb_name = Path(label["im_file"]).with_suffix(".txt").name txt_file = save_dir / lb_name - cls = l["cls"] - for i, s in enumerate(l["segments"]): + cls = label["cls"] + for i, s in enumerate(label["segments"]): line = (int(cls[i]), *s.reshape(-1)) texts.append(("%g " * len(line)).rstrip() % line) if texts: diff --git a/ultralytics/data/split_dota.py b/ultralytics/data/split_dota.py index e9cfc686f..f0a1630ca 100644 --- a/ultralytics/data/split_dota.py +++ b/ultralytics/data/split_dota.py @@ -26,8 +26,8 @@ def bbox_iof(polygon1, bbox2, eps=1e-6): bbox2 (np.ndarray): Bounding boxes, (n ,4). """ polygon1 = polygon1.reshape(-1, 4, 2) - lt_point = np.min(polygon1, axis=-2) - rb_point = np.max(polygon1, axis=-2) + lt_point = np.min(polygon1, axis=-2) # left-top + rb_point = np.max(polygon1, axis=-2) # right-bottom bbox1 = np.concatenate([lt_point, rb_point], axis=-1) lt = np.maximum(bbox1[:, None, :2], bbox2[..., :2]) @@ -35,8 +35,8 @@ def bbox_iof(polygon1, bbox2, eps=1e-6): wh = np.clip(rb - lt, 0, np.inf) h_overlaps = wh[..., 0] * wh[..., 1] - l, t, r, b = (bbox2[..., i] for i in range(4)) - polygon2 = np.stack([l, t, r, t, r, b, l, b], axis=-1).reshape(-1, 4, 2) + left, top, right, bottom = (bbox2[..., i] for i in range(4)) + polygon2 = np.stack([left, top, right, top, right, bottom, left, bottom], axis=-1).reshape(-1, 4, 2) sg_polys1 = [Polygon(p) for p in polygon1] sg_polys2 = [Polygon(p) for p in polygon2] diff --git a/ultralytics/engine/model.py b/ultralytics/engine/model.py index a9fc4e8cb..1ef2e0991 100644 --- a/ultralytics/engine/model.py +++ b/ultralytics/engine/model.py @@ -142,7 +142,6 @@ class Model(nn.Module): # Check if Triton Server model elif self.is_triton_model(model): self.model_name = self.model = model - self.task = task return # Load or create new YOLO model diff --git a/ultralytics/models/sam/modules/tiny_encoder.py b/ultralytics/models/sam/modules/tiny_encoder.py index c56282e16..5ecf426cd 100644 --- a/ultralytics/models/sam/modules/tiny_encoder.py +++ b/ultralytics/models/sam/modules/tiny_encoder.py @@ -384,8 +384,8 @@ class TinyViTBlock(nn.Module): convolution. """ h, w = self.input_resolution - b, l, c = x.shape - assert l == h * w, "input feature has wrong size" + b, hw, c = x.shape # batch, height*width, channels + assert hw == h * w, "input feature has wrong size" res_x = x if h == self.window_size and w == self.window_size: x = self.attn(x) @@ -394,13 +394,13 @@ class TinyViTBlock(nn.Module): pad_b = (self.window_size - h % self.window_size) % self.window_size pad_r = (self.window_size - w % self.window_size) % self.window_size padding = pad_b > 0 or pad_r > 0 - if padding: x = F.pad(x, (0, 0, 0, pad_r, 0, pad_b)) pH, pW = h + pad_b, w + pad_r nH = pH // self.window_size nW = pW // self.window_size + # Window partition x = ( x.view(b, nH, self.window_size, nW, self.window_size, c) @@ -408,19 +408,18 @@ class TinyViTBlock(nn.Module): .reshape(b * nH * nW, self.window_size * self.window_size, c) ) x = self.attn(x) + # Window reverse x = x.view(b, nH, nW, self.window_size, self.window_size, c).transpose(2, 3).reshape(b, pH, pW, c) - if padding: x = x[:, :h, :w].contiguous() - x = x.view(b, l, c) + x = x.view(b, hw, c) x = res_x + self.drop_path(x) - x = x.transpose(1, 2).reshape(b, c, h, w) x = self.local_conv(x) - x = x.view(b, c, l).transpose(1, 2) + x = x.view(b, c, hw).transpose(1, 2) return x + self.drop_path(self.mlp(x)) diff --git a/ultralytics/nn/modules/__init__.py b/ultralytics/nn/modules/__init__.py index 4211a9e31..561f4e772 100644 --- a/ultralytics/nn/modules/__init__.py +++ b/ultralytics/nn/modules/__init__.py @@ -133,6 +133,7 @@ __all__ = ( "ResNetLayer", "OBB", "WorldDetect", + "v10Detect", "ImagePoolingAttn", "ContrastiveHead", "BNContrastiveHead", diff --git a/ultralytics/nn/modules/block.py b/ultralytics/nn/modules/block.py index 4572b1699..186b27bc8 100644 --- a/ultralytics/nn/modules/block.py +++ b/ultralytics/nn/modules/block.py @@ -40,7 +40,6 @@ __all__ = ( "SPPELAN", "CBFuse", "CBLinear", - "Silence", "RepVGGDW", "CIB", "C2fCIB", diff --git a/ultralytics/solutions/__init__.py b/ultralytics/solutions/__init__.py index e19328878..d4e58afd9 100644 --- a/ultralytics/solutions/__init__.py +++ b/ultralytics/solutions/__init__.py @@ -15,6 +15,7 @@ __all__ = ( "Heatmap", "ObjectCounter", "ParkingManagement", + "ParkingPtsSelection", "QueueManager", "SpeedEstimator", "Analytics",