Fix ambiguous variable names (#13864)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: Alex Pasquali <alexpasquali98@gmail.com>
This commit is contained in:
parent
c497732278
commit
ee859ac64d
7 changed files with 22 additions and 24 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ __all__ = (
|
|||
"ResNetLayer",
|
||||
"OBB",
|
||||
"WorldDetect",
|
||||
"v10Detect",
|
||||
"ImagePoolingAttn",
|
||||
"ContrastiveHead",
|
||||
"BNContrastiveHead",
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ __all__ = (
|
|||
"SPPELAN",
|
||||
"CBFuse",
|
||||
"CBLinear",
|
||||
"Silence",
|
||||
"RepVGGDW",
|
||||
"CIB",
|
||||
"C2fCIB",
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ __all__ = (
|
|||
"Heatmap",
|
||||
"ObjectCounter",
|
||||
"ParkingManagement",
|
||||
"ParkingPtsSelection",
|
||||
"QueueManager",
|
||||
"SpeedEstimator",
|
||||
"Analytics",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue