Skip to content
Snippets Groups Projects
Commit 3c3bc831 authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Notebook] start sketching Brevitas import notebook

parent 4cbaa924
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Importing Brevitas networks into FINN
%% Cell type:code id: tags:
``` python
import inspect
def showSrc(what):
print("".join(inspect.getsourcelines(what)[0]))
```
%% Cell type:code id: tags:
``` python
from models.LFC import LFC
showSrc(LFC)
```
%% Output
class LFC(Module):
def __init__(self, num_classes=10, weight_bit_width=None, act_bit_width=None,
in_bit_width=None, in_ch=1, in_features=(28, 28)):
super(LFC, self).__init__()
weight_quant_type = get_quant_type(weight_bit_width)
act_quant_type = get_quant_type(act_bit_width)
in_quant_type = get_quant_type(in_bit_width)
stats_op = get_stats_op(weight_quant_type)
self.features = ModuleList()
self.features.append(get_act_quant(in_bit_width, in_quant_type))
self.features.append(Dropout(p=IN_DROPOUT))
in_features = reduce(mul, in_features)
for out_features in FC_OUT_FEATURES:
self.features.append(get_quant_linear(in_features=in_features,
out_features=out_features,
per_out_ch_scaling=INTERMEDIATE_FC_PER_OUT_CH_SCALING,
bit_width=weight_bit_width,
quant_type=weight_quant_type,
stats_op=stats_op))
in_features = out_features
self.features.append(BatchNorm1d(num_features=in_features))
self.features.append(get_act_quant(act_bit_width, act_quant_type))
self.features.append(Dropout(p=HIDDEN_DROPOUT))
self.fc = get_quant_linear(in_features=in_features,
out_features=num_classes,
per_out_ch_scaling=LAST_FC_PER_OUT_CH_SCALING,
bit_width=weight_bit_width,
quant_type=weight_quant_type,
stats_op=stats_op)
def forward(self, x):
x = x.view(x.shape[0], -1)
x = 2.0 * x - torch.tensor([1.0])
for mod in self.features:
x = mod(x)
out = self.fc(x)
return out
%% Cell type:code id: tags:
``` python
!pip install --user netron
```
%% Output
Requirement already satisfied: netron in /opt/conda/lib/python3.6/site-packages (3.5.9)
%% Cell type:code id: tags:
``` python
import netron
netron.start('LFCW1A1.onnx', port=8081, host="0.0.0.0")
```
%% Output
Serving 'LFCW1A1.onnx' at http://0.0.0.0:8081
%% Cell type:code id: tags:
``` python
%%html
<iframe src="http://0.0.0.0:8081/" style="position: relative; width: 100%;" height="400"></iframe>
```
%% Output
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment