- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用tensorflow parse_single_sequence_example来解码来自TFRecordReader的record_string。它返回两个字典,一个用于 context_features,另一个用于equence_features。
filename_queue = tf.train.string_input_producer('temp.text', num_epochs=1, shuffle=True)
reader = tf.TFRecordReader()
key, record_string = reader.read(filename_queue)
context_features={
"output":tf.FixedLenFeature([],tf.int64)
}
sequence_features={
"input_sequence":tf.FixedLenSequenceFeature([5,],tf.float32)
}
context_parsed, sequence_parsed = tf.parse_single_sequence_example(serialized=record_string,context_features=context_features,sequence_features=sequence_features)
context_parsed和sequence_parsed都是字典。如何获取与键关联的张量对象。如果我执行以下获取操作
with tf.Session() as sess:
a=sess.run([context_parsed],feed_dict=None)
它失败了,这是可以理解的。
Fetch argument {'output': <tf.Tensor 'ParseSingleSequenceExample/ParseSingleSequenceExample:1' shape=() dtype=int64>} of {'output': <tf.Tensor 'ParseSingleSequenceExample/ParseSingleSequenceExample:1' shape=() dtype=int64>} has invalid type <class 'dict'>, must be a string or Tensor. (Can not convert a dict into a Tensor or Operation.)
如何获取 context_parsed['output'] 张量?如何将该张量提供给图中的某个占位符?
out=context_parsed['output']
我添加上面的行并尝试获取它,但它不起作用,终端只是卡在 ipython 中。
with tf.Session() as sess:
a=sess.run(out,feed_dict=None)
我还添加了 tf.contrib.learn.run_n 的输出
In [13]: context = tf.contrib.learn.run_n(context_parsed, n=1, feed_dict=None)
In [14]: context[0]
Out[14]: {'length': 6, 'output': 4}
In [15]: context = tf.contrib.learn.run_n(out, n=1, feed_dict=None)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-e5d7d977676f> in <module>()
----> 1 个上下文 = tf.contrib.learn.run_n(out, n=1, feed_dict=None)
/home/ankgoyal/anaconda3/lib/python3.5/site- packages/tensorflow/contrib/learn/python/learn/graph_actions.py in run_n(output_dict, feed_dict, restore_checkpoint_path, n)
553 output_dict=output_dict,
554 feed_dicts=itertools.repeat(feed_dict, n),
--> 555 restore_checkpoint_path=restore_checkpoint_path)
556
557
/home/ankgoyal/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/graph_actions.py in run_feeds(output_dict, feed_dicts, restore_checkpoint_path)
579 ValueError: if `output_dict` or `feed_dicts` is None or empty.
580 """
--> 581 if not output_dict:
582 raise ValueError('output_dict is invalid: %s.' % output_dict)
583 if not feed_dicts:
/home/ankgoyal/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in __bool__(self)
513 `TypeError`.
514 """
--> 515 raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "
516 "Use `if t is not None:` instead of `if t:` to test if a "
517 "tensor is defined, and use the logical TensorFlow ops "
TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use the logical TensorFlow ops to test the value of a tensor.
如何获取 context_parsed['output'] 张量?如何将该张量提供给图表中的某个占位符?
最佳答案
我发现了我犯的错误。实际上,我没有为 TFReader() 启动新线程,因此终端挂起。
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
print(sess.run(context_parsed['length']))
coord.join(threads)
输出打印为 6
关于python - Tensorflow 运行时字典查找,处理 tf.parse_single_sequence_example 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42498040/
在 Tensorflow(从 v1.2.1 开始)中,似乎有(至少)两个并行 API 来构建计算图。 tf.nn 中有函数,如 conv2d、avg_pool、relu、dropout,tf.laye
我正在处理眼睛轨迹数据和卷积神经网络。我被要求使用 tf.reduce_max(lastconv, axis=2)代替 MaxPooling 层和 tf.reduce_sum(lastconv,axi
TensorFlow 提供了 3 种不同的数据存储格式 tf.train.Feature .它们是: tf.train.BytesList tf.train.FloatList tf.train.In
我正在尝试为上下文强盗问题 (https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part
我在使用 Tensorflow 时遇到问题: 以下代码为卷积 block 生成正确的图: def conv_layer(self, inputs, filter_size = 3, num_filte
我正在将我的训练循环迁移到 Tensorflow 2.0 API .在急切执行模式下,tf.GradientTape替换 tf.gradients .问题是,它们是否具有相同的功能?具体来说: 在函数
tensorflow 中 tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)) 的目的是什么? 更多上下文:
我一直在努力学习 TensorFlow,我注意到不同的函数用于相同的目标。例如,为了平方变量,我看到了 tf.square()、tf.math.square() 和 tf.keras.backend.
我正在尝试使用自动编码器开发图像着色器。有 13000 张训练图像。如果我使用 tf.data,每个 epoch 大约需要 45 分钟,如果我使用 tf.utils.keras.Sequence 大约
我尝试按照 tensorflow 教程实现 MNIST CNN 神经网络,并找到这些实现 softmax 交叉熵的方法给出了不同的结果: (1) 不好的结果 softmax = tf.nn.softm
其实,我正在coursera上做deeplearning.ai的作业“Art Generation with Neural Style Transfer”。在函数 compute_layer_styl
训练神经网络学习“异或” 我正在尝试使用“批量归一化”,我创建了一个批量归一化层函数“batch_norm1”。 import tensorflow as tf import nump
我正在尝试协调来自 TF“图形和 session ”指南以及 TF“Keras”指南和 TF Estimators 指南的信息。现在在前者中它说 tf.Session 使计算图能够访问物理硬件以执行图
我正在关注此处的多层感知器示例:https://github.com/aymericdamien/TensorFlow-Examples我对函数 tf.nn.softmax_cross_entropy
回到 TensorFlow = 2.0 中消失了。因此,像这样的解决方案...... with tf.variable_scope("foo"): with tf.variable_scope
我按照官方网站中的步骤安装了tensorflow。但是,在该网站中,作为安装的最后一步,他们给出了一行代码来“验证安装”。但他们没有告诉这段代码会给出什么输出。 该行是: python -c "imp
代码: x = tf.constant([1.,2.,3.], shape = (3,2,4)) y = tf.constant([1.,2.,3.], shape = (3,21,4)) tf.ma
我正在尝试从 Github 训练一个 3D 分割网络.我的模型是用 Keras (Python) 实现的,这是一个典型的 U-Net 模型。模型,总结如下, Model: "functional_3"
我正在使用 TensorFlow 2。我正在尝试优化一个函数,该函数使用经过训练的 tensorflow 模型(毒药)的损失。 @tf.function def totalloss(x): x
试图了解 keras 优化器中的 SGD 优化代码 (source code)。在 get_updates 模块中,我们有: # momentum shapes = [K.int_shape(p) f
我是一名优秀的程序员,十分优秀!