Convulational neural network to predict a number

Hello, I have a database of images where every image is represented by a number, eg. color entropy calculated for that image. I am trying to train a CNN by giving to the network an image and the corresponding number to it and I’m expecting after the train is done to have a CNN that will see an image and predict me a number(eg. color entropy). Can anyone give me ideas? ( I am new to pytorch and I can’t fiind anything similar to this in tutorials). How to train the network so that it can estimate me a number after the CNN gets an image as an input?

Hi Public!

Let’s say your images are 256x256 pixels, and each pixel is
given by an rgb value made up of three 8-bit bytes. Therefore
each image is given by 196608 numerical (8-bit) values. Convert
these to floats.

Because your example of color entropy doesn’t care about the
structure of the image, that is, whether two given pixels are
close to one another or far apart, convolutional layers won’t add
any value. (However, the fact that the three color components
of a given pixel are naturally grouped together is something you
might want to build into the structure of your network, rather than
having your network learn.)

So you might try a simple, single-hidden-layer network – something
like this:

Have 512 hidden neurons. So you start with a fully-connected
layer (nn.Linear (166608, 512)), followed by nonlinear
activations (e.g., nn.ReLU() or nn.Tanh()), followed by a
second fully-connected layer with a single output
(nn.Linear (512, 1)). You would most likely use the square
of the difference between your predicted and known color entropy
as your loss function (nn.MSELoss()).

My gut tells me that color entropy might be hard for a network to
learn. As a practical matter, if what you need is the color entropy
of an image, it will be much more satisfactory – faster, more
accurate – simply to calculate it directly, rather than predict it
with a network.

Good luck.

K. Frank

1 Like