在SKFlow中正确使用Tensorflow tf.split函数
Skflow文档中有一个RNN的最小示例。输入数据是形状为(4,5)的矩阵。为什么要根据以下输入函数拆分数据在SKFlow中正确使用Tensorflow tf.split函数,tensorflow,skflow,Tensorflow,Skflow,Skflow文档中有一个RNN的最小示例。输入数据是形状为(4,5)的矩阵。为什么要根据以下输入函数拆分数据 def input_fn(X): return tf.split(1, 5, X) 此函数返回5个形状为4,1的数组的列表 [array([[ 2.], [ 2.], [ 3.], [ 2.]], dtype=float32), array([[ 1.], [ 2.], [ 3.], [ 4.]
def input_fn(X):
return tf.split(1, 5, X)
此函数返回5个形状为4,1的数组的列表
[array([[ 2.],
[ 2.],
[ 3.],
[ 2.]], dtype=float32), array([[ 1.],
[ 2.],
[ 3.],
[ 4.]], dtype=float32), array([[ 2.],
[ 3.],
[ 1.],
[ 5.]], dtype=float32), array([[ 2.],
[ 4.],
[ 2.],
[ 4.]], dtype=float32), array([[ 3.],
[ 5.],
[ 1.],
[ 1.]], dtype=f
而且,上述功能或定义这样的功能对RNN有什么区别/影响?当两个输入函数都运行时
def input_fn(X):
return tf.split(1, 1, X)
返回以下内容:
[[[ 1., 3., 3., 2., 1.],
[ 2., 3., 4., 5., 6.]]
在此介绍:
testRNN(self):
random.seed(42)
import numpy as np
data = np.array(list([[2, 1, 2, 2, 3],
[2, 2, 3, 4, 5],
[3, 3, 1, 2, 1],
[2, 4, 5, 4, 1]]), dtype=np.float32)
# labels for classification
labels = np.array(list([1, 0, 1, 0]), dtype=np.float32)
# targets for regression
targets = np.array(list([10, 16, 10, 16]), dtype=np.float32)
test_data = np.array(list([[1, 3, 3, 2, 1], [2, 3, 4, 5, 6]]))
def input_fn(X):
return tf.split(1, 5, X)
# Classification
classifier = skflow.TensorFlowRNNClassifier(
rnn_size=2, cell_type='lstm', n_classes=2, input_op_fn=input_fn)
classifier.fit(data, labels)
classifier.weights_
classifier.bias_
predictions = classifier.predict(test_data)
self.assertAllClose(predictions, np.array([1, 0]))