python - 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 之前,每次调用同一个网络(甚至是引擎的新实例)都会产生相同的输出。
解决方案
推荐阅读
- amazon-web-services - AWS如何在自动上传视频后触发媒体转换
- apache-spark - Spark operator vs spark submit - 如何选择使用哪一个?
- entity-framework-core - 将表值参数传递给 EF Core 查询
- javascript - 另一个项目中的 Firebase 身份验证
- typescript - 使用动态键在 Typescript 中动态创建对象,无需将类型扩展为 { [key: string]: T }
- blazor - 无法使用子目录直接访问 Azure 静态应用中托管的 Blazor WASM
- calculator - 需要创建 GPA 计算器才能在命令行中运行
- dependency-injection - 控制反转和深度依赖
- docker - 有谁知道如何通过 Puppet manifest 安装 docker 和 docker-compose
- c - 指针非法访问 PIC32 上的数组