Skip to content

Commit b2bc469

Browse files
committed
update to 7.0.1
1 parent bbaf5c3 commit b2bc469

17 files changed

+7
-479
lines changed

examples/charcnn_text_classifier.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
11

22
import tensorflow as tf
3-
<<<<<<< HEAD
43
import tensorgraph as tg
54
from tensorgraph.layers import Reshape, Embedding, Conv2D, RELU, Linear, Flatten, ReduceSum, Softmax
65
from nltk.tokenize import RegexpTokenizer
76
from nlpbox import CharNumberEncoder, CatNumberEncoder
87
from tensorgraph.utils import valid, split_df, make_one_hot
98
from tensorgraph.cost import entropy, accuracy
10-
=======
11-
import tensorgraphx as tg
12-
from tensorgraphx.layers import Reshape, Embedding, Conv2D, RELU, Linear, Flatten, ReduceSum, Softmax
13-
from nltk.tokenize import RegexpTokenizer
14-
from nlpbox import CharNumberEncoder, CatNumberEncoder
15-
from tensorgraphx.utils import valid, split_df, make_one_hot
16-
from tensorgraphx.cost import entropy, accuracy
17-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
189
import pandas
1910
import numpy as np
2011

2112
# character CNN
2213
def model(word_len, sent_len, nclass):
2314
unicode_size = 1000
2415
ch_embed_dim = 20
25-
26-
<<<<<<< HEAD
27-
=======
28-
h, w = valid(ch_embed_dim, word_len, stride=(1,1), kernel_size=(ch_embed_dim,5))
29-
h, w = valid(h, w, stride=(1,1), kernel_size=(1,5))
30-
h, w = valid(h, w, stride=(1,2), kernel_size=(1,5))
31-
conv_out_dim = int(h * w * 60)
32-
33-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
3416
X_ph = tf.placeholder('int32', [None, sent_len, word_len])
3517
input_sn = tg.StartNode(input_vars=[X_ph])
3618
charcnn_hn = tg.HiddenNode(prev=[input_sn],
@@ -39,7 +21,6 @@ def model(word_len, sent_len, nclass):
3921
encode_dim=ch_embed_dim,
4022
zero_pad=True),
4123
Reshape(shape=(-1, ch_embed_dim, word_len, 1)),
42-
<<<<<<< HEAD
4324
Conv2D(num_filters=20, padding='VALID',
4425
kernel_size=(ch_embed_dim,5), stride=(1,1)),
4526
RELU(),
@@ -51,19 +32,6 @@ def model(word_len, sent_len, nclass):
5132
RELU(),
5233
Flatten(),
5334
Linear(nclass),
54-
=======
55-
Conv2D(input_channels=1, num_filters=20, padding='VALID',
56-
kernel_size=(ch_embed_dim,5), stride=(1,1)),
57-
RELU(),
58-
Conv2D(input_channels=20, num_filters=40, padding='VALID',
59-
kernel_size=(1,5), stride=(1,1)),
60-
RELU(),
61-
Conv2D(input_channels=40, num_filters=60, padding='VALID',
62-
kernel_size=(1,5), stride=(1,2)),
63-
RELU(),
64-
Flatten(),
65-
Linear(conv_out_dim, nclass),
66-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
6735
Reshape((-1, sent_len, nclass)),
6836
ReduceSum(1),
6937
Softmax()
@@ -101,11 +69,7 @@ def tweets(word_len, sent_len, train_valid_ratio=[5,1]):
10169

10270

10371
def train():
104-
<<<<<<< HEAD
10572
from tensorgraph.trainobject import train as mytrain
106-
=======
107-
from tensorgraphx.trainobject import train as mytrain
108-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
10973
with tf.Session() as sess:
11074
word_len = 20
11175
sent_len = 50

examples/cifar10_allcnn.py

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from __future__ import division, print_function, absolute_import
99

10-
<<<<<<< HEAD
1110
from tensorgraph.layers import Conv2D, RELU, MaxPooling, LRN, Tanh, Dropout, \
1211
Softmax, Flatten, Linear, AvgPooling, \
1312
Lambda, BatchNormalization, IdentityBlock, \
@@ -17,25 +16,13 @@
1716
import tensorflow as tf
1817
from tensorgraph.cost import entropy, accuracy, mse
1918
from tensorgraph.dataset import Mnist, Cifar10
20-
=======
21-
from tensorgraphx.layers import Conv2D, RELU, MaxPooling, LRN, Tanh, Dropout, \
22-
Softmax, Flatten, Linear, AvgPooling, \
23-
Lambda, BatchNormalization, IdentityBlock, \
24-
TransitionLayer, DenseNet
25-
from tensorgraphx.utils import same, valid, same_nd, valid_nd
26-
import tensorgraphx as tg
27-
import tensorflow as tf
28-
from tensorgraphx.cost import entropy, accuracy, mse
29-
from tensorgraphx.dataset import Mnist, Cifar10
30-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
3119
from tensorflow.python.framework import ops
3220
import numpy as np
3321

3422

3523
def model(nclass, h, w, c):
3624
with tf.name_scope('Cifar10AllCNN'):
3725
seq = tg.Sequential()
38-
<<<<<<< HEAD
3926
seq.add(Conv2D(num_filters=96, kernel_size=(3, 3), stride=(1, 1), padding='SAME'))
4027
seq.add(RELU())
4128
seq.add(BatchNormalization())
@@ -73,54 +60,6 @@ def model(nclass, h, w, c):
7360
seq.add(BatchNormalization())
7461

7562
seq.add(AvgPooling(poolsize=(8, 8), stride=(1,1), padding='VALID'))
76-
=======
77-
seq.add(Conv2D(input_channels=c, num_filters=96, kernel_size=(3, 3), stride=(1, 1), padding='SAME'))
78-
seq.add(RELU())
79-
h, w = same(in_height=h, in_width=w, stride=(1,1), kernel_size=(3,3))
80-
seq.add(BatchNormalization(input_shape=[h,w,96]))
81-
82-
seq.add(Conv2D(input_channels=96, num_filters=96, kernel_size=(3, 3), stride=(1, 1), padding='SAME'))
83-
seq.add(RELU())
84-
h, w = same(in_height=h, in_width=w, stride=(1,1), kernel_size=(3,3))
85-
seq.add(Dropout(0.5))
86-
87-
seq.add(Conv2D(input_channels=96, num_filters=96, kernel_size=(3, 3), stride=(2, 2), padding='SAME'))
88-
seq.add(RELU())
89-
h, w = same(in_height=h, in_width=w, stride=(2,2), kernel_size=(3,3))
90-
seq.add(BatchNormalization(input_shape=[h,w,96]))
91-
92-
seq.add(Conv2D(input_channels=96, num_filters=192, kernel_size=(3, 3), stride=(1, 1), padding='SAME'))
93-
seq.add(RELU())
94-
h, w = same(in_height=h, in_width=w, stride=(1,1), kernel_size=(3,3))
95-
seq.add(Dropout(0.5))
96-
97-
seq.add(Conv2D(input_channels=192, num_filters=192, kernel_size=(3, 3), stride=(1, 1), padding='SAME'))
98-
seq.add(RELU())
99-
h, w = same(in_height=h, in_width=w, stride=(1,1), kernel_size=(3,3))
100-
seq.add(BatchNormalization(input_shape=[h,w,192]))
101-
102-
seq.add(Conv2D(input_channels=192, num_filters=192, kernel_size=(3, 3), stride=(2, 2), padding='SAME'))
103-
seq.add(RELU())
104-
h, w = same(in_height=h, in_width=w, stride=(2,2), kernel_size=(3,3))
105-
seq.add(Dropout(0.5))
106-
107-
seq.add(Conv2D(input_channels=192, num_filters=192, kernel_size=(3, 3), stride=(1, 1), padding='SAME'))
108-
seq.add(RELU())
109-
h, w = same(in_height=h, in_width=w, stride=(1,1), kernel_size=(3,3))
110-
seq.add(BatchNormalization(input_shape=[h,w,192]))
111-
112-
seq.add(Conv2D(input_channels=192, num_filters=192, kernel_size=(1, 1), stride=(1, 1), padding='SAME'))
113-
seq.add(RELU())
114-
h, w = same(in_height=h, in_width=w, stride=(1,1), kernel_size=(1,1))
115-
seq.add(Dropout(0.5))
116-
117-
seq.add(Conv2D(input_channels=192, num_filters=nclass, kernel_size=(1, 1), stride=(1, 1), padding='SAME'))
118-
seq.add(RELU())
119-
h, w = same(in_height=h, in_width=w, stride=(1,1), kernel_size=(1,1))
120-
seq.add(BatchNormalization(input_shape=[h,w,nclass]))
121-
122-
seq.add(AvgPooling(poolsize=(h, w), stride=(1,1), padding='VALID'))
123-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
12463
seq.add(Flatten())
12564
seq.add(Softmax())
12665
return seq
@@ -210,11 +149,7 @@ def train():
210149

211150

212151
def train_with_trainobject():
213-
<<<<<<< HEAD
214152
from tensorgraph.trainobject import train as mytrain
215-
=======
216-
from tensorgraphx.trainobject import train as mytrain
217-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
218153
config = tf.ConfigProto()
219154
config.gpu_options.allow_growth = True
220155
with tf.Session(config = config) as sess:
@@ -243,11 +178,7 @@ def train_with_trainobject():
243178

244179

245180
def train_with_VGG():
246-
<<<<<<< HEAD
247181
from tensorgraph.trainobject import train as mytrain
248-
=======
249-
from tensorgraphx.trainobject import train as mytrain
250-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
251182
config = tf.ConfigProto()
252183
config.gpu_options.allow_growth = True
253184
with tf.Session(config = config) as sess:
@@ -256,21 +187,12 @@ def train_with_VGG():
256187
_, nclass = y_train.shape
257188
print('X max', np.max(X_train))
258189
print('X min', np.min(X_train))
259-
<<<<<<< HEAD
260190
from tensorgraph.layers import VGG19
261191
seq = tg.Sequential()
262192
layer = VGG19()
263193
seq.add(layer)
264194
seq.add(Flatten())
265195
seq.add(Linear(nclass))
266-
=======
267-
from tensorgraphx.layers import VGG19
268-
seq = tg.Sequential()
269-
layer = VGG19(input_channels=c, input_shape=(h,w))
270-
seq.add(layer)
271-
seq.add(Flatten())
272-
seq.add(Linear(512,nclass))
273-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
274196
seq.add(Softmax())
275197
X_ph = tf.placeholder('float32', [None, h, w, c])
276198
y_ph = tf.placeholder('float32', [None, nclass])
@@ -292,11 +214,7 @@ def train_with_VGG():
292214

293215

294216
def train_with_Resnet():
295-
<<<<<<< HEAD
296217
from tensorgraph.trainobject import train as mytrain
297-
=======
298-
from tensorgraphx.trainobject import train as mytrain
299-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
300218
config = tf.ConfigProto()
301219
config.gpu_options.allow_growth = True
302220
with tf.Session(config = config) as sess:
@@ -306,28 +224,12 @@ def train_with_Resnet():
306224
print('X max', np.max(X_train))
307225
print('X min', np.min(X_train))
308226
seq = tg.Sequential()
309-
<<<<<<< HEAD
310227
seq.add(IdentityBlock(nlayers=4, filters=[32, 64]))
311228
seq.add(TransitionLayer(16))
312229
seq.add(IdentityBlock(nlayers=4, filters=[64, 128]))
313230
seq.add(TransitionLayer(16))
314231
seq.add(Flatten())
315232
seq.add(Linear(nclass))
316-
=======
317-
id1 = IdentityBlock(input_channels=c, input_shape=(h,w), nlayers=4, filters=[32, 64])
318-
seq.add(id1)
319-
trans1 = TransitionLayer(input_channels=id1.output_channels, input_shape=id1.output_shape)
320-
seq.add(trans1)
321-
322-
id2 = IdentityBlock(input_channels=trans1.output_channels, input_shape=trans1.output_shape,
323-
nlayers=4, filters=[64, 128])
324-
seq.add(id2)
325-
trans2 = TransitionLayer(input_channels=id2.output_channels, input_shape=id2.output_shape)
326-
seq.add(trans2)
327-
seq.add(Flatten())
328-
ldim = trans2.output_channels * np.prod(trans2.output_shape)
329-
seq.add(Linear(ldim,nclass))
330-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
331233
seq.add(Softmax())
332234

333235
X_ph = tf.placeholder('float32', [None, h, w, c])
@@ -350,11 +252,7 @@ def train_with_Resnet():
350252

351253

352254
def train_with_Densenet():
353-
<<<<<<< HEAD
354255
from tensorgraph.trainobject import train as mytrain
355-
=======
356-
from tensorgraphx.trainobject import train as mytrain
357-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
358256
config = tf.ConfigProto()
359257
config.gpu_options.allow_growth = True
360258
with tf.Session(config = config) as sess:
@@ -364,17 +262,9 @@ def train_with_Densenet():
364262
print('X max', np.max(X_train))
365263
print('X min', np.min(X_train))
366264
seq = tg.Sequential()
367-
<<<<<<< HEAD
368265
seq.add(DenseNet(ndense=3, growth_rate=4, nlayer1blk=4))
369266
seq.add(Flatten())
370267
seq.add(Linear(nclass))
371-
=======
372-
dense = DenseNet(input_channels=c, input_shape=(h,w), ndense=3, growth_rate=4, nlayer1blk=4)
373-
seq.add(dense)
374-
seq.add(Flatten())
375-
ldim = dense.output_channels
376-
seq.add(Linear(ldim,nclass))
377-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
378268
seq.add(Softmax())
379269

380270
X_ph = tf.placeholder('float32', [None, h, w, c])

examples/example.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11

22
import tensorflow as tf
33
import numpy as np
4-
<<<<<<< HEAD
54
from tensorgraph import Graph, StartNode, HiddenNode, EndNode
65
from tensorgraph.layers import Linear, RELU, Concat, Mean, Sum
76
from tensorgraph import ProgressBar, SequentialIterator
8-
=======
9-
from tensorgraphx import Graph, StartNode, HiddenNode, EndNode
10-
from tensorgraphx.layers import Linear, RELU, Concat, Mean, Sum
11-
from tensorgraphx import ProgressBar, SequentialIterator
12-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
137

148

159
def model():
@@ -25,21 +19,12 @@ def model():
2519

2620
h1 = HiddenNode(prev=[start1, start2],
2721
input_merge_mode=Concat(),
28-
<<<<<<< HEAD
2922
layers=[Linear(y2_dim), RELU()])
3023
h2 = HiddenNode(prev=[start2],
3124
layers=[Linear(y2_dim), RELU()])
3225
h3 = HiddenNode(prev=[h1, h2],
3326
input_merge_mode=Sum(),
3427
layers=[Linear(y1_dim), RELU()])
35-
=======
36-
layers=[Linear(y1_dim+y2_dim, y2_dim), RELU()])
37-
h2 = HiddenNode(prev=[start2],
38-
layers=[Linear(y2_dim, y2_dim), RELU()])
39-
h3 = HiddenNode(prev=[h1, h2],
40-
input_merge_mode=Sum(),
41-
layers=[Linear(y2_dim, y1_dim), RELU()])
42-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
4328
e1 = EndNode(prev=[h3])
4429
e2 = EndNode(prev=[h2])
4530

@@ -74,11 +59,7 @@ def train():
7459
n_exp += len(y1_batch)
7560
pbar.update(n_exp)
7661
print('end')
77-
<<<<<<< HEAD
7862
# saver.save(sess, 'test.tf')
79-
=======
80-
saver.save(sess, 'test.tf')
81-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
8263

8364

8465
if __name__ == '__main__':

examples/hierachical_softmax.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
<<<<<<< HEAD
32
from tensorgraph.node import StartNode, HiddenNode, EndNode
43
import tensorflow as tf
54
from tensorgraph.layers.linear import Linear
@@ -8,16 +7,7 @@
87
from tensorgraph.graph import Graph
98
import numpy as np
109
from tensorgraph.data_iterator import SequentialIterator
11-
=======
12-
from tensorgraphx.node import StartNode, HiddenNode, EndNode
13-
import tensorflow as tf
14-
from tensorgraphx.layers.linear import Linear
15-
from tensorgraphx.layers.activation import RELU, Softmax
16-
from tensorgraphx.layers.merge import Concat, Mean, Sum
17-
from tensorgraphx.graph import Graph
18-
import numpy as np
19-
from tensorgraphx.data_iterator import SequentialIterator
20-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
10+
2111

2212
## params
2313
x_dim = 50
@@ -35,15 +25,9 @@
3525
# define the graph model structure
3626
start = StartNode(input_vars=[x_ph])
3727

38-
<<<<<<< HEAD
3928
h1 = HiddenNode(prev=[start], layers=[Linear(component_dim), Softmax()])
4029
h2 = HiddenNode(prev=[h1], layers=[Linear(component_dim), Softmax()])
4130
h3 = HiddenNode(prev=[h2], layers=[Linear(component_dim), Softmax()])
42-
=======
43-
h1 = HiddenNode(prev=[start], layers=[Linear(x_dim, component_dim), Softmax()])
44-
h2 = HiddenNode(prev=[h1], layers=[Linear(component_dim, component_dim), Softmax()])
45-
h3 = HiddenNode(prev=[h2], layers=[Linear(component_dim, component_dim), Softmax()])
46-
>>>>>>> e55a706e1467da7b7c54b6d04055aba847f5a2b5
4731

4832

4933
e1 = EndNode(prev=[h1], input_merge_mode=Sum())

0 commit comments

Comments
 (0)