Theo Viel commited on
Commit ·
4fc0da9
1
Parent(s): c95b6d6
fix docstring & typing
Browse files- graphic_element_v1.py +1 -1
- utils.py +25 -19
graphic_element_v1.py
CHANGED
|
@@ -8,7 +8,7 @@ class Exp:
|
|
| 8 |
Configuration class for the graphic element model.
|
| 9 |
|
| 10 |
This class contains all configuration parameters for the YOLOX-based
|
| 11 |
-
|
| 12 |
parameters, and class-specific thresholds.
|
| 13 |
"""
|
| 14 |
|
|
|
|
| 8 |
Configuration class for the graphic element model.
|
| 9 |
|
| 10 |
This class contains all configuration parameters for the YOLOX-based
|
| 11 |
+
graphic element detection model, including architecture settings, inference
|
| 12 |
parameters, and class-specific thresholds.
|
| 13 |
"""
|
| 14 |
|
utils.py
CHANGED
|
@@ -30,17 +30,20 @@ def reformat_for_plotting(
|
|
| 30 |
) -> Tuple[List[npt.NDArray[np.int_]], List[npt.NDArray[np.float64]]]:
|
| 31 |
"""
|
| 32 |
Reformat YOLOX predictions for plotting.
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
Args:
|
| 35 |
-
boxes (np.ndarray): Array of bounding boxes.
|
| 36 |
-
labels (np.ndarray): Array of labels.
|
| 37 |
-
scores (np.ndarray): Array of confidence scores.
|
| 38 |
-
shape (tuple): Shape of the image.
|
| 39 |
num_classes (int): Number of classes.
|
| 40 |
|
| 41 |
Returns:
|
| 42 |
-
list[np.ndarray]: List of box bounding boxes per class.
|
| 43 |
-
list[np.ndarray]: List of confidence scores per class.
|
| 44 |
"""
|
| 45 |
boxes_plot = boxes.copy()
|
| 46 |
boxes_plot[:, [0, 2]] *= shape[1]
|
|
@@ -58,6 +61,7 @@ def plot_sample(
|
|
| 58 |
boxes_list: List[npt.NDArray[np.int_]],
|
| 59 |
confs_list: List[npt.NDArray[np.float64]],
|
| 60 |
labels: List[str],
|
|
|
|
| 61 |
) -> None:
|
| 62 |
"""
|
| 63 |
Plots an image with bounding boxes.
|
|
@@ -68,6 +72,7 @@ def plot_sample(
|
|
| 68 |
boxes_list (list[np.ndarray]): List of box bounding boxes per class.
|
| 69 |
confs_list (list[np.ndarray]): List of confidence scores per class.
|
| 70 |
labels (list): List of class labels.
|
|
|
|
| 71 |
"""
|
| 72 |
plt.imshow(img, cmap="gray")
|
| 73 |
plt.axis(False)
|
|
@@ -92,15 +97,16 @@ def plot_sample(
|
|
| 92 |
plt.gca().add_patch(rect)
|
| 93 |
|
| 94 |
# Add class and index label with proper alignment
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
def reorder_boxes(
|
|
@@ -117,13 +123,13 @@ def reorder_boxes(
|
|
| 117 |
Ordering depends on the class.
|
| 118 |
|
| 119 |
Args:
|
| 120 |
-
boxes (np.ndarray): Array of bounding boxes
|
| 121 |
-
labels (np.ndarray): Array of labels
|
| 122 |
classes (list, optional): List of class labels. Defaults to None.
|
| 123 |
-
scores (np.ndarray, optional): Array of
|
| 124 |
|
| 125 |
Returns:
|
| 126 |
-
np.ndarray [N, 4]: Ordered boxes.
|
| 127 |
np.ndarray [N]: Ordered labels.
|
| 128 |
np.ndarray [N]: Ordered scores if scores is not None.
|
| 129 |
"""
|
|
|
|
| 30 |
) -> Tuple[List[npt.NDArray[np.int_]], List[npt.NDArray[np.float64]]]:
|
| 31 |
"""
|
| 32 |
Reformat YOLOX predictions for plotting.
|
| 33 |
+
- Unnormalizes boxes to original image size.
|
| 34 |
+
- Reformats boxes to [xmin, ymin, width, height].
|
| 35 |
+
- Converts to list of boxes and scores per class.
|
| 36 |
|
| 37 |
Args:
|
| 38 |
+
boxes (np.ndarray [N, 4]): Array of bounding boxes in format [xmin, ymin, xmax, ymax].
|
| 39 |
+
labels (np.ndarray [N]): Array of labels.
|
| 40 |
+
scores (np.ndarray [N]): Array of confidence scores.
|
| 41 |
+
shape (tuple [2]): Shape of the image (height, width).
|
| 42 |
num_classes (int): Number of classes.
|
| 43 |
|
| 44 |
Returns:
|
| 45 |
+
list[np.ndarray[N]]: List of box bounding boxes per class.
|
| 46 |
+
list[np.ndarray[N]]: List of confidence scores per class.
|
| 47 |
"""
|
| 48 |
boxes_plot = boxes.copy()
|
| 49 |
boxes_plot[:, [0, 2]] *= shape[1]
|
|
|
|
| 61 |
boxes_list: List[npt.NDArray[np.int_]],
|
| 62 |
confs_list: List[npt.NDArray[np.float64]],
|
| 63 |
labels: List[str],
|
| 64 |
+
show_text: bool = True,
|
| 65 |
) -> None:
|
| 66 |
"""
|
| 67 |
Plots an image with bounding boxes.
|
|
|
|
| 72 |
boxes_list (list[np.ndarray]): List of box bounding boxes per class.
|
| 73 |
confs_list (list[np.ndarray]): List of confidence scores per class.
|
| 74 |
labels (list): List of class labels.
|
| 75 |
+
show_text (bool, optional): Whether to show the text. Defaults to True.
|
| 76 |
"""
|
| 77 |
plt.imshow(img, cmap="gray")
|
| 78 |
plt.axis(False)
|
|
|
|
| 97 |
plt.gca().add_patch(rect)
|
| 98 |
|
| 99 |
# Add class and index label with proper alignment
|
| 100 |
+
if show_text:
|
| 101 |
+
plt.text(
|
| 102 |
+
box[0], box[1],
|
| 103 |
+
f"{l}_{box_idx} conf={confs[box_idx]:.3f}",
|
| 104 |
+
color='white',
|
| 105 |
+
fontsize=8,
|
| 106 |
+
bbox=dict(facecolor=col, alpha=1, edgecolor=col, pad=0, linewidth=2),
|
| 107 |
+
verticalalignment='bottom',
|
| 108 |
+
horizontalalignment='left'
|
| 109 |
+
)
|
| 110 |
|
| 111 |
|
| 112 |
def reorder_boxes(
|
|
|
|
| 123 |
Ordering depends on the class.
|
| 124 |
|
| 125 |
Args:
|
| 126 |
+
boxes (np.ndarray [N, 4]): Array of bounding boxes in format [xmin, ymin, xmax, ymax].
|
| 127 |
+
labels (np.ndarray [N]): Array of labels.
|
| 128 |
classes (list, optional): List of class labels. Defaults to None.
|
| 129 |
+
scores (np.ndarray [N], optional): Array of confidence scores. Defaults to None.
|
| 130 |
|
| 131 |
Returns:
|
| 132 |
+
np.ndarray [N, 4]: Ordered boxes in format [xmin, ymin, xmax, ymax].
|
| 133 |
np.ndarray [N]: Ordered labels.
|
| 134 |
np.ndarray [N]: Ordered scores if scores is not None.
|
| 135 |
"""
|