成功解决AttributeError: 'MapDataset' object has no attribute 'group_by_window'

简介: 成功解决AttributeError: 'MapDataset' object has no attribute 'group_by_window'

解决问题


image.png


AttributeError: 'MapDataset' object has no attribute 'group_by_window'



解决思路


错误属性:“mapdataset”对象没有“window”的“group”属性


A transformation that groups windows of elements by key and reduces them.


This transformation maps each consecutive element in a dataset to a key using key_func and groups the elements by key. It then applies reduce_func to at most window_size_func(key) elements matching the same key. All except the final window for each key will contain window_size_func(key) elements; the final window may be smaller.


You may provide either a constant window_size or a window size determined by the key through window_size_func.


Args:


key_func: A function mapping a nested structure of tensors (having shapes and types defined by self.output_shapes and self.output_types) to a scalar tf.int64 tensor.

reduce_func: A function mapping a key and a dataset of up to window_size consecutive elements matching that key to another dataset.

window_size: A tf.int64 scalar tf.Tensor, representing the number of consecutive elements matching the same key to combine in a single batch, which will be passed to reduce_func. Mutually exclusive with window_size_func.

window_size_func: A function mapping a key to a tf.int64 scalar tf.Tensor, representing the number of consecutive elements matching the same key to combine in a single batch, which will be passed to reduce_func. Mutually exclusive with window_size.

Returns:


A Dataset transformation function, which can be passed to tf.data.Dataset.apply.


Raises:


ValueError: if neither or both of {window_size, window_size_func} are passed.


解决方法


'MapDataset' 这种对象,没有'group_by_window'这种属性。


tf.contrib.data.group_by_window(

   key_func,

   reduce_func,

   window_size=None,

   window_size_func=None

)

   # batched_dataset = src_tgt_dataset.group_by_window(

   #     key_func=key_func, reduce_func=reduce_func, window_size=batch_size)

   #20180626修改此处

   batched_dataset = src_tgt_dataset.apply(

       tf.contrib.data.group_by_window(

           key_func=key_func, reduce_func=reduce_func, window_size=batch_size))




相关文章
|
4月前
|
TensorFlow 算法框架/工具 Python
【Tensorflow 2】解决'Tensor' object has no attribute 'numpy'
解决'Tensor' object has no attribute 'numpy'
87 3
|
5月前
|
并行计算 Serverless API
函数计算操作报错合集之出现 "AttributeError: 'NoneType' object has no attribute 'pop'" 错误,是什么原因
在使用函数计算服务(如阿里云函数计算)时,用户可能会遇到多种错误场景。以下是一些常见的操作报错及其可能的原因和解决方法,包括但不限于:1. 函数部署失败、2. 函数执行超时、3. 资源不足错误、4. 权限与访问错误、5. 依赖问题、6. 网络配置错误、7. 触发器配置错误、8. 日志与监控问题。
169 1
|
4月前
|
API C++ Python
【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')
【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')
|
4月前
|
TensorFlow API 算法框架/工具
【Tensorflow+keras】解决使用model.load_weights时报错 ‘str‘ object has no attribute ‘decode‘
python 3.6,Tensorflow 2.0,在使用Tensorflow 的keras API,加载权重模型时,报错’str’ object has no attribute ‘decode’
62 0
|
5月前
|
Python
【Python】已解决:(Python xlwt写入Excel报错)AttributeError: ‘function’ object has no attribute ‘font’
【Python】已解决:(Python xlwt写入Excel报错)AttributeError: ‘function’ object has no attribute ‘font’
123 0
|
5月前
|
Python
【Python】已解决:(Python写入Excel表格报错)‘NoneType’ object has no attribute ‘write’
【Python】已解决:(Python写入Excel表格报错)‘NoneType’ object has no attribute ‘write’
325 0
|
5月前
|
XML 数据格式 Python
【Python】已解决:AttributeError: ‘function’ object has no attribute ‘ELement’
【Python】已解决:AttributeError: ‘function’ object has no attribute ‘ELement’
199 0
|
5月前
|
API Python
【Python】已解决:AttributeError: ‘TfidfVectorizer’ object has no attribute ‘get_feature_names_out’
【Python】已解决:AttributeError: ‘TfidfVectorizer’ object has no attribute ‘get_feature_names_out’
188 0
|
2天前
|
JSON Java Apache
Java基础-常用API-Object类
继承是面向对象编程的重要特性,允许从已有类派生新类。Java采用单继承机制,默认所有类继承自Object类。Object类提供了多个常用方法,如`clone()`用于复制对象,`equals()`判断对象是否相等,`hashCode()`计算哈希码,`toString()`返回对象的字符串表示,`wait()`、`notify()`和`notifyAll()`用于线程同步,`finalize()`在对象被垃圾回收时调用。掌握这些方法有助于更好地理解和使用Java中的对象行为。
|
1月前
|
存储 Java 程序员
Java基础的灵魂——Object类方法详解(社招面试不踩坑)
本文介绍了Java中`Object`类的几个重要方法,包括`toString`、`equals`、`hashCode`、`finalize`、`clone`、`getClass`、`notify`和`wait`。这些方法是面试中的常考点,掌握它们有助于理解Java对象的行为和实现多线程编程。作者通过具体示例和应用场景,详细解析了每个方法的作用和重写技巧,帮助读者更好地应对面试和技术开发。
127 4