python - 使用 OpenCV 时如何在 NN 中使用 keras Lambda
问题描述
我有一个功能
def preprocess(image):
image = cv2.cvtColor(image, cv2.COLOR_RGB2YUV)
image = cv2.GaussianBlur(image, (3, 3), 0)
image = cv2.resize(image, (200, 66))
return image
我想在这样的 NN 的 Lambda 层中使用这个函数
model=Sequential()
model.add(Lambda(preprocess,input_shape=(160,320,3)))
#model.add(Lambda(lambda x: (x / 255.0) - 0.5, input_shape=(160,320,3)))
model.add(Lambda(lambda x: (x / 255.0) - 0.5))
model.add(Cropping2D(cropping=((60,25), (0,0))))
但是我得到了错误
model = nvidia_model()
print(model.summary())
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-9f6554917809> in <module>()
----> 1 model = nvidia_model()
2 print(model.summary())
6 frames
<ipython-input-9-5e5ec9bc70c2> in preprocess(image)
1 def preprocess(image):
2
----> 3 image = cv2.cvtColor(image, cv2.COLOR_RGB2YUV)
4 image = cv2.GaussianBlur(image, (3, 3), 0)
5 image = cv2.resize(image, (200, 66))
TypeError: Expected Ptr<cv::UMat> for argument '%s'
如何将此功能用作NN的一层?(请注意,仅使用 lambda x:(x/255.0) 效果很好。
注意:我不想在外部这样做。(因为我已经这样做了,所以效果很好,但现在我正在尝试在内部进行)
解决方案
推荐阅读
- python - 避免硬编码以获取 Python 文件路径
- list - 如何仅计算列表(PROLOG)中的数字元素,除了_?
- python - 密码python没有正确返回
- javascript - XMLhttprequest 得到 '404 not found' 但 invoke-webrequest 运行良好
- ubuntu - 带有 Bacula 的灾难恢复 Ubuntu 服务器
- internet-explorer - 如何以角度检索http 302响应
- swift - 我需要用正常的蓝点显示我的位置,并用不同的标记显示另一个点
- php - 如何让带有css样式的复选框在php的循环中工作
- android - 在带有 Kotlin 协程的 Room DAO 中使用 Deferred<...>
- dart - 处理从 DatePicker 接收的日期/时间数据的最佳格式