mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-23 23:26:25 +01:00
Add cnn/preview.c
This commit is contained in:
parent
715f550a49
commit
cfb3cb28d7
5
Makefile
5
Makefile
@ -63,7 +63,7 @@ $(BUILDDIR)/mnist_%.o: $(MNIST_SRCDIR)/%.c $(MNIST_SRCDIR)/include/%.h
|
|||||||
#
|
#
|
||||||
# Build cnn
|
# Build cnn
|
||||||
#
|
#
|
||||||
cnn: $(BUILDDIR)/cnn-main $(BUILDDIR)/cnn-main-cuda;
|
cnn: $(BUILDDIR)/cnn-main $(BUILDDIR)/cnn-main-cuda $(BUILDDIR)/cnn-preview;
|
||||||
|
|
||||||
$(BUILDDIR)/cnn-main: $(CNN_SRCDIR)/main.c $(BUILDDIR)/cnn_train.o $(BUILDDIR)/cnn_cnn.o $(BUILDDIR)/cnn_creation.o $(BUILDDIR)/cnn_initialisation.o $(BUILDDIR)/cnn_make.o $(BUILDDIR)/cnn_neuron_io.o $(BUILDDIR)/cnn_function.o $(BUILDDIR)/cnn_utils.o $(BUILDDIR)/cnn_update.o $(BUILDDIR)/cnn_free.o $(BUILDDIR)/cnn_jpeg.o $(BUILDDIR)/cnn_convolution.o $(BUILDDIR)/cnn_backpropagation.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o
|
$(BUILDDIR)/cnn-main: $(CNN_SRCDIR)/main.c $(BUILDDIR)/cnn_train.o $(BUILDDIR)/cnn_cnn.o $(BUILDDIR)/cnn_creation.o $(BUILDDIR)/cnn_initialisation.o $(BUILDDIR)/cnn_make.o $(BUILDDIR)/cnn_neuron_io.o $(BUILDDIR)/cnn_function.o $(BUILDDIR)/cnn_utils.o $(BUILDDIR)/cnn_update.o $(BUILDDIR)/cnn_free.o $(BUILDDIR)/cnn_jpeg.o $(BUILDDIR)/cnn_convolution.o $(BUILDDIR)/cnn_backpropagation.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o
|
||||||
$(CC) $^ -o $@ $(CFLAGS)
|
$(CC) $^ -o $@ $(CFLAGS)
|
||||||
@ -75,6 +75,9 @@ else
|
|||||||
$(NVCC) $(NVCCFLAGS) $^ -o $@
|
$(NVCC) $(NVCCFLAGS) $^ -o $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
$(BUILDDIR)/cnn-preview: $(CNN_SRCDIR)/preview.c $(BUILDDIR)/cnn_jpeg.o $(BUILDDIR)/colors.o
|
||||||
|
$(CC) $^ -o $@ $(CFLAGS)
|
||||||
|
|
||||||
$(BUILDDIR)/cnn_%.o: $(CNN_SRCDIR)/%.c $(CNN_SRCDIR)/include/%.h
|
$(BUILDDIR)/cnn_%.o: $(CNN_SRCDIR)/%.c $(CNN_SRCDIR)/include/%.h
|
||||||
$(CC) -c $< -o $@ $(CFLAGS)
|
$(CC) -c $< -o $@ $(CFLAGS)
|
||||||
|
|
||||||
|
51
src/cnn/preview.c
Normal file
51
src/cnn/preview.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "include/jpeg.h"
|
||||||
|
|
||||||
|
|
||||||
|
void print_image(unsigned char* image, int height, int width) {
|
||||||
|
|
||||||
|
for (int i=0; i < (int)width; i++) {
|
||||||
|
for (int j=0; j < (int)height; j++) {
|
||||||
|
printf("\x1b[38;2;%d;%d;%dm#\x1b[0m", image[((i*width)+j)*3 + 0], image[((i*width)+j)*3 + 1], image[((i*width)+j)*3 + 2]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void preview_images(char* path, int limit) {
|
||||||
|
jpegDataset* dataset = loadJpegDataset(path);
|
||||||
|
imgRawImage* image;
|
||||||
|
|
||||||
|
if (limit == -1) {
|
||||||
|
limit = dataset->numImages;
|
||||||
|
}
|
||||||
|
for (int i=0; i < limit; i++) {
|
||||||
|
printf("--- Image %d : %d ---\n", i, dataset->labels[i]);
|
||||||
|
|
||||||
|
if (!dataset->images[i]) {
|
||||||
|
image = loadJpegImageFile(dataset->fileNames[i]);
|
||||||
|
dataset->images[i] = image->lpData;
|
||||||
|
free(image);
|
||||||
|
}
|
||||||
|
print_image(dataset->images[i], dataset->height, dataset->width);
|
||||||
|
|
||||||
|
free(dataset->images[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc < 2) {
|
||||||
|
printf("Utilisation: %s [DIRECTORY] (opt:nombre d'images)\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int limit = -1;
|
||||||
|
if (argc > 2) {
|
||||||
|
limit = strtol(argv[2], NULL, 10);
|
||||||
|
}
|
||||||
|
preview_images(argv[1], limit);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user