forked from imaculate/Face-Recognition-Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
imagenet.c
75 lines (61 loc) · 1.96 KB
/
imagenet.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
******************************************************************
* HISTORY
* 15-Oct-94 Jeff Shufelt (js), Carnegie Mellon University
* Prepared for 15-681, Fall 1994.
*
******************************************************************
*/
#include <stdio.h>
#include <pgmimage.h>
#include <backprop.h>
extern void exit();
#define TARGET_HIGH 0.9
#define TARGET_LOW 0.1
/*** This is the target output encoding for a network with one output unit.
It scans the image name, and if it's an image of me (js) then
it sets the target unit to HIGH; otherwise it sets it to LOW.
Remember, units are indexed starting at 1, so target unit 1
is the one to change.... ***/
load_target(img, net)
IMAGE *img;
BPNN *net;
{
int scale;
char userid[40], head[40], expression[40], eyes[40], photo[40];
userid[0] = head[0] = expression[0] = eyes[0] = photo[0] = '\0';
/*** scan in the image features ***/
sscanf(NAME(img), "%[^_]_%[^_]_%[^_]_%[^_]_%d.%[^_]",
userid, head, expression, eyes, &scale, photo);
if (!strcmp(userid, "glickman")) {
net->target[1] = TARGET_HIGH; /* it's me, set target to HIGH */
} else {
net->target[1] = TARGET_LOW; /* not me, set it to LOW */
}
}
/***********************************************************************/
/********* You shouldn't need to change any of the code below. *******/
/***********************************************************************/
load_input_with_image(img, net)
IMAGE *img;
BPNN *net;
{
double *units;
int nr, nc, imgsize, i, j, k;
nr = ROWS(img);
nc = COLS(img);
imgsize = nr * nc;;
if (imgsize != net->input_n) {
printf("LOAD_INPUT_WITH_IMAGE: This image has %d pixels,\n", imgsize);
printf(" but your net has %d input units. I give up.\n", net->input_n);
exit (-1);
}
units = net->input_units;
k = 1;
for (i = 0; i < nr; i++) {
for (j = 0; j < nc; j++) {
units[k] = ((double) img_getpixel(img, i, j)) / 255.0;
k++;
}
}
}