我正在使用tensorflow-gpu
和mobilenet ssd v1开发对象检测工具。它运行成功,但是使用opencv videoCapture
的速度大约为(1 FPS)。 GPU使用率仅显示1-2%。请提出任何解决方案。
counting_started2018-12-20 13:52:29.390097: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-12-20 13:52:30.345891: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties:
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.30GiB
2018-12-20 13:52:30.346365: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0
2018-12-20 13:52:31.688196: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-12-20 13:52:31.688390: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0
2018-12-20 13:52:31.688504: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N
2018-12-20 13:52:31.688754: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3013 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
2018-12-20 13:52:35.488701: I tensorflow/stream_executor/dso_loader.cc:151] successfully opened CUDA library cupti64_90.dll locally
with detection_graph.as_default():
with tf.device('/gpu:0'):
with tf.Session(graph=detection_graph) as sess:
d_image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
d_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
d_scores = detection_graph.get_tensor_by_name('detection_scores:0')
d_classes = detection_graph.get_tensor_by_name('detection_classes:0')
d_num_detections = detection_graph.get_tensor_by_name('num_detections:0')
while True:
import gc
gc.collect()
ret, image_np = cap.read()
if image_np is None:
break
image_rgb = cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB)
(height, width) = image_np.shape[:2]
rects = []
if totalFrames % 1 == 0:
trackers = []
status = "Detecting"
image_np_expanded = np.expand_dims(image_np, axis=0)
options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
# Actual detection.
(boxes, scores, classes, num_detections) = sess.run(
[d_boxes, d_scores, d_classes, d_num_detections],
feed_dict={d_image_tensor: image_np_expanded},
options=options, run_metadata=run_metadat
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=2)
cv2.imshow('object detection', image_np)
if cv2.waitKey(25) == ord('q'):
cv2.destroyAllWindows()
break
在上图中看到时,它将显示GPU的实际使用情况。在运行时始终为1-2%。我想念什么?