machine-learning - 如何在火炬张量中检索 x 和 y 坐标?
问题描述
我正在使用 mobilenetv2 模型。所以我正在使用检测并且我能够获得分数(一个对象与训练集列表上的某物的相似程度)和对象名称。我只需要弄清楚如何获取 x 和 y 坐标以及检测的宽度和高度。我提供了一个实时示例(作为注释),说明变量在整个运行时过程中的样子。我正在处理 [3, 224, 224] 的张量形状
const ImageFrame& frame =
cc->Inputs().Index(0).Value().Get<ImageFrame>();
auto tensor = ImageFrameToNormalizedTensor(frame, 0, 255.);
std::vector<torch::jit::IValue> inputs;
inputs.push_back(tensor->unsqueeze(0));
// tensor->unsqueeze(0).sizes() = [1, 3, 224, 224]
auto result = model.forward(inputs).toTensor();
result = result.squeeze(0);
// result.argmax(0) = 733
// result.index({result.argmax(0)}) = 7.50187
auto output_detections = absl::make_unique<Detections>();
const auto class_id = result.argmax(0).item<int>();
const auto score = result.index({result.argmax(0)}).item<float>();
Detection detection;
detection.add_label_id(class_id);
detection.add_score(score);
我能够获得 class_id 和分数。谁能指导我如何获得 x、y、w(宽度)和 h(高度)。
解决方案
推荐阅读
- excel - 有没有更聪明的方法来解决几个列
- facebook - 如何根据产品类别展示 Facebook 广告?
- jenkins - Jenkins Pipeline 不执行下一阶段
- azure - 我可以使用 azure devops 创建一个 azure 应用吗
- elasticsearch - ElasticSearch 源过滤对象数组
- c# - 无法使用 .NET API v2.0 在 VZAAR 上上传视频?
- webpack - 如何将 ckeditor gem 与 Rails 6 + Webpacker 集成?
- php - 在除 default_controller 之外的所有控制器上出现错误 404
- mongodb - 为日期创建一个自动化函数
- python - 在PyQt5 for QtWidget中按下角落的红色x按钮时如何处理/覆盖?