- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试批量处理 (batch_size, time_steps, my_data)
为什么在 flat_map
我得到的步骤 AttributeError: 'dict' object has no attribute 'batch'
x_train = np.random.normal(size=(60000, 768))
token_type_ids = np.ones(shape=(len(x_train)))
position_ids = np.random.normal(size=(x_train.shape[0], 5))
features_ds = tf.data.Dataset.from_tensor_slices({'inputs_embeds': x_train,
'token_type_ids': token_type_ids,
'position_ids': position_ids})
y_ds = tf.data.Dataset.from_tensor_slices(y_train)
ds = tf.data.Dataset.zip((features_ds, y_ds))
# result = list(ds.as_numpy_iterator())
result_ds = ds.window(size=time_steps, shift=time_steps, stride=1, drop_remainder=True). \
flat_map(lambda x, y: tf.data.Dataset.zip((x.batch(time_steps), y.batch(time_steps))))
知道是什么问题吗?以及如何解决?
最佳答案
您可以将批处理添加为单独的步骤:
x_train = np.random.normal(size=(60000, 768))
token_type_ids = np.ones(shape=(len(x_train)))
position_ids = np.random.normal(size=(x_train.shape[0], 5))
features_ds = tf.data.Dataset.from_tensor_slices({'inputs_embeds': x_train,
'token_type_ids': token_type_ids,
'position_ids': position_ids})
y_train = np.random.normal(size=(60000, 1))
y_ds = tf.data.Dataset.from_tensor_slices(y_train)
ds = tf.data.Dataset.zip((features_ds, y_ds))
result_ds = ds.window(size=time_steps, shift=time_steps, stride=1, drop_remainder=True).\
flat_map(lambda x, y: tf.data.Dataset.zip((x, y)))
time_steps=3
result_ds=result_ds.batch(time_steps)
for i in result_ds.take(1):
print(i)
关于tensorflow - tf.data WindowDataset flat_map 给出 'dict' 对象没有属性 'batch' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63366229/
我正在尝试编写一个包含字符串索引和字符串中每个字符的向量。 在下面的例子中,0 J, 0 a, 0 n ... 1 J, 1i, ... fn main() { let names = vec
我一整天都在编写以下代码,(here 是围栏) /// The rule that moves state from one to another. /// /// `S` - the type pa
你好!我正在尝试完成我的第一个 RxPY 项目,但我遇到了一些问题 了解 Python 中 flat_map 的行为。 在这个项目中,有一个从生成器(Kafka 消费者)创建的 Observable。
给定结构的集合(向量/切片)。如何在每个结构的某些字段上创建组合的迭代器? 以下是使用flat_map的具体尝试: struct Game { home_team: u8, away_
我知道我们可以使用 collect移动 Result从内到外,例如: fn produce_result(my_struct: &MyStruct) -> Result; let my_results
这个问题在这里已经有了答案: Conditionally iterate over one of several possible iterators (4 个答案) 关闭 2 年前。 是否可以在
有没有办法在不切换到使用 iter 而不是 into_iter 的情况下完成这项工作? let strings: Vec = vec!["1 2".to_string(), "3 4".to_stri
我的问题的以下简化/抽象版本: fn main() { let arr = vec![1., 2., 3., 4., 5., 6., 7., 8., 9.]; let size = a
我的问题的以下简化/抽象版本: fn main() { let foo_selectors = vec![0, 1]; let foos: Vec = foo_selectors
我正在研究 Project Euler 96自学 Rust。我编写了这段代码来读取文件并将其转换为整数向量 ( Playground )。 let file = File::open(&args[1]
给定 foo 的定义: let foo = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]]; 我希望能够编写这样的代码: let result: V
在处理一些遗留代码时,我遇到了内存问题,这主要是(我相信)由于广泛使用 STL map (特别是“ map 中的 map ”)。 我正在将 Boost flat_map 视为一种可能的解决方案。有没有
我正在尝试生成这样的序列:1,2,3,4,5,6,7,8,9,1,0,1,1,1,2... fn main() { let iter = (1..).flat_map(|j| j.to_str
为什么在闭包上没有类型注释的情况下可以编译? fn transform(input: &Vec>) { input.iter().flat_map(|words| words.iter());
我认为当你有一个可变长度的散列数组并且你想单独处理每个散列时,flat_map 很棒: data = [ {'apple' => 'fruit'}, {'carrot' => 'vegetab
编辑:因为我用错误的例子写了问题并且没有描述我的问题,我会再做一次! 在我看来,#flat_map 尽管是 Enumerator::Lazy 类的一部分,但它本身并不是非常可枚举的。 这个例子可以正常
我认为我对生命周期有很好的理解,但我读到的内容与编译器在闭包方面所说的不一致;) 我有一个带有签名的函数: fn split_to_words(content: &str) -> Vec 使用 for
我希望能够重复一个过程,在该过程中,我们正在迭代的集合被更改 n 次。 n 仅在运行时已知,可以由用户指定,因此我们不能将其硬编码到类型中。 通过 collect 在迭代之间使用中间数据结构的方法是可
我正在尝试创建一个管道,以使用 TensorFlow Dataset API 和 Pandas 读取多个 CSV 文件。但是,使用 flat_map 方法会产生错误。但是,如果我使用 map 方法,我
我正在使用数据集 API,读取数据如下: dataset = tf.data.TFRecordDataset(filename, compression_type="GZIP") dataset =
我是一名优秀的程序员,十分优秀!