import numpy as np
import tensorlayer as tl
x = np.asarray([['a','a'],['b','b'],['c','c'],['d','d'],['e','e'],['f','f']])
y = np.asarray([0,1,2,3,4,5])
# x与y的元素个数要相同,否则会报错
for xx, yy in tl.iterate.minibatches(inputs=x, targets=y,batch_size=2,shuffle=False):
print(xx, yy)
print('~~~~~~~~~~~~~~~')
# 下面两种输入法貎似也行
m = np.array([['a','a'],['b','b'],['c','c'],['d','d'],['e','e'],['f','f']])
n = np.array([0,1,2,3,4,5])
for mm, nn in tl.iterate.minibatches(inputs=m, targets=n,batch_size=2,shuffle=True):
print(mm, nn)
print('~~~~~~~~~~~~~~~')
f = [['a','a'],['b','b'],['c','c'],['d','d'],['e','e'],['f','f']]
t = [0,1,2,3,4,5]
for ff, tt in tl.iterate.minibatches(inputs=f, targets=t,batch_size=3,shuffle=False):
print(ff, tt)
上面2.6.1的例子很奇怪,试过np.array与直接 定义个列表好像也没什么影响~~,不一定要np.asarray~~情况如下:
[['a' 'a']
['b' 'b']] [0 1]
[['c' 'c']
['d' 'd']] [2 3]
[['e' 'e']
['f' 'f']] [4 5]
~~~~~~~~~~~~~~~
[['e' 'e']
['a' 'a']] [4 0]
[['c' 'c']
['b' 'b']] [2 1]
[['f' 'f']
['d' 'd']] [5 3]
~~~~~~~~~~~~~~~
[['a', 'a'], ['b', 'b'], ['c', 'c']] [0, 1, 2]
[['d', 'd'], ['e', 'e'], ['f', 'f']] [3, 4, 5]
[Finished in 4.3s]
下面是2.6.2的例子,还是很顺利的,就是要注意# tl.logging.set_verbosity(tl.logging.DEBUG)要注释掉,不然会报错,说是tensorlayer还没logging这个功能,另一个是network = tl.layers.DenseLayer(network, n_units=10, act=tf.identity, name='output')这行的act要定义个算法,