代码:
import numpy as np
import tensorflow as tf
from tensorflow.contrib.learn.python.learn.dataframe import tensorflow_dataframe as df
tf.logging.set_verbosity(tf.logging.INFO)
# Data sets
IRIS_TRAINING = "/home/huaxing.jinhx/data/iris/iris_training.csv"
IRIS_TEST = "/home/huaxing.jinhx/data/iris/iris_test.csv"
filepatterns = "/home/huaxing.jinhx/data/iris/iris*"
# Load datasets.
default_values = [0,0,0,0,0]
column_names = "x1 x2 x3 x4 y".split()
data_df = df.TensorFlowDataFrame()
data_df.from_csv(filepatterns,
default_values,
has_header=False,
column_names=column_names,
num_threads=1,
enqueue_size=None,
batch_size=10,
queue_capacity=None,
min_after_dequeue=None,
shuffle=False,
seed=None)
batch = data_df.run_one_epoch()
错误:
I tensorflow / core / common_runtime / gpu / gpu_device.cc:1041]正在创建 TensorFlow设备(/ gpu:0) - > (设备:0,名称:特斯拉K40m,pci总线 id:0000:81:00.0)Traceback(最近一次调用最后一次):文件 “/home/huaxing.jinhx/proj/tf_samples/read_csv.py”,第32行,in batch = data_df.run_one_batch()文件“/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/dataframe/tensorflow_dataframe.py”, 第263行,在run_one_batch中 返回列表(self.run(num_batches = 1))[0]文件“/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/dataframe/tensorflow_dataframe.py”, 第128行,在运行中 values = session.run(cols)文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”, 第717行,在运行中 run_metadata_ptr)文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py”, 第855行,在_run raise RuntimeError('会话图是空的。向'运行时错误添加操作:会话图是空的。添加操作到 调用run()之前的图形。
答案 0 :(得分:0)
from_csv()
是TensorFlowDataFrame
上的一种类方法,可为您提供新数据框。在这里,您在空数据框上执行run_one_epoch()
,这解释了错误。相反,请尝试这个:
data_df = df.TensorFlowDataFrame.from_csv(...)
batch = data_df.run_one_epoch()