Implement CNN+LSTM Model to predict a video

Viewed 84

Hi guys i already making my model for cnn(alexNet)+lstm model for prediction in a video to check from 10 frames to make a prediction but i still confused by how to code the program to check the frame first and how to resize it correctly so every video that i input can be checked by this model

here's some of the code that has been made

while vid.isOpened():
    ret, frame = vid.read()
    if ret == True:
      frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      scale_percent = 20 # percent of original size
      width = int(frame.shape[1] * scale_percent / 100)
      height = int(frame.shape[0] * scale_percent / 100)
      dim = (width, height)
      frame_set = cv2.resize(frame, dim, interpolation = cv2.INTER_AREA)
      pred = model.predict(frame_set)
      texto = pred(frame)
      frame = cv2.putText(frame,str(texto),(0,130), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 3)
      cv2.imshow('Video', frame)

      if cv2.waitKey(25) & 0xFF == ord('q'):
        break
      else:
        break

vid.release()
cv2.destroyAllWindows()
 

but I still got error because my resize isn't the same as my model ask

ValueError: Input 0 is incompatible with layer model_1: expected shape=(None, 10, 299, 299, 3), found shape=(None, 384)

it asks just like when i made my model when 10 is how much frame that my model need to predict

1 Answers

The input shape of your Alexnet model is (None, 10, 299, 299, 3), while your frame_set sample has size (None, 384). You should modify the input shape of your model to be (384) (for example, by adding one first layer (Input((384,))), even though I guess Alexnet is better suited for images. However I cannot tell you how to do that since I don't see the model definition

Related