2017-10-21 82 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網點並創建新模型