keras - 使用 keras 模型检查输入时出错
问题描述
我是训练模型,将模型保存在磁盘上,使用模型时出错。
Error when checking input: expected conv2d_input to have 4 dimensions, but got array with shape (150, 150, 3)
火车型号:
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3))
使用型号:
model = load_model(os.path.join('models', 'myModel.h5'))
model.predict(img) # img - OpenCV image
解决方案
用这个:
import numpy as np
model.predict(img[np.newaxis, :, :, :])
推荐阅读
- java - JavaFX maven 多模块应用打包
- maven - 由于循环依赖而无法构建的项目
- react-native - React Native 导航的问题
- c# - 如何从 Xamarin SearchBar 获取文本到 viewmodel
- html - 这个设计可以只用 CSS 做吗?
- php - 如何使用 orWhere in Doctrine | 返回具有 ROLE_ADMIN 和 ROLE_USER 的用户
- windows-store-apps - 在 APPXBUNDLE 中打包 APPX
- ruby-on-rails - 使用 redis 作为 Rails 应用程序的数据库,以处理大量 api 请求
- sql - SSIS包变量配置
- c# - UWP 和 WPF 之间的 (UDP) 通信