demo
demo

Reputation: 441

Use CNN for regression task in Keras

I want to use CNN for regression problem (Keras, TF backend). It's possible by simply change last layer (Dense) activations to linear and use euclidean distance as loss function ?

Upvotes: 3

Views: 1988

Answers (2)

GuangshengZuo
GuangshengZuo

Reputation: 4687

What you mean change the last activation to linear is actually just no activation, if you set the activation = None, then the last layer will be a linear layer. see keras dense layer:

keras.layers.Dense(units, activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

And the euclidean distance as loss function is actually same as mean_squared_error. euclidean distance is just sqrt(mean_squared_error), so it is same.

Upvotes: 2

Dr. Snoopy
Dr. Snoopy

Reputation: 56367

Yes, but you need to use a linear output, you can also normalize the outputs and use a sigmoid activation. Then you use a mean squared error loss.

Upvotes: 1

Related Questions