【问题标题】:W&B Keras callback TypeError: ufunc 'isfinite' not supported for the input typesW&B Keras 回调 TypeError:输入类型不支持 ufunc 'isfinite'
【发布时间】:2020-01-20 00:25:16
【问题描述】:

我正在尝试一个 TF 模型,其中输入是字符串张量作为输入,我的模型包含一个用于文本处理的 TextVectorization 层,该层在 TF 2.2 中可用。

训练在 W&B 回调中失败并出现以下错误

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' 

调试的时候发现问题出在权重直方图的计算过程中

> /usr/local/lib/python3.6/dist-packages/numpy/lib/histograms.py(325)_get_outer_edges()
    323     else:
    324         first_edge, last_edge = a.min(), a.max()
--> 325         if not (np.isfinite(first_edge) and np.isfinite(last_edge)):
    326             raise ValueError(
    327                 "autodetected range of [{}, {}] is not finite".format(first_edge, last_edge))
ipdb> first_edge
b'0'
ipdb> last_edge
b'zurich'
ipdb> np.isfinite('0')
*** TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

这是我设置 W&B 回调和运行训练的方法

wandb_callback = wandb.keras.WandbCallback(log_weights=True)
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
model.fit(train_ds, validation_data=valid_ds, epochs=config.epochs, shuffle=True, verbose=1, callbacks=[wandb_callback])

我尝试使用wandb.keras.WandbCallback() 创建回调,但没有记录权重,但同样的问题,它一直在尝试计算直方图并在一个时期结束时失败。

知道这里有什么问题吗?

【问题讨论】:

    标签: python tensorflow keras callback


    【解决方案1】:

    你能分享你的实际模型代码吗?看起来模型本身包含字符串张量。通常,您会在通过网络之前将字符串转换为嵌入。你在使用 TensorFlow 2 吗?

    【讨论】:

    • 是的,我已经更新了描述,我正在使用 TextVectorization 层进行图内文本预处理。
    猜你喜欢
    • 2020-09-29
    • 2020-02-16
    • 2019-11-04
    • 2018-01-08
    • 2020-07-28
    • 2022-12-17
    • 1970-01-01
    • 2020-07-21
    • 2023-03-30
    相关资源
    最近更新 更多