【发布时间】:2018-12-02 19:26:31
【问题描述】:
张量流的第一步,我正在尝试训练一个用于图像分类的 DNN 模型。
我当前的代码是:
folder_path = Path('cropped_images/cropped')
df['filename'] = df['tag_id'].map(lambda tag: str(folder_path / (tag + '.png')))
def database_input_fn():
def parse_image(filename, label):
image_decoded = tf.image.decode_png(tf.read_file(filename), channels=3)
image_resized = tf.image.resize_images(image_decoded, [64, 64])
label = label == 'large vehicle'
return image_resized, label
filenames = tf.constant(df['filename'])
labels = tf.constant(df['general_class'])
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.map(parse_image)
dataset = dataset.shuffle()
dataset = dataset.batch(32)
dataset = dataset.repeat()
return dataset
images_fc = tf.feature_column.numeric_column('image', shape=[64, 64, 3])
estimator = tf.estimator.DNNClassifier(feature_columns=[images_fc],
hidden_units=[32, 32, 32, 32])
metrics = estimator.train(lambda : dataset, steps=10000)
其中df 是pandas.DataFrame,其中包含图像路径及其对应的标签。图像存储在磁盘上的上述文件夹路径中。
我收到以下错误:
ValueError: Tensor("IteratorV2:0", shape=(), dtype=resource) must be from the same graph as Tensor("BatchDatasetV2_4:0", shape=(), dtype=variant).
我错过了什么?为什么不是所有东西都在同一张图上构建?
【问题讨论】:
标签: tensorflow tensorflow-estimator