Joseph Redmon
2013-11-04 41bcfac86fa4dc856f3d1894efeee0f55f86f7b0
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
#include "network.h"
#include "image.h"
 
#include "connected_layer.h"
#include "convolutional_layer.h"
#include "maxpool_layer.h"
 
void run_network(image input, network net)
{
    int i;
    double *input_d = 0;
    for(i = 0; i < net.n; ++i){
        if(net.types[i] == CONVOLUTIONAL){
            convolutional_layer layer = *(convolutional_layer *)net.layers[i];
            run_convolutional_layer(input, layer);
            input = layer.output;
            input_d = layer.output.data;
        }
        else if(net.types[i] == CONNECTED){
            connected_layer layer = *(connected_layer *)net.layers[i];
            run_connected_layer(input_d, layer);
            input_d = layer.output;
        }
        else if(net.types[i] == MAXPOOL){
            maxpool_layer layer = *(maxpool_layer *)net.layers[i];
            run_maxpool_layer(input, layer);
            input = layer.output;
            input_d = layer.output.data;
        }
    }
}
 
image get_network_image(network net)
{
    int i;
    for(i = net.n-1; i >= 0; --i){
        if(net.types[i] == CONVOLUTIONAL){
            convolutional_layer layer = *(convolutional_layer *)net.layers[i];
            return layer.output;
        }
        else if(net.types[i] == MAXPOOL){
            maxpool_layer layer = *(maxpool_layer *)net.layers[i];
            return layer.output;
        }
    }
    return make_image(1,1,1);
}