numpy - 火炬挤压,狭窄,切片?
问题描述
我有一组图像,我在这些图像上运行深度学习模型,以在 pytorch 中获得一些预测张量。这里有关于张量和形状/重塑的好的新手教程吗?
x = prediction['masks']
我知道的这个对象包含对象检测预测的掩码。但我不清楚如何一次提取一个掩码以将该掩码乘以我刚刚运行推理的图像。
我现在只是在整批中使用 1 张图像来玩。但一开始的第 0 维让我离开了这里。我看着尝试torch.squeeze(x,0)
但没有任何作用
最后,我只想将我的掩码作为一个opencv或numpy数组/矩阵..在推理测试图像上像这样..
dst = opencvimage * mask_img
cv2.imshow('image', dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
opencvimage 是一种ndarray: (9212,1631,3)
听起来很合理的 RGB 或 BGR 格式。
编辑 - 添加张量的制作方式
这是重要的评分功能..当我打包张量以摆脱0th dim
形状轴时,听起来我应该在这里摆弄
images = ImageDataset(paths_to_images, transform=transform)
loader = torch.utils.data.DataLoader(images, batch_size=1, num_workers=1)
all_predictions = []
with torch.no_grad():
for batch in loader:
predictions = list(model(batch.to(device)))
for prediction in predictions:
all_predictions.append(prediction)
# Take predictions and masks and draw on the images
return predictions
现在阅读它..似乎对面具的预测是空的..这意味着我需要重新访问我认为的教程..或者我是如何加载东西的
我添加了一张支票来查看这些盒子。它们看起来也是空的??
解决方案
推荐阅读
- .net - 如何在控制台应用程序中模拟 Internet Explorer url 编码
- sql - 当我尝试将值插入表时,错误消息 SQL 命令未正确结束
- sql - 使用 Ansible 设置不同的 ORACLE_HOME 和 PATH 环境变量
- java - Java 输入中最长的单词
- java - 无法在 Oracle 上加载 java 并且 dbms_java.grant_permission 不起作用
- c# - 类的实例变量不能调用?
- javascript - 连续第一个元素后不需要的空间
- sql-server - 是否可以使用 T-SQL 为 Always Encrypted 列加密数据?
- javascript - 我可以使用 pactjs 测试通过事件流和消息队列进行通信的微服务吗?
- python - 从 pandas datafrmae 开始有条件地删除行