lasso-net / lassonet

Feature selection in neural networks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lassonet Python library data input

GoldengateOggy opened this issue · comments

Dear Devs,

My name is Dufot Nicolas, working on picture classification using neural networks (with PyTorch).
I found your publication "LassoNet: A Neural Network with Feature Sparsity" very interesting and your function LassoNetClassifier is very useful to prioritize pixels and identify informative sub parts of the image for complex pictures classification.

I took mnist_classif.py script in the example folder in the aim to adapt the LassoNetClassifier to my pictures datas.
I have understand the numpy array X_train, X_test, y_train, y_test input with X for the pixels datas and y for the classification labels.

In the mnist_classif.py, datas in X_train and X_test are mono channel pixels (black and white MNIST dataset).
The data looks like this: [ [pixels datas for picture 1] [pixels datas for picture 2] ... [pixel datas for picture n] ]
I.E: a list of pictures presented as a list of pixels values.

This is working for mono channel pixels, the question is: how to insert into this my 3 channels colored pictures ?

My datas look like: [ [[ pixels datas for channel 1 picture 1 ] [ pixels datas for channel 2 picture 1 ] [ pixels datas for channel 3 picture 1 ]] ... [[ pixels datas for channel 1 picture n ] [ pixels datas for channel 2 picture n ] [ pixels datas for channel 3 picture n ]]]
IE: A list of pictures presented as 3 sub lists detailing 3 values per pixels, one value per channels. This is the standard datas presentation using PyTorch

How to deal with it ?

Second question, linked to the first: how to specify network parameters using LassoNetClassifier ? how to make it work with my dataset ?

Actually, when I try to use LassoNetClassifier with my arrays, the error "RuntimeError: mat1 and mat2 shapes cannot be multiplied (2436x28 and 3x2)" occurs. I have seen this error many times with PyTorch, this is due to bad shape parameters for the different neuronal layers, which also depend on the image input size and channels numbers (you see the link with first question)
So, configuration of the neuronal network needs to be adapted to my dataset (higher image size than in MNIST dataset).

Have a nice day,
Cordially.

Did you try reshaping your input to be (samples, dimensions)? Each sample should be a vector.

Thank you for your quick answer.
When you say "samples", you talk about one vector by samples or more ?
Colored pixels are 3 vectors samples !

I made some test with your tool by converting my colored dataset into black and white pixels (one vector). It is working well but loosing some infomations as colors are important in my study.

Hope we will find a solution to deal with colored datasets.
Cordially,

One vector per sample. An image is hwc with c being 3 (channels). You should "flatten" it to be a one dimensional vector. Your final matrix has shape (n, hwc)