TensorFlowSharp是TensorFlow在c#平台上的包装器。 github
现在,我需要将形状为32,64,1的张量重塑为形状为1,2048的新张量,但当我引用正式API文档时,用法似乎如下:
TFOutput Reshape (TensorFlow.TFOutput tensor, TensorFlow.TFOutput shape);问题是,我不知道如何用TFOutput的方式表达我所需要的形状,任何建议都会被感激:)!
发布于 2017-08-18 22:27:31
在标准TensorFlowSharp中,有关如何执行此操作的示例可以通过以下方法提供:
tf.Reshape(x, tf.Const(shape));其中tf是当前TFSession中的默认TFGraph。
或者,如果您使用Keras,您可能可以使用
using (var K = new TensorFlowBackend())
{
double[,] input_array = new double[,] { { 1, 2 }, { 3, 4 } };
Tensor variable = K.variable(array: input_array);
Tensor variable_new_shape = K.reshape(variable, new int[] { 1, 4 });
double[,] output = (double[,])variable_new_shape.eval();
Assert.AreEqual(new double[,] { { 1, 2, 3, 4 } }, output);
}https://stackoverflow.com/questions/45753153
复制相似问题