Tensorflow元组具有不同的形状

时间:2017-03-28 09:41:58

标签: python tensorflow factorization

我在返回两个变量vwt的元组时遇到问题,其中vshape=(20,20)wtshape=(1,)wt是一个变量,是一个权重值。我想在map_fn

中返回元组(v,wt)

我的代码看起来有点接近这个

tf.map_fn(fn, nonzeros(Matrix, dim, row))

nonzeros(Matrix, dim, row) returns a (index, value)

fn将返回一个元组,但我得到的错误输出是:

ValueError: The two structures don't have the same number of elements. First 
structure: <dtype: 'int64'>, second structure: (<tf.Tensor 
'map_2/while/while/Exit_1:0' shape=(20,) dtype=float32>, <tf.Tensor 
'map_2/while/Sub:0' shape=() dtype=int64>).

1 个答案:

答案 0 :(得分:1)

您将在此处返回using (var decryptedStream = new MemoryStream (envelopedCms.ContentInfo.Content)) { var entity = MimeEntity.Load (decryptedStream); if (entity is ApplicationPkcs7Mime) { // Note: no need to create a new ApplicationPkcs7Mime part, just cast it! var p7m = (ApplicationPkcs7Mime) entity; using (var ctx = new TemporarySecureMimeContext ()) { // Import the X509Certificate2 into the S/MIME context var cert = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate (certificate); ctx.Import (cert); if (p7m.SecureMimeType == SecureMimeType.SignedData) { // Verify the content *and* extract the original content from the binary envelope MimeEntity extracted; var signatures = p7m.Verify (ctx, out extracted); // Save the Excel content to disk using (var stream = File.Create ("excel.xls")) { var part = extracted as MimePart; part.Content.DecodeTo (stream); } } } } } 循环的结果。 var categories = articles.selectMany(x => x.categoies).Distinct().Select(x => { var categoriziedArticles = articles.Where(z => z.cagories.Conains(x))); return new Category(categoriziedArticles); }); 循环返回多个值的元组,在您的情况下,我们可以看到您的while循环返回一个感兴趣的值和一个计数器值作为元组。

tf.while

你从tf.while传回的意思可能就是这两个值中的第一个。因此,在您未在此处显示的代码中,您应该具有以下内容:

(<tf.Tensor 'map_2/while/while/Exit_1:0' shape=(20,) dtype=float32>, <tf.Tensor 'map_2/while/Sub:0' shape=() dtype=int64>)

你拥有的是:

map_fn

因此,您看到的错误是抱怨value, counter = tf.while(...) return value 与您传入的return tf.while(...) 不符。修复while循环后,您将比较<dtype: 'int64'>tuple,大概是(20,)并且会匹配(尽管你最终会遇到int / float问题)。