-
Notifications
You must be signed in to change notification settings - Fork 3
/
classify.c
61 lines (50 loc) · 1.26 KB
/
classify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: Apache-2.0
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "../src/utils/fs.h"
#include <vaccel.h>
int main(int argc, char *argv[])
{
int ret;
char *image;
size_t image_size;
char out_text[512];
char out_imagename[512];
struct vaccel_session sess;
if (argc != 3) {
fprintf(stderr, "Usage: %s filename #iterations\n", argv[0]);
return 0;
}
ret = vaccel_session_init(&sess, 0);
if (ret != VACCEL_OK) {
fprintf(stderr, "Could not initialize session\n");
return 1;
}
printf("Initialized session with id: %" PRId64 "\n", sess.id);
ret = fs_file_read(argv[1], (void **)&image, &image_size);
if (ret)
goto close_session;
for (int i = 0; i < atoi(argv[2]); ++i) {
ret = vaccel_image_classification(
&sess, image, (unsigned char *)out_text,
(unsigned char *)out_imagename, image_size,
sizeof(out_text), sizeof(out_imagename));
if (ret) {
fprintf(stderr, "Could not run op: %d\n", ret);
goto close_session;
}
if (i == 0)
printf("classification tags: %s\n", out_text);
}
close_session:
free(image);
if (vaccel_session_release(&sess) != VACCEL_OK) {
fprintf(stderr, "Could not clear session\n");
return 1;
}
return ret;
}