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]
相关推荐
牧马人win1 小时前
.NET 开发 MCP 服务器完全指南:打造智能数据库查询助手
ai·.net·mcp
后端AI实验室1 小时前
我把同一个需求分别交给初级程序员、高级程序员和AI,结果让我沉默了
java·ai
明月_清风4 小时前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风4 小时前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
ZhengEnCi21 小时前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风1 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风1 天前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
测试蔡坨坨2 天前
OpenClaw 快速上手教程:用手机远程指挥电脑,打造你的 24 小时 AI 管家!
ai
方方不听话2 天前
🦞 重磅!腾讯 QQ 官方接入 OpenClaw“小龙虾”:一键创建机器人,1分钟极速部署!
ai·openclaw·小龙虾
Flittly2 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent