cv2_imshow collab 没有显示使用 cnn+l;stm 模型预测视频的任何内容
cv2_imshow collab doesnt show anything for predicting video using cnn+l;stm model
大家好,我正在尝试将我的模型测试到视频中以进行预测
我没有错误日志或任何东西
但没有出现,我正在尝试打开视频并使用我的 cnn(alexnet)+lstm 模型进行预测
这是我的代码
model_path = 'Model/CCTV_10Frame_Adam_Model_1e2_b16_regul.h5'
model = models.load_model(model_path)
vid = cv2.VideoCapture("Data16_116.mp4")
while(True):
ret, frame = vid.read()
start = time.time()
if ret:
draw = frame.copy()
draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)
scale_percent = 20 # percent of original size
width = 299
height = width
dim = (width, height)
frame_set = cv2.resize(draw, dim, interpolation = cv2.INTER_AREA)
frame_set=np.arange(10*width*height*3).reshape(10,width, height, 3)
frame_set.reshape(10, width, height, 3).shape
frame_set = np.expand_dims(frame_set, axis=0)
result=model.predict(frame_set)
cv2_imshow(result)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
vid.release()
cv2.destroyAllWindows()
有人知道这件事吗?
任何答案将不胜感激
非常感谢!
注意:我确实在 vsc 中尝试过,但遗憾的是它只打开了 1 秒并且日志说
Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.25GiB
with freed_by_count=0. The caller indicates that this is not a
failure, but may mean that there could be performance gains if more
memory were available.
"""您能否在从代码中删除 **else:break** 块后进行检查?因为它可能会跳过相机帧而不验证来自用户的任何中断。
"""
if cv2.waitKey(1) & 0xFF == ord('q'): // remove the else block
break
大家好,我正在尝试将我的模型测试到视频中以进行预测
我没有错误日志或任何东西
但没有出现,我正在尝试打开视频并使用我的 cnn(alexnet)+lstm 模型进行预测
这是我的代码
model_path = 'Model/CCTV_10Frame_Adam_Model_1e2_b16_regul.h5'
model = models.load_model(model_path)
vid = cv2.VideoCapture("Data16_116.mp4")
while(True):
ret, frame = vid.read()
start = time.time()
if ret:
draw = frame.copy()
draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)
scale_percent = 20 # percent of original size
width = 299
height = width
dim = (width, height)
frame_set = cv2.resize(draw, dim, interpolation = cv2.INTER_AREA)
frame_set=np.arange(10*width*height*3).reshape(10,width, height, 3)
frame_set.reshape(10, width, height, 3).shape
frame_set = np.expand_dims(frame_set, axis=0)
result=model.predict(frame_set)
cv2_imshow(result)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
vid.release()
cv2.destroyAllWindows()
有人知道这件事吗?
任何答案将不胜感激
非常感谢!
注意:我确实在 vsc 中尝试过,但遗憾的是它只打开了 1 秒并且日志说
Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.25GiB with freed_by_count=0. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available.
"""您能否在从代码中删除 **else:break** 块后进行检查?因为它可能会跳过相机帧而不验证来自用户的任何中断。 """
if cv2.waitKey(1) & 0xFF == ord('q'): // remove the else block
break