Update
This commit is contained in:
@@ -54,7 +54,7 @@ class ConfigManager:
|
||||
"models_directory": "data/models",
|
||||
"base_model_choices": [
|
||||
"yolov8s-seg.pt",
|
||||
"yolov11s-seg.pt",
|
||||
"yolo11s-seg.pt",
|
||||
],
|
||||
},
|
||||
"training": {
|
||||
@@ -225,6 +225,4 @@ class ConfigManager:
|
||||
|
||||
def get_allowed_extensions(self) -> list:
|
||||
"""Get list of allowed image file extensions."""
|
||||
return self.get(
|
||||
"image_repository.allowed_extensions", Image.SUPPORTED_EXTENSIONS
|
||||
)
|
||||
return self.get("image_repository.allowed_extensions", Image.SUPPORTED_EXTENSIONS)
|
||||
|
||||
@@ -46,9 +46,9 @@ def get_pseudo_rgb(arr: np.ndarray, gamma: float = 0.3) -> np.ndarray:
|
||||
a3[a3 > p9999] = p9999
|
||||
a3 /= a3.max()
|
||||
|
||||
# return np.stack([a1, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0)
|
||||
return np.stack([a1, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0)
|
||||
return np.stack([a2, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0)
|
||||
return np.stack([a1, a2, a3], axis=0)
|
||||
# return np.stack([a1, a2, a3], axis=0)
|
||||
|
||||
|
||||
class ImageLoadError(Exception):
|
||||
@@ -114,8 +114,7 @@ class Image:
|
||||
if not is_image_file(str(self.path), self.SUPPORTED_EXTENSIONS):
|
||||
ext = self.path.suffix.lower()
|
||||
raise ImageLoadError(
|
||||
f"Unsupported image format: {ext}. "
|
||||
f"Supported formats: {', '.join(self.SUPPORTED_EXTENSIONS)}"
|
||||
f"Unsupported image format: {ext}. " f"Supported formats: {', '.join(self.SUPPORTED_EXTENSIONS)}"
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@@ -18,7 +18,13 @@ class UT:
|
||||
self.rois = None
|
||||
if no_labels:
|
||||
self.rois = ImagejRoi.fromfile(self.roifile_fn)
|
||||
print(self.roifile_fn.stem)
|
||||
print(self.roifile_fn.parent.parts[-1])
|
||||
if "Roi-" in self.roifile_fn.stem:
|
||||
self.stem = self.roifile_fn.stem.split("Roi-")[1]
|
||||
else:
|
||||
self.stem = self.roifile_fn.parent.parts[-1]
|
||||
|
||||
else:
|
||||
self.roifile_fn = roifile_fn / roifile_fn.parts[-1]
|
||||
self.stem = self.roifile_fn.stem
|
||||
@@ -95,9 +101,7 @@ class UT:
|
||||
for i, roi in enumerate(self.rois):
|
||||
rc = roi.subpixel_coordinates
|
||||
if rc is None:
|
||||
print(
|
||||
f"No coordinates: {self.roifile_fn}, element {i}, out of {len(self.rois)}"
|
||||
)
|
||||
print(f"No coordinates: {self.roifile_fn}, element {i}, out of {len(self.rois)}")
|
||||
continue
|
||||
xmn, ymn = rc.min(axis=0)
|
||||
xmx, ymx = rc.max(axis=0)
|
||||
@@ -143,6 +147,9 @@ if __name__ == "__main__":
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# print(args)
|
||||
# aa
|
||||
|
||||
for path in args.input:
|
||||
print("Path:", path)
|
||||
if not args.no_labels:
|
||||
@@ -152,6 +159,7 @@ if __name__ == "__main__":
|
||||
|
||||
else:
|
||||
for rfn in Path(path).glob("*.zip"):
|
||||
# if Path(path).suffix == ".zip":
|
||||
print("Roi FN:", rfn)
|
||||
ut = UT(rfn, args.no_labels)
|
||||
ut.export_rois(args.output, class_index=0)
|
||||
|
||||
@@ -56,9 +56,7 @@ def yolo_bbox_to_xyxy(coords, img_w, img_h):
|
||||
def poly_to_pts(coords, img_w, img_h):
|
||||
# coords: [x1 y1 x2 y2 ...] either normalized or absolute
|
||||
if coords_are_normalized(coords[4:]):
|
||||
coords = [
|
||||
coords[i] * (img_w if i % 2 == 0 else img_h) for i in range(len(coords))
|
||||
]
|
||||
coords = [coords[i] * (img_w if i % 2 == 0 else img_h) for i in range(len(coords))]
|
||||
pts = np.array(coords, dtype=np.int32).reshape(-1, 2)
|
||||
return pts
|
||||
|
||||
@@ -154,21 +152,21 @@ def load_labels_file(label_path):
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Show YOLO segmentation / polygon annotations"
|
||||
)
|
||||
parser = argparse.ArgumentParser(description="Show YOLO segmentation / polygon annotations")
|
||||
parser.add_argument("image", type=str, help="Path to image file")
|
||||
parser.add_argument("labels", type=str, help="Path to YOLO label file (polygons)")
|
||||
parser.add_argument(
|
||||
"--alpha", type=float, default=0.4, help="Polygon fill alpha (0..1)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-bbox", action="store_true", help="Don't draw bounding boxes for polygons"
|
||||
)
|
||||
parser.add_argument("--labels", type=str, help="Path to YOLO label file (polygons)")
|
||||
parser.add_argument("--alpha", type=float, default=0.4, help="Polygon fill alpha (0..1)")
|
||||
parser.add_argument("--no-bbox", action="store_true", help="Don't draw bounding boxes for polygons")
|
||||
args = parser.parse_args()
|
||||
|
||||
print(args)
|
||||
|
||||
img_path = Path(args.image)
|
||||
if args.labels:
|
||||
lbl_path = Path(args.labels)
|
||||
else:
|
||||
lbl_path = img_path.with_suffix(".txt")
|
||||
lbl_path = Path(str(lbl_path).replace("images", "labels"))
|
||||
|
||||
if not img_path.exists():
|
||||
print("Image not found:", img_path)
|
||||
@@ -188,9 +186,7 @@ def main():
|
||||
if not labels:
|
||||
print("No labels parsed from", lbl_path)
|
||||
# continue and just show image
|
||||
out = draw_annotations(
|
||||
img.copy(), labels, alpha=args.alpha, draw_bbox_for_poly=(not args.no_bbox)
|
||||
)
|
||||
out = draw_annotations(img.copy(), labels, alpha=args.alpha, draw_bbox_for_poly=(not args.no_bbox))
|
||||
|
||||
# Convert BGR -> RGB for matplotlib display
|
||||
out_rgb = cv2.cvtColor(out, cv2.COLOR_BGR2RGB)
|
||||
|
||||
Reference in New Issue
Block a user