如何有效地充分使用tensorflow-gpu?

时间:2019-07-17 10:57:58

标签: python tensorflow gpu

我对使用tensorflow-gpu有问题。当我在训练步骤上使用tensorflow-gpu时,它可以完美运行,实际上比我预期的要好。它使用了我的笔记本电脑gpu(Geforce 940m-Notebook)几乎100%,性能令人满意。

但是,当我尝试在实时或某些视频中使用tensorflow-gpu进行对象检测时,它仅使用我的gpu大约%30,并且会话部分需要花费很多时间才能完成。我也收到称为ran out of memory trying to allocate 2.26GiB with freed_by_count=0.的错误。

我将在下面放置一些屏幕快照的链接,以清除有关我的问题的所有信息。

我进行了搜索以找出有关该错误的解决方案,但是它对我不起作用。 我尝试过的:

How can I solve 'ran out of gpu memory' in TensorFlow

How to prevent tensorflow from allocating the totality of a GPU memory?

我的图形卡功能(Nvdia GeForce 940M):

内存:2048 GPU默认时钟:1072 MHz GPU Boost Clock:1176 MHz

这是我的代码的一部分:

with detection_graph.as_default():

    with tf.Session(graph=detection_graph, 
      config=tf.ConfigProto(gpu_options=gpu_options)) as sess:


    model = tf.keras.models.load_model("CNN-3")

    while True:

      ret, image_np = cap.read()

      if W is None or H is None:
        (H, W)= image_np.shape[:2]



      image_np_expanded = np.expand_dims(image_np, axis=0)
      image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')

      boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
      scores = detection_graph.get_tensor_by_name('detection_scores:0')

      classes = detection_graph.get_tensor_by_name('detection_classes:0')
      num_detections = 
        detection_graph.get_tensor_by_name('num_detections:0')


      (boxes, scores, classes, num_detections) = sess.run(
    [boxes, scores, classes, num_detections],
    feed_dict={image_tensor: image_np_expanded})

训练过程中的这些图像:

https://pasteboard.co/IowqeLE.jpg ----- https://pasteboard.co/IowpXpV.gif

这些是实时对象检测:

https://pasteboard.co/IowqJME.jpg ----- https://pasteboard.co/Iowr8gS.gif

此错误消息:

https://pasteboard.co/IowrzDw.jpg

0 个答案:

没有答案