void forward_network(network net, network_state state) { int i; for(i = 0; i < net.n; ++i){ layer l = net.layers[i]; if(l.type == CONVOLUTIONAL){ forward_convolutional_layer(l, state); } else if(l.type == DECONVOLUTIONAL){ forward_deconvolutional_layer(l, state); } else if(l.type == DETECTION){ forward_detection_layer(l, state); } else if(l.type == CONNECTED){ forward_connected_layer(l, state); } else if(l.type == CROP){ forward_crop_layer(l, state); } else if(l.type == COST){ forward_cost_layer(l, state); } else if(l.type == SOFTMAX){ forward_softmax_layer(l, state); } else if(l.type == MAXPOOL){ forward_maxpool_layer(l, state); } else if(l.type == DROPOUT){ forward_dropout_layer(l, state); } else if(l.type == ROUTE){ forward_route_layer(l, net); } state.input = l.output; } }
void forward_crnn_layer(layer_t l, network_state state) { NETWORK_STATE(s); s.train = state.train; int i; layer_t input_layer = *(l.input_layer); layer_t self_layer = *(l.self_layer); layer_t output_layer = *(l.output_layer); memset(output_layer.delta, 0, sizeof(float) * l.outputs * l.batch * l.steps); memset(self_layer.delta, 0, sizeof(float) * l.hidden * l.batch * l.steps); memset(input_layer.delta, 0, sizeof(float) * l.hidden * l.batch * l.steps); if(state.train) memset(l.state, 0, sizeof(float) * l.hidden * l.batch); for (i = 0; i < l.steps; ++i) { s.input = state.input; forward_convolutional_layer(input_layer, s); s.input = l.state; forward_convolutional_layer(self_layer, s); float *old_state = l.state; if(state.train) l.state += l.hidden*l.batch; if(l.shortcut){ fltcpy(l.state, old_state, l.hidden * l.batch); }else{ memset(l.state, 0, sizeof(float) * l.hidden * l.batch); } fltadd(l.state, input_layer.output, l.hidden * l.batch); fltadd(l.state, self_layer.output, l.hidden * l.batch); s.input = l.state; forward_convolutional_layer(output_layer, s); state.input += l.inputs*l.batch; increment_layer(&input_layer, 1); increment_layer(&self_layer, 1); increment_layer(&output_layer, 1); } }
void forward_crnn_layer(layer l, network net) { network s = net; s.train = net.train; int i; layer input_layer = *(l.input_layer); layer self_layer = *(l.self_layer); layer output_layer = *(l.output_layer); fill_cpu(l.outputs * l.batch * l.steps, 0, output_layer.delta, 1); fill_cpu(l.hidden * l.batch * l.steps, 0, self_layer.delta, 1); fill_cpu(l.hidden * l.batch * l.steps, 0, input_layer.delta, 1); if(net.train) fill_cpu(l.hidden * l.batch, 0, l.state, 1); for (i = 0; i < l.steps; ++i) { s.input = net.input; forward_convolutional_layer(input_layer, s); s.input = l.state; forward_convolutional_layer(self_layer, s); float *old_state = l.state; if(net.train) l.state += l.hidden*l.batch; if(l.shortcut){ copy_cpu(l.hidden * l.batch, old_state, 1, l.state, 1); }else{ fill_cpu(l.hidden * l.batch, 0, l.state, 1); } axpy_cpu(l.hidden * l.batch, 1, input_layer.output, 1, l.state, 1); axpy_cpu(l.hidden * l.batch, 1, self_layer.output, 1, l.state, 1); s.input = l.state; forward_convolutional_layer(output_layer, s); net.input += l.inputs*l.batch; increment_layer(&input_layer, 1); increment_layer(&self_layer, 1); increment_layer(&output_layer, 1); } }
void forward_network(network net, network_state state) { state.workspace = net.workspace; int i; for(i = 0; i < net.n; ++i){ state.index = i; layer l = net.layers[i]; if(l.delta){ scal_cpu(l.outputs * l.batch, 0, l.delta, 1); } if(l.type == CONVOLUTIONAL){ forward_convolutional_layer(l, state); } else if(l.type == DECONVOLUTIONAL){ forward_deconvolutional_layer(l, state); } else if(l.type == ACTIVE){ forward_activation_layer(l, state); } else if(l.type == LOCAL){ forward_local_layer(l, state); } else if(l.type == NORMALIZATION){ forward_normalization_layer(l, state); } else if(l.type == BATCHNORM){ forward_batchnorm_layer(l, state); } else if(l.type == DETECTION){ forward_detection_layer(l, state); } else if(l.type == CONNECTED){ forward_connected_layer(l, state); } else if(l.type == RNN){ forward_rnn_layer(l, state); } else if(l.type == GRU){ forward_gru_layer(l, state); } else if(l.type == CRNN){ forward_crnn_layer(l, state); } else if(l.type == CROP){ forward_crop_layer(l, state); } else if(l.type == COST){ forward_cost_layer(l, state); } else if(l.type == SOFTMAX){ forward_softmax_layer(l, state); } else if(l.type == MAXPOOL){ forward_maxpool_layer(l, state); } else if(l.type == AVGPOOL){ forward_avgpool_layer(l, state); } else if(l.type == DROPOUT){ forward_dropout_layer(l, state); } else if(l.type == ROUTE){ forward_route_layer(l, net); } else if(l.type == SHORTCUT){ forward_shortcut_layer(l, state); } state.input = l.output; } }
void test_convolutional_layer() { convolutional_layer l = make_convolutional_layer(1, 5, 5, 3, 2, 5, 2, 1, LEAKY, 1); l.batch_normalize = 1; float data[] = {1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 1,1,1,1,1, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 2,2,2,2,2, 3,3,3,3,3, 3,3,3,3,3, 3,3,3,3,3, 3,3,3,3,3, 3,3,3,3,3}; network_state state = {0}; state.input = data; forward_convolutional_layer(l, state); }
void forward_network(network net, network_state state) { int i; for(i = 0; i < net.n; ++i){ layer l = net.layers[i]; if(l.delta){ scal_cpu(l.outputs * l.batch, 0, l.delta, 1); } if(l.type == CONVOLUTIONAL){ forward_convolutional_layer(l, state); } else if(l.type == DECONVOLUTIONAL){ forward_deconvolutional_layer(l, state); } else if(l.type == NORMALIZATION){ forward_normalization_layer(l, state); } else if(l.type == DETECTION){ forward_detection_layer(l, state); } else if(l.type == CONNECTED){ forward_connected_layer(l, state); } else if(l.type == CROP){ forward_crop_layer(l, state); } else if(l.type == COST){ forward_cost_layer(l, state); } else if(l.type == SOFTMAX){ forward_softmax_layer(l, state); } else if(l.type == MAXPOOL){ forward_maxpool_layer(l, state); } else if(l.type == AVGPOOL){ forward_avgpool_layer(l, state); } else if(l.type == DROPOUT){ forward_dropout_layer(l, state); } else if(l.type == ROUTE){ forward_route_layer(l, net); } state.input = l.output; } }