forked from rai-project/dlframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer_info.go
98 lines (85 loc) · 2.27 KB
/
layer_info.go
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
package cmd
import (
"fmt"
"os"
"path/filepath"
"sort"
"github.com/c3sr/dlframework/evaluation"
"github.com/spf13/cobra"
)
var layerInfoCmd = &cobra.Command{
Use: "info",
Aliases: []string{},
Short: "Get layer information from framework traces in a database",
PreRunE: func(cmd *cobra.Command, args []string) error {
if databaseName == "" {
databaseName = defaultDatabaseName["layer"]
}
err := rootSetup()
if err != nil {
return err
}
if modelName == "all" && outputFormat == "json" && outputFileName == "" {
outputFileName = filepath.Join(mlArcWebAssetsPath, "layers")
}
if overwrite && isExists(outputFileName) {
os.RemoveAll(outputFileName)
}
if plotPath == "" {
plotPath = evaluation.TempFile("", "layer_plot_*.html")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
run := func() error {
evals, err := getEvaluations()
if err != nil {
return err
}
summary0, err := evals.SummaryLayerInformations(performanceCollection)
if err != nil {
return err
}
summary1 := evaluation.SummaryLayerLatencyInformations(summary0)
if sortOutput {
sort.Slice(summary1, func(ii, jj int) bool {
return summary1[ii].Duration > summary1[jj].Duration
})
}
plotPath = outputFileName + "_latency_bar.html"
err = summary1.WriteBarPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
plotPath = outputFileName + "_latency_box.html"
err = summary1.WriteBoxPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
plotPath = outputFileName + "_allocated_memory.html"
summary2 := evaluation.SummaryLayerAllocatedMemoryInformations(summary0)
err = summary2.WriteBarPlot(plotPath)
if err != nil {
return err
}
fmt.Println("Created plot in " + plotPath)
if topLayers != -1 {
if topLayers >= len(summary0) {
topLayers = len(summary0)
}
summary0 = summary0[:topLayers]
}
writer := NewWriter(evaluation.SummaryMeanLayerInformation{})
defer writer.Close()
for _, v := range summary0 {
writer.Row(evaluation.SummaryMeanLayerInformation(v))
}
return nil
}
return forallmodels(run)
},
}
func init() {
}