-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_visual.py
105 lines (68 loc) · 2.53 KB
/
model_visual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import torch
from mmengine import Config
from functools import partial
import os
# if you want
from mmrotate.registry import MODELS
from mmrotate.utils import register_all_modules
register_all_modules()
from mmdet.registry import MODELS
from mmdet.utils import register_all_modules
register_all_modules()
from mmyolo.utils import register_all_modules
register_all_modules()
from mmengine.runner import Runner
import graphviz
from torchview import draw_graph
from torchinfo import summary
# graphviz.set_jupyter_format('svg')
# graphviz.set_default_engine('')
graphviz.set_default_format('svg')
import pandas as pd
def draw_model(config, filename):
cfg = Config.fromfile(config)
dataloader = Runner.build_dataloader(cfg.val_dataloader)
for idx, data_batch in enumerate(dataloader):
# print(idx, data_batch)
break
model = MODELS.build(cfg.model)
_forward = model.forward
data = model.data_preprocessor(data_batch)
model.forward = partial(_forward, data_samples=data['data_samples'])
# summary(model, data['inputs'].shape, depth=3)
# summary(model, (1, 3, 1024, 1024), depth=3)
model_graph = draw_graph(model, input_size=data['inputs'].shape)
model_graph.visual_graph
model_graph.visual_graph.render(filename=filename, view=False, cleanup=True)
result_configs = []
if __name__ == '__main__':
# prefix = 'mmdetection/configs/'
prefix = '../mmyolo/configs/'
algorithms = os.listdir(prefix)
configs_list = []
for algorithm in algorithms:
configs = os.listdir(prefix + algorithm)
if 'metafile.yml' in configs:
for config in configs:
if config.endswith('.py'):
configs_list.append(prefix + algorithm + '/' + config)
# print(configs_list)
for i, config in enumerate(configs_list):
print(i, config, configs_list.__len__())
result_dict = dict()
result_dict['config'] = config
try:
# draw_model(config, config.replace('mmyolo', 'model_visual'))
draw_model(config, config.replace('mmyolo', 'model_visual/mmyolo'))
result_dict['result'] = 'PASS'
print('PASS')
except Exception as e:
result_dict['result'] = 'FAIL'
result_dict['error'] = str(e)
print(e)
print('FAIL')
# print(config)
result_configs.append(result_dict)
pd.DataFrame(result_configs).to_csv('result.csv')