首页 > 解决方案 > Coral 模型返回损坏的数据,直到结果被 python 释放

问题描述

我们将珊瑚棒与我们创建的自定义网络一起使用(基于 vgg 作为主干)。我们使用的 edge-tpu 版本是 2.11

网络返回 2 个输出:形状 1*12*12*65 和 1*12*12*256。我们从 python 调用这样的网络:

def _run_net(self, crop : np.ndarray):

    orig_w = crop.shape[1]
    orig_h = crop.shape[0]

    if orig_w != WIDTH or orig_h != HEIGHT:
        crop = cv2.resize(crop, (WIDTH, HEIGHT))
    image = crop.reshape(1, HEIGHT, WIDTH, 1)


    all_data = self.engine.RunInference(image.flatten())[1]
    tensor_sizes = self.engine.get_all_output_tensors_sizes()
    num_points = int(math.sqrt(tensor_sizes[0] / 65))
    raw_points = all_data[:tensor_sizes[0]]
    raw_points = raw_points.reshape((1, num_points, num_points, 65))
    raw_descriptors = all_data[tensor_sizes[0]:]
    raw_descriptors = raw_descriptors.reshape((1, num_points, num_points, 256))
    #Imprtant Note! the copy of raw points and desc here is a must, because as long as memory is held the net always return
    #the same results!!! this seems to be a bug in coral

    return (raw_points, raw_descriptors, orig_w, orig_h) #does not work

    #return (np.copy(raw_points), np.copy(raw_descriptors), orig_w, orig_h) #works ok!

似乎直到 python 在 raw_points 和 raw_descriptors 上调用 gc 之前,每次调用同一个网络(甚至是引擎的新实例)都会产生相同的输出。

标签: pythontensorflowtensorflow-litegoogle-coral

解决方案


推荐阅读