tensorflow keras Model.fit returning: ValueError: Unrecognized data type

题意:TensorFlow Keras 的 Model.fit 方法返回了一个 ValueError,提示数据类型无法识别

问题背景:

I'm trying to train a keras model with 2 inputs: an image part that's a tf.data.Dataset and a nor mal part represented by a pd.DataFrame

python 复制代码
from tensorflow.keras.optimizers import Adam
opt = Adam(learning_rate=1e-3, decay=1e-3 / 200)

model.compile(loss="mean_absolute_percentage_error", optimizer=opt)

model.fit(
    x=[df.loc[:, df.columns != 'target'], ds.batch(8)], y=df["target"],
    epochs=200)

I was trying to fit the model but I get ValueError

python 复制代码
ValueError: Unrecognized data type: x=[...][401059 rows x 52 columns]
, <_BatchDataset element_spec=(TensorSpec(shape=(None, 32, 256, 256, 3), 
dtype=tf.float32, name=None), 
TensorSpec(shape=(None, 32, 256, 256, 3), dtype=tf.float32, name=None))>] (of type <class 'list'>)

问题解决:

the problem was an error in tensoflow zipping and reformating dataset helped

python 复制代码
def post_zip_process(example1, example2):
    reshaped_input = tf.transpose(example1[0], [0, 1, 2 ,-1])
    reshaped_input = reshaped_input[0, :, :, :]
    print(reshaped_input.shape)
    return (reshaped_input, example2[0]), example1[1]
相关推荐
咖啡配辣条11 分钟前
Python基础09
python
超大力王13 分钟前
DAY 45 超大力王爱学Python
开发语言·python
林-梦璃14 分钟前
Python开发基础手语识别(基础框架版)
开发语言·python·手语识别
RockyRich41 分钟前
突然无法调用scikit-learn、xgboost
python·机器学习·scikit-learn
真的很上进42 分钟前
2025最全TS手写题之partial/Omit/Pick/Exclude/Readonly/Required
java·前端·vue.js·python·算法·react·html5
敲键盘的小夜猫1 小时前
大模型智能体核心技术:CoT与ReAct深度解析
人工智能·python
华科云商xiao徐1 小时前
Python利用Scrapy框架部署分布式爬虫
python·scrapy
小前端大牛马1 小时前
java教程笔记(十四)-线程池
java·笔记·python
老歌老听老掉牙2 小时前
旋量理论:刚体运动的几何描述与机器人应用
python·算法·机器学习·机器人·旋量
我是初九2 小时前
【李沐-动手学深度学习v2】1.Colab学习环境配置
人工智能·python·学习·colab