python - ValueError:在回归问题上训练 VGG16 模型以生成边界框坐标时,使用序列设置数组元素
问题描述
我正在尝试对我的回归问题使用自定义 Huber 损失函数并训练 VGG16 模型来生成边界框坐标。代码如下:
def huber(true, pred, delta=1.0):
loss = np.where(np.abs(true-pred) < delta , 0.5*((true-pred)**2), delta*np.abs(true - pred) - 0.5*(delta**2))
return np.sum(loss)
...
...
...
model.compile(optimizer=Adam(lr=0.001), loss=huber)
运行脚本时,使用自定义 Huber 损失函数时出现错误:
model.compile(optimizer=Adam(lr=0.001), loss=huber)
File "C:\Users\...\lib\site-packages\keras\engine\training.py", line 342, in compile
sample_weight, mask)
File "C:\Users\...\lib\site-packages\keras\engine\training_utils.py", line 404, in weighted
score_array = fn(y_true, y_pred)
File "C:\Users\...\train_code.py", line 157, in huber
loss = np.where(np.abs(true-pred) < delta , 0.5*((true-pred)**2), delta*np.abs(true - pred) - 0.5*(delta**2))
File "<__array_function__ internals>", line 6, in where
ValueError: setting an array element with a sequence.
解决方案
推荐阅读
- python - 在 python 中使用 TASK_TRIGGER_LOGON 创建计划任务
- graph - 完整图中“广义”匹配的算法
- android - 可以在 Google Play 上为 Android TV 和智能手机发布相同的应用程序
- php - 如何用php中的变量替换url值?并在获取数组中获得动态结果?
- git - Git local 忽略符号链接的目录
- python - 理解 Flask 请求对象
- amazon-web-services - 为什么 AWS Glue 不支持将 SQL 作为 ETL 语言?
- python-3.6 - 尝试使用 python docx 模块从 word 文档中打印 20 行,但它只打印第一行
- java - BigDecimal setScale 方法语法不起作用
- c# - 变量像类型一样使用