如何在自定义图像上测试cntk对象检测示例?

时间:2017-02-26 16:14:45

标签: neural-network object-detection cntk

我正在尝试在PascalVoc预训练数据集上运行CNTK对象检测示例。我在fastrcnn中运行所有必需的脚本,并获取数据集中定义的测试数据的可视输出。现在我想在我自己的图像上测试网络,我该怎么做?

2 个答案:

答案 0 :(得分:0)

对于快速R-CNN,您需要一个库,为您的测试图像生成候选ROI(感兴趣的区域),例如: selective search

如果您想评估一批图片,可以按照tutorial中的说明生成测试映射文件和ROI坐标(请参阅相应的test.txttest.rois.txt proc子文件夹)。如果要评估单个图像,则需要将图像和候选ROI坐标作为cntk eval的输入传递,类似于this example

# compute model output 
arguments = {loaded_model.arguments[0]: [hwc_format]} 
output = loaded_model.eval(arguments) 

答案 1 :(得分:0)

对于FastRCNN,您需要首先通过选择性搜索算法运行自定义图像以生成ROI(感兴趣的区域),然后将其提供给您的模型,如下所示:

using namespace std; int m, n; string walls(int a){ // west north east south if(a == 1){ return "1000"; } else if(a == 2){ return "0100"; } else if(a == 3){ return "1100"; } else if(a == 4){ return "0010"; } else if(a == 5){ return "1010"; } else if(a == 6){ return "0110"; } else if(a == 7){ return "1110"; } else if(a == 8){ return "0001"; } else if(a == 9){ return "1001"; } else if(a == 10){ return "0101"; } else if(a == 11){ return "1101"; } else if(a == 12){ return "0011"; } else if(a == 13){ return "1011"; } else if(a == 14){ return "0111"; } else{ return "1111"; } } //checking if a square isn't just four walls bool isOpen(string s){ if(s.find('0') != string::npos){ return true; } return false; } bool isRight(string x, string y){ //if there's a east well open for x, y must have a west wall open if((x[2] == '0')&&(y[0] == '0')){ return true; } return false; } bool isDown(string x, string y){ //if there's a south wall open for x, y must have a north wall open if((x[3] == '0')&&(y[1] == '0')){ return true; } return false; } //size of the room that you're finding the path in int roomSize = 0; string seenCoords; int findPath(string modules[n][m], int i, int j){ if((i < n)&&(j < m)){ if(isOpen(modules[i][j])){ //use dashes to keep track of ij coords //13-15-23- //13 15 and 23 are considered ij coords //checking whether square i,j has been seen before if(seenCoords.find(to_string(i) + to_string(j) + "-") == string::npos){ //add the coords to the ones you've already seen seenCoords += to_string(i) + to_string(j) + "-"; roomSize++; if(isRight(modules[i][j], modules[i+1][j])){ roomSize += findPath(modules, i+1, j); } if(isDown(modules[i][j], modules[i][j+1])){ roomSize += findPath(modules, i, j+1); } } } } //last char in string is the room size return roomSize; } int main(){ ifstream fin("castle.in"); ofstream fout("castle.out"); fin >> m >> n; string modules[n][m]; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ int a; fin >> a; modules[i][j] = walls(a); } } int roomCount, largestRoom = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ //if it's not just four walls if(isOpen(modules[i][j])){ //if you haven't seen the square i, j before if(seenCoords.find(to_string(i) + to_string(j) + "-") == string::npos){ //recurse on the square and find all the paths off it roomSize = findPath(modules, i, j); roomCount++; if(roomSize > largestRoom){ largestRoom = seenCoords[seenCoords.length()-1]; } roomSize = 0; } } else{ //if it's not open it's just made of four walls roomCount++; if(largestRoom < 1){ largestRoom = 1; } } } } }

您可以在此处找到更多详细信息:https://github.com/Microsoft/CNTK/tree/release/latest/Examples/Image/Detection/FastRCNN

无论如何,由于使用选择性搜索(这是一个真正的瓶颈),FastRCNN不是最有效的方法。如果你想提高性能,你可以尝试FasterRCNN,因为它摆脱了SS算法,并用Region Proposal Network取代它,它可以做得更好。 如果您有兴趣,可以在GitHub上查看我的回购:https://github.com/karolzak/CNTK-Hotel-pictures-classificator