TensorFlow 张量到 Pandas 数据帧 [英] TensorFlow tensor to Pandas dataframe

查看:45
本文介绍了TensorFlow 张量到 Pandas 数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型学习 W:

W = tf.Variable(tf.truncated_normal([pixels,h1],stddev=np.sqrt(2.0 / (pixels))))

我从运行我的 TF 图/会话的函数返回 W.

I return W from a function that runs my TF graph / session.

在我的笔记本中,我检查了 W 的类型:

In my notebook, I checked type of W:

type(W)
out: tensorflow.python.ops.variables.Variable

我还检查了 W 的维度:

I also checked dimensionality of W:

W.get_shape()
out: TensorShape([Dimension(3072), Dimension(1024)])

我想将 W 转换为 Pandas 数据帧(用于检查等).

I'd like to convert W into a Pandas dataframe (for examination, etc.).

我该怎么做?

(看到这个答案 使用 eval() 将张量转换为 numpy,然后当然可以将其写入熊猫.但该操作似乎只在 TF 会话中有效.)

(Saw this answer on converting tensor to numpy with eval(), which could then be written to pandas of course. But that operation only seemed to work within the TF session.)

推荐答案

变量只存在于一个会话中.它们在图中定义为操作,但实际上并不在图中存储任何值.它们只有在从图中创建会话时才具有值,并调用初始化操作(或调用加载).

variables only exist within a session. they are defined in the graph, as operations, but dont actually store any values as such, in the graph . they only have values when a session is created from the graph, and initialize operation called (or load is called).

当然,一旦您在会话中从变量中加载了值,使用 eval,您就可以自由地处理会话,并将生成的 numpy 张量 jsut 用作任何正常的 numpy 张量.

Of course, once you've loaded the value from the varaible, in a session, using eval, you're free to dispose of the session, and use the resulting numpy tensor jsut as any normal numpy tensor.

这篇关于TensorFlow 张量到 Pandas 数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆