以下是我编写的代码片段:
int n,i,j;
map<int,int>mp;
vector<int>vec;
cin>>n;
for(i=0; i<n; i++)
{
cin>>j;
mp[j]==0? mp[j]=1,vec.push_back(j): mp[j]=1;
}
Run Code Online (Sandbox Code Playgroud)
对于for循环内的第二行,CodeBlocks-16.01 版本显示以下错误:
second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'
Run Code Online (Sandbox Code Playgroud)
但是当我将行更改为:
second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'
Run Code Online (Sandbox Code Playgroud)
没有错误。以下行有什么问题?
mp[j]==0? vec.push_back(j), mp[j]=1: mp[j]=1;
Run Code Online (Sandbox Code Playgroud) 我有一个faces列表,其中列表的每个元素都是一个形状为 ( 1, 224, 224, 3) 的 numpy 数组,即人脸图像。我有一个模型,其输入形状为(None, 224, 224, 3),输出形状为(None, 2)。
现在我想对faces列表中的所有图像进行预测。当然,我可以遍历列表并一个一个地得到预测,但我想将所有图像作为一个批次处理,只使用一次调用来model.predict()更快地获得结果。
如果我像现在这样直接传递人脸列表(最后是完整的代码),我只会得到第一张图像的预测。
print(f"{len(faces)} faces found")
print(faces[0].shape)
maskPreds = model.predict(faces)
print(maskPreds)
Run Code Online (Sandbox Code Playgroud)
输出:
3 faces found
(1, 224, 224, 3)
[[0.9421933 0.05780665]]
Run Code Online (Sandbox Code Playgroud)
但是maskPreds对于 3 个图像应该是这样的:
[[0.9421933 0.05780665],
[0.01584494 0.98415506],
[0.09914105 0.9008589 ]]
Run Code Online (Sandbox Code Playgroud)
完整代码:
print(f"{len(faces)} faces found")
print(faces[0].shape)
maskPreds = model.predict(faces)
print(maskPreds)
Run Code Online (Sandbox Code Playgroud)
注意:如果我不将每个图像从 (224, 224, 3) 转换为 ( 1, 224, 224, 3),tensorflow 会抛出错误,指出输入维度不匹配。
ValueError: Error when checking …Run Code Online (Sandbox Code Playgroud)