2017-10-21 85 views
0

我已经训练使用code尺寸误差,同时预测

我试着去得到预测如下:a convolutional3d模型,

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: Error when checking : expected conv3d_1_input to have 5 dimensions, but got array with shape (1, 16, 16, 15)

如何我可以解决这个问题吗?

回答

1

看到docs for convolutional 3D layers

Input shape

5D tensor with shape: (samples, channels, conv_dim1, conv_dim2, conv_dim3) if data_format='channels_first' or 5D tensor with shape: (samples, conv_dim1, conv_dim2, conv_dim3, channels) if data_format='channels_last'.

那么,什么是bascially发生的事情是,你提供给您的第一CONV 3D图层输入形状不适合于预期的输入。

为了解决这个问题,你可以去如下:

  • 变化所提供的输入,所以它的预期输入相匹配(也考虑到data_format如上所述)。因为它看起来在你的代码中,你根本不使用img_depth信息。您基本上提供了一个2D图像到3D转换网。
  • 使用2D网点并创建新模型