C++ ';无效参数:输出维度必须为正';在TensorFlow API中使用批处理时
对于视频中的目标检测,我们使用大小大于1的批处理。但在视频结束时,当剩下的帧数小于批处理大小时,我们得到以下错误:C++ ';无效参数:输出维度必须为正';在TensorFlow API中使用批处理时,c++,tensorflow,C++,Tensorflow,对于视频中的目标检测,我们使用大小大于1的批处理。但在视频结束时,当剩下的帧数小于批处理大小时,我们得到以下错误: 2018-06-07 15:31:26.456907: W tensorflow/core/framework/op_kernel.cc:1290] CtxFailure at image_resizer_state.h:84: Invalid argument: output dimensions must be positive 为了阅读我们使用Opencv 3.3.0的视频
2018-06-07 15:31:26.456907: W tensorflow/core/framework/op_kernel.cc:1290] CtxFailure at image_resizer_state.h:84: Invalid argument: output dimensions must be positive
为了阅读我们使用Opencv 3.3.0的视频,帧存储在vectorbatch
for (size_t i = 0; i < batch_size; i++) {
ret = cap.read(readImage);
if (!ret) {
break;
}
batch.push_back(readImage.clone());
}
for(大小i=0;i
该向量转化为tf张量,如下所示:
tensorflow::Tensor inputImg(
tensorflow::DT_UINT8,
tensorflow::TensorShape(
{static_cast<long long int>(batch.size()), height, width, depth}));
for (size_t i = 0; i < batch.size(); i++) {
auto tmp = inputImg.Slice(i, i + 1);
uint8_t *p = tmp.flat<uint8_t>().data();
cv::Mat cameraImg(height, width, CV_8UC3, p);
batch[i].convertTo(cameraImg, CV_8UC3);
}
tensorflow::Tensor inputImg(
tensorflow::DT_UINT8,
tensorflow::TensorShape(
{static_cast(batch.size()),高度、宽度、深度});
对于(size_t i=0;i
您可以注意到,Tensor是用实际批次的大小初始化的,因此它在视频开始时包含定义数量的图像,在视频结束时包含较少的图像
然后我们运行“探测器”
std::向量输出张量;
tensorflow::状态=
session->Run({“image\u tensor:0”,inputImg}},{“detection\u box:0”,“detection\u scores:0”,
“检测类:0”,“数量检测:0”},{},&输出张量);
最后出现错误(status.ok()==False
并显示所述消息)
因此,在整个视频过程中,我们没有错误,但例如,当只剩下2张图像时(因此,向量批的大小为2),而之前的批大小为5,我们有错误,并且输出张量的大小为0。我们尝试在每次迭代中随机改变批次大小来运行检测器,当当前批次的大小与前一批次的大小不同时,没有错误,它只发生在视频的末尾
如果我们选择批量大小,则
视频大小%batch\u大小==0
错误也不会发生
我们使用从(master
branch)构建的TF
有人知道这个问题的解决办法吗
std::vector<tensorflow::Tensor> output_tensors;
tensorflow::Status status =
session->Run({{"image_tensor:0", inputImg}}, {"detection_boxes:0", "detection_scores:0",
"detection_classes:0", "num_detections:0"}, {}, &output_tensors);