Python TensorFlow数据集API映射函数中的张量计算
我有以下数据集输入函数来创建数据集生成器Python TensorFlow数据集API映射函数中的张量计算,python,tensorflow,tensorflow-datasets,Python,Tensorflow,Tensorflow Datasets,我有以下数据集输入函数来创建数据集生成器 def dataset_input_fn(filenames, shuffle, batch_size, sample): def parser(record): features = { 'mean_rgb': tf.FixedLenFeature([1024], tf.float32), 'category': tf.FixedLenFeature([], tf.int64)
def dataset_input_fn(filenames, shuffle, batch_size, sample):
def parser(record):
features = {
'mean_rgb': tf.FixedLenFeature([1024], tf.float32),
'category': tf.FixedLenFeature([], tf.int64)
}
parsed = tf.parse_single_example(record, features)
vrv = parsed['mean_rgb']
label = tf.cast(parsed['category'], tf.int32)
return {"mean_rgb": vrv}, label
dataset = tf.data.TFRecordDataset(filenames)
dataset = dataset.map(parser)
if sample:
dataset = dataset.flat_map(
lambda x, y: tf.data.Dataset.from_tensors((x, y)).repeat(oversample_classes(y))
)
dataset = dataset.filter(undersampling_filter)
dataset = dataset.shuffle(buffer_size=100 * batch_size)
dataset = dataset.batch(batch_size).repeat(1)
iterator = dataset.make_one_shot_iterator()
features, labels = iterator.get_next()
return features, labels
我正试图根据标签跟踪超/次采样数据。在我的dataset.flat_map
函数中,我迭代了每个标签,并想确定重复的频率。然而,y是一个张量,我不能把它作为一个整数来计算。当我尝试sess.run(label)
ValueError:获取参数
不能解释为张量。(张量张量(“arg1:0”,形状=()),
dtype=int32)不是此图的元素。)
您可以发布该错误的完整堆栈跟踪吗?问题似乎不在
数据集\u input\u fn()
范围内,因为它似乎没有运行任何会触发该异常的代码。(“Fetch参数”表示它来自sess.run()
调用。)