Neural network YOLO内存不足

Neural network YOLO内存不足,neural-network,yolo,Neural Network,Yolo,我遵循了在GoogleColab中实现YOLO的方法。 它起作用了,在照片上的物体周围显示适当的矩形。 然后我需要在30000张图片上运行它。我所做的是在循环中运行示例中的代码(参见上面的链接)(参见下面的代码)。在第260张图片之后,我得到了“内存不足”。 请帮忙 除了我添加的循环外,代码几乎与(上面的链接)相同,结果如下: arrExtensions = ['.jpg','.jpeg','.png', '.gif'] arrCoinLocations = [] nCount = 0 fo

我遵循了在GoogleColab中实现YOLO的方法。 它起作用了,在照片上的物体周围显示适当的矩形。 然后我需要在30000张图片上运行它。我所做的是在循环中运行示例中的代码(参见上面的链接)(参见下面的代码)。在第260张图片之后,我得到了“内存不足”。 请帮忙

除了我添加的循环外,代码几乎与(上面的链接)相同,结果如下:

arrExtensions = ['.jpg','.jpeg','.png', '.gif']

arrCoinLocations = []

nCount = 0
for strExtension in arrExtensions:

  TEST_IMAGE_PATHS = glob.glob(working_path + "images/*" + strExtension)

  for image_path in TEST_IMAGE_PATHS:
    nCount = nCount + 1
    arrImageInfo = [image_path]

    image_np = load_image_into_numpy_array(image_path)      
      
    # Changed when trying to fight OOM  
    input_tensor = tf.cast( #convert_to_tensor(
      np.expand_dims(image_np, 0), dtype=tf.float32)
    detections, predictions_dict, shapes = detect_fn(input_tensor)

    boxes = detections['detection_boxes'][0].numpy()
    scores = detections['detection_scores'][0].numpy()
    min_score_thresh=.5
    max_boxes_to_draw=200

    print(nCount)
    #print(nCount, ": ", image_path)

    for i, box in enumerate(boxes):
      if(scores[i] < min_score_thresh or i >= max_boxes_to_draw):
        break

      ymin = box[0]
      xmin = box[1]
      ymax = box[2]
      xmax = box[3]
      #print("\t", xmin, ymin, xmax, ymax)
      #print(box)
      
      im_height, im_width = image_np.shape[:2]
      (left, top, right, bottom) = (xmin, ymin, xmax, ymax)
      #print("\t", left, top, right, bottom)

      arrImageInfo.append([int(left * im_width), int(top * im_height), int(right * im_width), int(bottom * im_height)])

#    plt.figure(figsize=(12,16))
#    plt.imshow(image_np_with_detections)
#    plt.show()

    # Flag, if the image porocessed
    arrImageInfo.append("not processed")
    arrCoinLocations.append(arrImageInfo)
arextensions=['.jpg'、'.jpeg'、'.png'、'.gif']
arrconlocations=[]
n计数=0
对于延期中的延期:
TEST_IMAGE_path=glob.glob(工作_path+“images/*”+strExtension)
对于测试图像路径中的图像路径:
nCount=nCount+1
arrImageInfo=[图像路径]
image\u np=将\u image\u加载到\u numpy\u数组(image\u路径)
#在尝试战斗时发生了变化
输入_张量=tf.cast(#将_转换为_张量(
np.expand_dims(image_np,0),dtype=tf.float32)
检测、预测、形状=检测(输入张量)
box=检测['detection_box'][0].numpy()
分数=检测['detection_scores'][0].numpy()
最小得分阈值=.5
最大箱数至绘图=200
打印(nCount)
#打印(nCount,“:”,图像路径)
对于i,枚举中的框(框):
如果(分数[i]=max\u框\u至\u绘制):
打破
ymin=box[0]
xmin=box[1]
ymax=框[2]
xmax=框[3]
#打印(“\t”、xmin、ymin、xmax、ymax)
#打印(框)
图像高度,图像宽度=图像形状[:2]
(左、上、右、下)=(xmin、ymin、xmax、ymax)
#打印(“\t”、左、上、右、下)
arrImageInfo.append([int(左*im_宽度)、int(上*im_高度)、int(右*im_宽度)、int(下*im_高度)])
#plt.图(figsize=(12,16))
#plt.imshow(带检测的图像)
#plt.show()
#标记,如果图像已处理
arrImageInfo.append(“未处理”)
arrconLocations.append(arrImageInfo)