File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -60,3 +60,36 @@ g = generateGraph(net, input)
60
60
graph .dot (g ,modelname .. ' _optimized' ,modelname .. ' _optimized' )
61
61
```
62
62
![ GoogleNet with memory optimization] ( doc/googlenet_optimized.gif )
63
+
64
+ ## Counting the amount of saved memory
65
+
66
+ We can also provide a function to compute the amount of memory used by the network
67
+ in bytes, which allows us to check the amount of saved memory. It currently
68
+ counts only the ` output ` fields of each module, and not it's internal buffers.
69
+
70
+ Here is an example
71
+
72
+ ``` lua
73
+ optnet = require ' optnet'
74
+ utils = require ' optnet.utils'
75
+ usedMemory = utils .usedMemory
76
+
77
+ models = require ' optnet.models'
78
+ modelname = ' googlenet'
79
+ net , input = models [modelname ]()
80
+
81
+ mem1 = usedMemory (net , input )
82
+
83
+ optnet .optimizeMemory (net , input )
84
+
85
+ mem2 = usedMemory (net , input )
86
+
87
+ optnet .removeOptimization (net )
88
+
89
+ mem3 = usedMemory (net , input )
90
+
91
+ print (' Before optimization : ' .. mem1 / 1024 / 1024 .. ' MBytes' )
92
+ print (' After optimization : ' .. mem2 / 1024 / 1024 .. ' MBytes' )
93
+ print (' After removing optimization: ' .. mem3 / 1024 / 1024 .. ' MBytes' )
94
+
95
+ ```
You can’t perform that action at this time.
0 commit comments