Skip to content

Instantly share code, notes, and snippets.

@belltailjp
Last active October 17, 2018 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belltailjp/924a6f88c5ccc122a4de964b447308b0 to your computer and use it in GitHub Desktop.
Save belltailjp/924a6f88c5ccc122a4de964b447308b0 to your computer and use it in GitHub Desktop.
chainer_computational_cost (used from a blog post in daily.belltail.jp)
import chainer
import chainer.links as L
import numpy as np
import chainer_computational_cost as c3
net = L.VGG16Layers()
x = np.random.random((1, 3, 224, 224)).astype(np.float32) # dummy input
with chainer.no_backprop_mode(), chainer.using_config('train', False):
with c3.ComputationalCostHook(fma_1flop=True) as cch:
y = net(x)
cch.show_summary_report(mode='table') # ←
+-----------------------+----------+--------+---------+----------+--------+
| Layer type | # Layers | GFLOPs | MemRead | MemWrite | MemR+W |
| | | | GiB | GiB | GiB |
+=======================+==========+========+=========+==========+========+
| Convolution2DFunction | 13 | 15.347 | 0.089 | 0.05 | 0.139 |
+-----------------------+----------+--------+---------+----------+--------+
| ReLU | 15 | 0.014 | 0.05 | 0.05 | 0.101 |
+-----------------------+----------+--------+---------+----------+--------+
| MaxPooling2D | 5 | 0.005 | 0.023 | 0.006 | 0.029 |
+-----------------------+----------+--------+---------+----------+--------+
| Reshape | 1 | 0.0 | 0.0 | 0.0 | 0.0 |
+-----------------------+----------+--------+---------+----------+--------+
| LinearFunction | 3 | 0.124 | 0.461 | 0.0 | 0.461 |
+-----------------------+----------+--------+---------+----------+--------+
| Softmax | 1 | 0.0 | 0.0 | 0.0 | 0.0 |
+-----------------------+----------+--------+---------+----------+--------+
| total | 38 | 15.488 | 0.623 | 0.107 | 0.729 |
+-----------------------+----------+--------+---------+----------+--------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment