tipe/src/cnn/make.c

56 lines
1.8 KiB
C
Raw Normal View History

2022-07-05 08:13:25 +02:00
#include <stdio.h>
2022-09-28 10:20:08 +02:00
#include "../colors.h"
2022-09-16 14:53:35 +02:00
#include "include/make.h"
2022-07-05 08:13:25 +02:00
void make_convolution(float*** input, Kernel_cnn* kernel, float*** output, int output_dim) {
2022-09-28 10:20:08 +02:00
printf_warning("Appel de make_convolution, incomplet\n");
2022-07-05 08:13:25 +02:00
float f;
int n = kernel->k_size;
for (int i=0; i < kernel->columns; i++) {
for (int j=0; j < output_dim; j++) {
for (int k=0; k < output_dim; k++) {
2022-07-05 08:13:25 +02:00
f = kernel->bias[i][j][k];
for (int a=0; a < kernel->rows; a++) {
for (int b=0; b < n; b++) {
for (int c=0; c < n; c++) {
2022-07-05 08:13:25 +02:00
f += kernel->w[a][i][b][c]*input[a][j+a][k+b];
}
}
}
output[i][j][k] = f;
}
}
}
}
void make_average_pooling(float*** input, float*** output, int size, int output_depth, int output_dim) {
2022-09-26 18:00:31 +02:00
// TODO, MISS CONDITIONS ON THE POOLING
2022-09-28 10:20:08 +02:00
printf_warning("Appel de make_average_pooling, incomplet\n");
2022-07-05 08:13:25 +02:00
float average;
int n = size*size;
for (int i=0; i < output_depth; i++) {
for (int j=0; j < output_dim; j++) {
for (int k=0; k < output_dim; k++) {
2022-07-05 08:13:25 +02:00
average = 0.;
for (int a=0; a < size; a++) {
for (int b=0; b < size; b++) {
2022-07-05 08:13:25 +02:00
average += input[i][2*j +a][2*k +b];
}
}
2022-09-19 18:39:49 +02:00
output[i][j][k] = average/n;
2022-07-05 08:13:25 +02:00
}
}
}
}
void make_fully_connected(float* input, Kernel_nn* kernel, float* output, int size_input, int size_output) {
float f;
for (int i=0; i < size_output; i++) {
2022-07-05 08:13:25 +02:00
f = kernel->bias[i];
for (int j=0; j < size_input; j++) {
2022-07-05 08:13:25 +02:00
f += kernel->weights[i][j]*input[j];
}
output[i] = f;
}
}