projects
/
pytorch.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
10f39c3
)
Added an error if named_parameters is called before the first forward()
author
Francois Fleuret
<francois@fleuret.org>
Wed, 13 Jun 2018 19:14:35 +0000
(21:14 +0200)
committer
Francois Fleuret
<francois@fleuret.org>
Wed, 13 Jun 2018 19:14:35 +0000
(21:14 +0200)
lazy_linear.py
patch
|
blob
|
history
diff --git
a/lazy_linear.py
b/lazy_linear.py
index
4599f00
..
b3d3165
100755
(executable)
--- a/
lazy_linear.py
+++ b/
lazy_linear.py
@@
-23,16
+23,25
@@
class LazyLinear(nn.Module):
return self.core(x)
return self.core(x)
+ def named_parameters(self, memo=None, prefix=''):
+ assert self.core is not None, 'Parameters not yet defined'
+ return super(LazyLinear, self).named_parameters(memo, prefix)
+
######################################################################
######################################################################
-model = nn.Sequential(nn.Conv2d(1, 8, kernel_size = 5),
- nn.ReLU(inplace = True),
- LazyLinear(128),
- nn.ReLU(inplace = True),
- nn.Linear(128, 10))
+if __name__ == "__main__":
+ model = nn.Sequential(nn.Conv2d(3, 8, kernel_size = 5),
+ nn.ReLU(inplace = True),
+ LazyLinear(128),
+ nn.ReLU(inplace = True),
+ nn.Linear(128, 10))
+
+ # model.eval()
+
+ input = Tensor(100, 3, 32, 32).normal_()
-
# model.eval(
)
+
output = model(input
)
-input = Tensor(100, 1, 32, 32).normal_()
+ for n, x in model.named_parameters():
+ print(n, x.size())
-output = model(input)