青春,十八碎 2022-09-12 16:39 采纳率: 0%
浏览 50
已结题

tensorflow跑模型报错 'BatchDataset' object has no attribute 'ndim'

问题遇到的现象和发生背景

使用tensorflow跑模型时,出现错误AttributeError: 'BatchDataset' object has no attribute 'ndim'

问题相关代码,请勿粘贴截图

history=model.fit(train_dataset,batch_size=batch_size, epochs=10,validation_data=val_dataset)
运行结果及报错内容

ttributeError                            Traceback (most recent call last)
<ipython-input-17-c440ece0c53a> in <module>
----> 1 history=model.fit(train_dataset,batch_size=batch_size, epochs=10,validation_data=val_dataset)

~\Anaconda3\envs\zktest\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
   1141         sample_weight=sample_weight,
   1142         class_weight=class_weight,
-> 1143         batch_size=batch_size)
   1144     # Prepare validation data.
   1145     if validation_data:

~\Anaconda3\envs\zktest\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, batch_size)
    763         feed_input_shapes,
    764         check_batch_axis=False,  # Don't enforce the batch size.
--> 765         exception_prefix='input')
    766 
    767     if y is not None:

~\Anaconda3\envs\zktest\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    148     data = data.values if data.__class__.__name__ == 'DataFrame' else data
    149     data = [data]
--> 150   data = [standardize_single_array(x) for x in data]
    151 
    152   if len(data) != len(names):

~\Anaconda3\envs\zktest\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\training_utils.py in <listcomp>(.0)
    148     data = data.values if data.__class__.__name__ == 'DataFrame' else data
    149     data = [data]
--> 150   data = [standardize_single_array(x) for x in data]
    151 
    152   if len(data) != len(names):

~\Anaconda3\envs\zktest\lib\site-packages\tensorflow\python\keras\_impl\keras\engine\training_utils.py in standardize_single_array(x)
     86   elif tensor_util.is_tensor(x):
     87     return x
---> 88   elif x.ndim == 1:
     89     x = np.expand_dims(x, 1)
     90   return x

AttributeError: 'BatchDataset' object has no attribute 'ndim'

A

我的解答思路和尝试过的方法

我感觉是版本问题,但是找不到哪里改

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 9月20日
      • 赞助了问题酬金10元 9月12日
      • 创建了问题 9月12日

      悬赏问题

      • ¥15 Excel数据分析,制作退休计划的电子表格模型
      • ¥15 EasyExcel向模板追加导入数据出现多余空行
      • ¥55 C语言谁能教我下面的代码怎么打
      • ¥15 C/C++程序代码解释
      • ¥15 java 2个list合并,如果id相同的对象则属性合并到一起,不同id的对象也要保留
      • ¥50 刚接触优化算法,在用Python时调用二次规划包cvxopt遇到如下问题
      • ¥15 python反斜杠问题
      • ¥30 pywinauto 如何获取弹出式菜单的数据
      • ¥15 正则问题,sos,SOS
      • ¥15 ModuleNotFoundError