解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following

简介: 解决ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following

2022-01-04 19:21:07.023270: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-01-04 19:21:07.058585: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)
Traceback (most recent call last):
  File "E:/Code/PyCharm/TensorFlow学习/main.py", line 78, in <module>
    validation_split=0.2)
  File "D:\Anaconda\lib\site-packages\keras\engine\training.py", line 1121, in fit
    (x, y, sample_weight), validation_split=validation_split))
  File "D:\Anaconda\lib\site-packages\keras\engine\data_adapter.py", line 1479, in train_validation_split
    "arrays, found following types in the input: {}".format(unsplitable))
ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found following types in the input: [<class 'tensorflow.python.data.ops.dataset_ops.MapDataset'>]

问题原因:

如果使用validation_split分割验证集,那么输入的训练集必须是Tensor或者Numpy数据类型,不可以是Dataset迭代器类型

解决办法:

方案一:添加验证集

添加验证集,而不是使用validation_split进行分割

val_batches = tf.data.experimental.cardinality(train_dataset)
val_dataset = train_dataset.skip(val_batches // 5)
train_dataset = train_dataset.take(val_batches // 5)

使用训练集一部分作为验证集使用

方案二:将Dataset类型变成Numpy或者Tensor

这种方式只适合数据量不是特别大

# 前提要将所有数据作为一个批次加入的Dataset中
train_data, train_label = next(iter(train_datasets))


目录
相关文章
|
Windows
已解决Win11报错 OSError: [WinError 1455] 页面文件太小,无法完成操作。
Win11报错 OSError: [WinError 1455] 页面文件太小,无法完成操作。 Error loading "D:\aaaa\envs\gs\lib\site-packages\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.
14764 0
已解决Win11报错 OSError: [WinError 1455] 页面文件太小,无法完成操作。
|
11月前
|
人工智能 运维 API
火爆全网的Skill自己怎么做?老金来教你!(含避坑指南)
本文深度解析Anthropic官方Skills开发指南(anthropics/skills),揭秘“渐进式展示”三层架构:100词元数据决定触发、5000词主体承载核心逻辑、资源按需加载。老金亲测踩坑,提炼6步实操流程与避坑公式,助你零基础打造高效、可维护的专业Skill。(239字)
13807 4
|
域名解析 网络协议 安全
DNS查询工具简介
DNS查询工具简介
19649 4
|
人工智能 自然语言处理 安全
claude国内怎么用?教你两种claude国内使用方法!
Claude AI 是由 Anthropic 公司开发的一款新一代 AI 助手,旨在成为更安全、更友好、更可靠的 AI 系统。它基于 Anthropic 对 AI 安全性的深入研究,并采用 “Constitutional AI” (宪法式 AI) 的训练方法,使其行为更符合人类价值观,并减少有害输出的可能性。 🛡️
|
TensorFlow API 算法框架/工具
Tensorflow:from tensorflow.keras import layers 报错
Tensorflow:from tensorflow.keras import layers 报错
2284 1
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17713 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
3天前
|
人工智能 安全 网络安全
|
7天前
|
云安全 数据采集 人工智能

热门文章

最新文章