Skip to content

Commit 81e6c21

Browse files
committed
add tutorial LayerList
1 parent 339fb03 commit 81e6c21

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
from tensorlayer.layers import Module, LayerList, Dense
5+
import tensorlayer as tl
6+
7+
d1 = Dense(n_units=800, act=tl.ReLU, in_channels=784, name='Dense1')
8+
d2 = Dense(n_units=800, act=tl.ReLU, in_channels=800, name='Dense2')
9+
d3 = Dense(n_units=10, act=tl.ReLU, in_channels=800, name='Dense3')
10+
11+
layer_list = LayerList([d1, d2])
12+
# Inserts a given d2 before a given index in the list
13+
layer_list.insert(1, d2)
14+
layer_list.insert(2, d2)
15+
# Appends d2 from a Python iterable to the end of the list.
16+
layer_list.extend([d2])
17+
# Appends a given d3 to the end of the list.
18+
layer_list.append(d3)
19+
20+
print(layer_list)
21+
22+
class model(Module):
23+
def __init__(self):
24+
super(model, self).__init__()
25+
self._list = layer_list
26+
def forward(self, inputs):
27+
output = self._list[0](inputs)
28+
for i in range(1, len(self._list)):
29+
output = self._list[i](output)
30+
return output
31+
32+
net = model()
33+
print(net)
34+
print(net(tl.layers.Input((10, 784))))

tensorlayer/layers/core/core_tensorflow.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,9 @@ class LayerList(Module):
678678
Examples:
679679
680680
"""
681-
def __init__(self, *args, **kwargs):
681+
def __init__(self, args):
682682
super(LayerList, self).__init__()
683-
if len(args) == 1:
684-
self.extend(args[0])
683+
self.extend(args)
685684

686685
def __getitem__(self, index):
687686
if isinstance(index, slice):

0 commit comments

Comments
 (0)