python - 我的视频模型测试程序没有显示任何内容
问题描述
目前我上周正在学习深度学习我尝试运行我的程序并且它工作正常但是现在当日志相同时没有任何显示
重新安装 nvidia 驱动程序后它不显示
我已经为 tensorflow 安装了 cuda 和 cuddn,就像 tensorflow 文档中所说的那样
这是我的代码
# import miscellaneous modules
import matplotlib.pyplot as plt
import cv2
import os
import numpy as np
import time
import pandas as pd
import tensorflow.keras.backend as K
# import keras_retinanet
from tensorflow.keras import models
import sys
model_path = 'Model/CCTV_10Frame_SGD_Model_1e4_b16_l21e2_224_Terbaru.h5'
model = models.load_model(model_path)
vid = cv2.VideoCapture("Data Fix/Data16_116.mp4")
while(vid.isOpened()):
ret, frame = vid.read()
vid.set(3, 480)
vid.set(4, 240)
start = time.time()
if ret == True:
draw = frame.copy()
draw = cv2.cvtColor(draw, cv2.COLOR_BGR2RGB)
scale_percent = 20 # percent of original size
width = 224
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_on_batch(frame_set)
# Get the predicted class from the result using argmax
pred_class = np.argmax(result)
# Here I assume that the index is the desired class like most cases
# Now we will write the class label on the image
# Set the font and place
font = cv2.FONT_HERSHEY_SIMPLEX
org = (50, 50)
cv2.putText(draw, str(pred_class), org, font, .5, (255,255,255),2,cv2.LINE_AA)
# now just show the frame
cv2.imshow('frame', draw)
print(result)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
vid.release()
cv2.destroyAllWindows()
日志是这样的
2021-08-30 23:18:53.846817: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudart64_110.dll
2021-08-30 23:19:24.046369: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library nvcuda.dll2021-08-30 23:19:24.671644: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties:
pciBusID: 0000:03:00.0 name: NVIDIA GeForce 920MX computeCapability: 5.0
coreClock: 0.993GHz coreCount: 2 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 13.41GiB/s
2021-08-30 23:19:24.672060: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudart64_110.dll
2021-08-30 23:19:24.687853: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cublas64_11.dll
2021-08-30 23:19:24.688315: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cublasLt64_11.dll
2021-08-30 23:19:24.709928: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cufft64_10.dll
2021-08-30 23:19:24.714666: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library curand64_10.dll
2021-08-30 23:19:24.720694: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cusolver64_11.dll
2021-08-30 23:19:24.728896: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cusparse64_11.dll
2021-08-30 23:19:24.730655: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudnn64_8.dll
2021-08-30 23:19:24.731295: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1871] Adding visible gpu devices: 0
2021-08-30 23:19:24.732060: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-08-30 23:19:24.733284: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties:
pciBusID: 0000:03:00.0 name: NVIDIA GeForce 920MX computeCapability: 5.0
coreClock: 0.993GHz coreCount: 2 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 13.41GiB/s
2021-08-30 23:19:24.734279: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1871] Adding visible gpu devices: 0
2021-08-30 23:19:25.486129: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-08-30 23:19:25.486614: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264] 0
2021-08-30 23:19:25.486863: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1277] 0: N
2021-08-30 23:19:25.487580: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1418] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1363 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce 920MX, pci bus id: 0000:03:00.0, compute capability: 5.0)
没有出现任何错误,但 cv2.imshow 没有工作,我也尝试在 cv2.imshow 之前添加一些打印以进行测试,但也没有打印结果
任何答案都会有帮助
太感谢了
解决方案
将您的视频文件移动到您的项目文件夹中,更改
vid = cv2.VideoCapture("Data Fix/Data16_116.mp4")
作为
vid = cv2.VideoCapture("Data16_116.mp4")
如果您的视频是否打开,您可以尝试添加此代码,将其添加到 vid = cv2.... 行
if (vid.isOpened()== False):
print("error")
推荐阅读
- javascript - 无法使用 react 和 redux 在待办事项列表中添加待办事项。我究竟做错了什么?
- php - 我如何从 id, php 中获取值
- ios - 我如何每天奖励用户?
- c++ - 开发“Windows C/C++ 桌面应用程序”以将 Windows10 连接到蓝牙 5.0 设备时出现问题
- python - 当我使用 collidepoint() 时,我的 pygame 窗口显示“没有响应”
- bash - 意外标记'('bash附近的语法错误
- node.js - “请求”类型上不存在属性“用户”
>' - c# - 使用 C# Fluent Assertions 比较具有不同大小的相同 DTO 列表
- django - 模板中的 Django TemplateDoesNotExist
- c++ - 如果我使用显式实例化,这是正确的编译方法吗?