attractivechaos / kann

A lightweight C library for artificial neural networks
Other
678 stars 117 forks source link

Image classification of cats, dogs, and pandas #50

Open mjswartz3141 opened 2 years ago

mjswartz3141 commented 2 years ago

I am attempting to use KANN to classify cats, dogs, and pandas. I have the data pre-processed such that it reads every image in as RGB byte, scales to float, and resizes to 32x32 (3 channel still). I store the image and labels as float x, float y, where the dimension of x is [nsamples][32x32x3] (formatted as a flattened array with rows = ncols * 3 laid out as RGB per pixel) and y is [nsamples][3] (for the 3 classes of cat/dog/panda). I split my data into a 75% train and send it into a modified version of the "Complete Example" provided:

int train_kann(float **x, int nrows, int ncols, int nbands, float **y, int nclasses, int n_samples)
{
    int max_bit, i;
    kad_node_t *t;
    kann_t *ann;

    max_bit = nrows * ncols * nbands;

    // construct an MLP with one hidden layers
    t = kann_layer_input(max_bit);
    t = kad_relu(kann_layer_dense(t, 64));
    t = kann_layer_cost(t, nclasses, KANN_C_CEM); // output uses 1-hot encoding
    ann = kann_new(t, 0);

    // train
    kann_train_fnn1(ann, 0.001f, 64, 50, 10, 0.1f, n_samples, x, y);

    return 0;
}

However I am getting some strange output from kann_train_fnn1. It is not reporting the class error in training or validation, so I am getting n_train_base == 0 and n_val == 0 (meaning no class error?).

epoch: 1; training cost: 13.2655; validation cost: 13.8155
epoch: 2; training cost: 13.8112; validation cost: 13.8155
epoch: 3; training cost: 13.8155; validation cost: 13.8155
epoch: 4; training cost: 13.8155; validation cost: 13.8155
(repeats these values for the remaining epochs)

I have a feeling this is an issue of how I set up my data and labels. Any help would be greatly appreciated.