什么是tf.constant和tf.convert_to_tensor

时间:2018-05-01 00:38:50

标签: python tensorflow

tf.to_float(tf.convert_to_tensor(python_object))在Tensorflow对象检测api中多次使用grid_anchor_generator。我会使用tf.constant(python_object, dtype=tf.float32)。我想知道它们之间的区别。感谢

1 个答案:

答案 0 :(得分:6)

对于tf.convert_to_tensor,输入值必须是静态非张量类型。例如一个numpy数组。

对于getNews(stocks: string, daysBack: number) { this.newsItems = []; const securityArray = stocks.split(','); this.recordsProcessed = 0; this.recordCount = securityArray.length; this.securityService.progressStart.next(0); this.securityService.progressFinish.next(this.recordCount); this.showRecs = false; for (let i = 0; i < securityArray.length; i++) { const stk = securityArray[i]; this.securityService.getNews(securityArray[i]).takeUntil(this.ngUnsubscribe).subscribe(n => { try { for (let x = 0; x < n.rss.channel.item.length; x++) { const iDate = new Date(new Date().setDate(new Date().getDate() - daysBack)); iDate.setHours(0, 0, 0, 0); const pDate = new Date(n.rss.channel.item[x].pubDate); if (pDate >= iDate) { const newsItem = new NewsItem( stk, decodeURI(n.rss.channel.item[x].description), n.rss.channel.item[x].guid, n.rss.channel.item[x].link, decodeURI(n.rss.channel.item[x].title), pDate ); this.newsItems.push(newsItem); } } this.recordsProcessed++; this.securityService.progressStart.next(this.recordsProcessed); if (this.recordCount === this.recordsProcessed) { this.showRecs = true; } } catch (e) { console.log(e); this.recordsProcessed++; this.securityService.progressStart.next(this.recordsProcessed); if (this.recordCount === this.recordsProcessed) { this.showRecs = true; } } }, error => { console.log('Error', error); this.recordsProcessed++; this.securityService.progressStart.next(this.recordsProcessed); }); } } ,值&#34;一个对象,其类型具有注册的Tensor转换函数。&#34;这意味着输入类型如Tensors或tf.Variables也可以作为输入提供。例如,请在此处查看变量的张量转换函数:https://github.com/tensorflow/tensorflow/blob/r1.8/tensorflow/python/ops/variables.py#L762