Spaces:
Sleeping
Sleeping
🧐 [Update] drawer to draw a v9 model
Browse files- yolo/utils/drawer.py +15 -14
yolo/utils/drawer.py
CHANGED
|
@@ -42,7 +42,7 @@ def draw_bboxes(img: Union[Image.Image, torch.Tensor], bboxes: List[List[Union[i
|
|
| 42 |
logger.info("Saved visualize image at visualize.png")
|
| 43 |
|
| 44 |
|
| 45 |
-
def draw_model(*, model_cfg=None, model=None):
|
| 46 |
from graphviz import Digraph
|
| 47 |
|
| 48 |
if model_cfg:
|
|
@@ -52,12 +52,14 @@ def draw_model(*, model_cfg=None, model=None):
|
|
| 52 |
elif model is None:
|
| 53 |
raise ValueError("Drawing Object is None")
|
| 54 |
|
| 55 |
-
model_size = len(model.model)
|
| 56 |
model_mat = np.zeros((model_size, model_size), dtype=bool)
|
| 57 |
|
| 58 |
-
layer_name = []
|
| 59 |
-
for idx, layer in enumerate(model.model):
|
| 60 |
layer_name.append(str(type(layer)).split(".")[-1][:-2])
|
|
|
|
|
|
|
| 61 |
if isinstance(layer.source, int):
|
| 62 |
source = layer.source + (layer.source < 0) * idx
|
| 63 |
model_mat[source, idx] = True
|
|
@@ -66,12 +68,13 @@ def draw_model(*, model_cfg=None, model=None):
|
|
| 66 |
source = source + (source < 0) * idx
|
| 67 |
model_mat[source, idx] = True
|
| 68 |
|
| 69 |
-
pattern_list = [("ELAN", 8, 3), ("ELAN", 8, 55), ("MP", 5, 11)]
|
| 70 |
pattern_mat = []
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
|
| 76 |
dot = Digraph(comment="Model Flow Chart")
|
| 77 |
node_idx = 0
|
|
@@ -83,12 +86,10 @@ def draw_model(*, model_cfg=None, model=None):
|
|
| 83 |
layer_name[idx] = name
|
| 84 |
model_mat[idx : idx + size, jdx : jdx + size] = False
|
| 85 |
model_mat[idx, idx + size] = True
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
dot.node(str(idx), f"{node_idx}-{layer_name[idx]}")
|
| 89 |
-
node_idx += 1
|
| 90 |
for jdx in range(idx, model_size):
|
| 91 |
-
if model_mat[idx, jdx]
|
| 92 |
dot.edge(str(idx), str(jdx))
|
| 93 |
|
| 94 |
dot.render("Model-arch", format="png", cleanup=True)
|
|
|
|
| 42 |
logger.info("Saved visualize image at visualize.png")
|
| 43 |
|
| 44 |
|
| 45 |
+
def draw_model(*, model_cfg=None, model=None, v7_base=False):
|
| 46 |
from graphviz import Digraph
|
| 47 |
|
| 48 |
if model_cfg:
|
|
|
|
| 52 |
elif model is None:
|
| 53 |
raise ValueError("Drawing Object is None")
|
| 54 |
|
| 55 |
+
model_size = len(model.model) + 1
|
| 56 |
model_mat = np.zeros((model_size, model_size), dtype=bool)
|
| 57 |
|
| 58 |
+
layer_name = ["INPUT"]
|
| 59 |
+
for idx, layer in enumerate(model.model, start=1):
|
| 60 |
layer_name.append(str(type(layer)).split(".")[-1][:-2])
|
| 61 |
+
if layer.tags is not None:
|
| 62 |
+
layer_name[-1] = f"{layer.tags}-{layer_name[-1]}"
|
| 63 |
if isinstance(layer.source, int):
|
| 64 |
source = layer.source + (layer.source < 0) * idx
|
| 65 |
model_mat[source, idx] = True
|
|
|
|
| 68 |
source = source + (source < 0) * idx
|
| 69 |
model_mat[source, idx] = True
|
| 70 |
|
|
|
|
| 71 |
pattern_mat = []
|
| 72 |
+
if v7_base:
|
| 73 |
+
pattern_list = [("ELAN", 8, 3), ("ELAN", 8, 55), ("MP", 5, 11)]
|
| 74 |
+
for name, size, position in pattern_list:
|
| 75 |
+
pattern_mat.append(
|
| 76 |
+
(name, size, model_mat[position : position + size, position + 1 : position + 1 + size].copy())
|
| 77 |
+
)
|
| 78 |
|
| 79 |
dot = Digraph(comment="Model Flow Chart")
|
| 80 |
node_idx = 0
|
|
|
|
| 86 |
layer_name[idx] = name
|
| 87 |
model_mat[idx : idx + size, jdx : jdx + size] = False
|
| 88 |
model_mat[idx, idx + size] = True
|
| 89 |
+
dot.node(str(idx), f"{layer_name[idx]}")
|
| 90 |
+
node_idx += 1
|
|
|
|
|
|
|
| 91 |
for jdx in range(idx, model_size):
|
| 92 |
+
if model_mat[idx, jdx]:
|
| 93 |
dot.edge(str(idx), str(jdx))
|
| 94 |
|
| 95 |
dot.render("Model-arch", format="png", cleanup=True)
|