【发布时间】:2017-10-21 18:22:34
【问题描述】:
我已经使用 code 训练了一个卷积 3d 模型
我试图得到如下预测,
import cv2
from keras.models import Sequential, load_model
import numpy as np
#create an empty frame
frames = []
#defince row, col
img_rows,img_cols,img_depth=16,16,15
cap = cv2.VideoCapture('run.avi')
fps = cap.get(5)
#Use only first 15 frames for prediction
for k in range(15):
ret, frame = cap.read()
frame=cv2.resize(frame,(img_rows,img_cols),interpolation=cv2.INTER_AREA)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frames.append(gray)
#preprocess
input = np.array(frames)
ipt=np.rollaxis(np.rollaxis(input,2,0),2,0)
reshape_frames = np.expand_dims(ipt, axis=0)
#run prediction
model = load_model('current.h5')
preds = model.predict(reshape_frames)
print(preds)
但它会引发以下错误,
ValueError:检查时出错:预期 conv3d_1_input 有 5 尺寸,但得到形状为 (1, 16, 16, 15) 的数组
我怎样才能解决这个问题?
【问题讨论】:
标签: python opencv neural-network keras