- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi.
I have started testing the sdk and I have verified that there is an example that does not match the version of cpp and python.
The cpp example of googlenet/Alexnet/SqueezeNet has less functionality than phyton example.
This is my proposal.
Insert in line 39 this code
// Labels family
#define LABELS_FILE_NAME "../../../data/ilsvrc12/synset_words.txt"
After de code "fp16tofloat(resultData32, (unsigned char*)resultData16, numResults);", replace from line 213 to the end whit this code.
// load labels
char category[100];
char *content = 0;
char *labels[1000];
for(int i = 0; i < 1000; i++){
labels[i] = 0;
}
FILE *f = fopen(LABELS_FILE_NAME, "rb");
if(f != NULL){
fseek(f, 0, SEEK_END);
size_t size = ftell(f);
rewind(f);
content = (char *)malloc(sizeof(char)*(size + 1));
if (content != NULL){
size_t read;
read = fread(content, sizeof(char), size, f);
fclose(f);
if(size == read){
content[size] = 0;
char * content2 = content;
char *token;
int pos = 0;
while ((token = strsep(&content2, "\n")) != NULL && pos < 1000){
labels[pos++] = token + 10;
}
}
}
}
int *results = NULL;
int totalSizeResults = 10;
int sizeResults = 0;
results = (int *)malloc(sizeof(int) * totalSizeResults);
if(results != NULL){
// we ignore all those that give a value 0
for (int index = 0; index < numResults; index++){
if (resultData32[index] > 0){
if(sizeResults == totalSizeResults){
totalSizeResults = sizeResults + 10;
results = (int*) realloc (results, totalSizeResults * sizeof(int));
if(results == NULL){
--sizeResults;
break;
}
}
results[sizeResults++] = index;
}
}
// sort descending
int tmp = 0;
for(int i=sizeResults - 1; i > 0; i--){
for(int j=i -1;j >= 0; j--){
if(resultData32[results[j]] < resultData32[results[j+1]]){
tmp=results[j+1];
results[j+1]=results[j];
results[j]=tmp;
}
}
}
// we show the categories
for(int i=0, limiteI = sizeResults; i < limiteI; i++){
printf("Category %d - %s is: %f\n", results[i], 1000 > results[i]?labels[results[i]]:"", resultData32[results[i]]);
}
if(sizeResults > 0){
sprintf(category,"%d",results[0]);
printf("The best candidate is: %s with a %f Probability\n", 1000 > results[0]?labels[results[0]]:category, resultData32[results[0]]);
}
}
if(results != NULL){
free(results);
}
if(content != NULL){
free(content);
}
}
}
retCode = mvncDeallocateGraph(graphHandle);
graphHandle = NULL;
}
free(graphFileBuf);
retCode = mvncCloseDevice(deviceHandle);
deviceHandle = NULL;
}
Link Copied
0 Replies
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page