python-3.x - Tensorflow:使用序列设置数组元素

标签 python-3.x machine-learning tensorflow

我正在尝试使用自己的图像数据集训练 CNN,但是当将批处理数据和标签传递到 feed_dict 时,我收到错误 ValueError: seting an array element with a我读到的序列 here ,这是一个维度问题,可能来 self 的 batch_label 张量,但我无法弄清楚如何使其成为一个单热张量(我的图表所期望的)。

我在这里上传了完整的代码作为要点:https://gist.github.com/guivn/f7f753547f77a3b12992

最佳答案

TL;DR:您无法提供 tf.Tensor 对象(即 batch_databatch_labels) > 在 gist 中)作为另一个张量的值。 (我相信在最新版本的 TensorFlow 中,错误消息应该更清楚。)

遗憾的是,您目前无法使用 feed/tf.placeholder() 机制将一个 TensorFlow 图的结果传递给另一个图。我们正在研究如何使这变得更容易,因为这是一个常见的混淆和功能请求。然而,对于您的确切程序来说,解决这个问题应该很容易。只需移动 lines创建输入并用它们替换占位符。您的程序将如下所示:

with graph.as_default():

  # Input data.
  filename_and_label_tensor = tf.train.string_input_producer(['train.txt'], shuffle=True)
  data, label = parse_csv(filename_and_label_tensor)
  tf_train_dataset, tf_train_labels = tf.train.batch([data, label], batch_size, num_threads=4)

  # Rest of the model construction goes here....

通常,如果您想通过同一模型传递另一个数据集,例如用于评估 - 最简单的方法是制作图表的另一个副本(可能共享相同的 tf.Variable 对象)。

关于python-3.x - Tensorflow:使用序列设置数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36230853/

相关文章:

python - 如何获取 scikit-learn SVM 分类器的所有 alpha 值?

python - 将onnx模型转换为keras

python - TensorFlow 1.12.0 安装不可见

python - pytorch 中的 tf.cast 等价物?

python - 如何使用来自 Google AutoML Vision Classification 的 TensorFlow Frozen GraphDef(单个 saving_model.pb)进行推理和迁移学习

python - 在后台打开网络浏览器

python-3.x - 模块未找到错误 : No module named 'openpyxl' in python 3. 6

python - 使用 Tensorflow 调用 copy.deepcopy(network) 时出现 "ValueError: Unknown layer: ... "

c++ - 在 C++ 库和 Python 之间发送字符串

machine-learning - 查找连续目标变量的 'Best' 截止点的方法