# predict numeric value from images

I have two questions:

1) I have images and I must predict a continuous value.

What is the approach I must follow?

Use for example a pretrained network like this?

 last_layer = pretrained net
x = Flatten()(last_layer)
x = Dense(512, activation='relu')(x)
x = Dropout(0.4)(x)
predictions = Dense(1)(x)


So, just use a Dense layer at the end with 1 node?

and then procees to prediction as usual?

2) If I have again a numerical values to predict but it is ordinal.

If I want to go with regression in this case, can I work like in previous example?

And just assign some probabilities to the result?

If result >0 and <=0.5 then classify as 0
If result >0.5 and <=1 then classify as 1


and so on?

It seems you are doing it right. The difference between case 1) and 2) should be mainly the loss function (and maybe the activation of the predictions layer).
For 1) you would use e.g. mean_squared_error, while for 2) you would use the binary cross entropy from logits (logits are what you would feed into a sigmoid or softmax layer). In the keras-documentation it seems like keras does not provide cross entropy from logits as a loss, so you have to set the activation of predictions to sigmoid and use binary_crossentropy. I guess then you could do the If result >0 and <= 0.5 then classify as 0 ..., the result >0 would be taken care ouf by definition of the sigmoid, however you might want optimize the threshold w.r.t. the precision and recall you need.
• When training a classifier, you are training the network to assign high values if the correct label is 1, and low values if the label is 0. So you won't get 0s and 1s as outputs, but something like 0.34 or 0.73, but you still have to decide, where the threshold is, above which you decide which class it is. I assume Keras just uses 0.5, when computing the accuracy in fit, however, since the threshold is not part of the loss function, that is basically an arbitrary value. – matthiaw91 Jul 5 '19 at 9:15