How to use softmax activation function at the outp

2019-09-18 09:56发布

I have a neural net of 3 hidden layers (so I have 5 layers in total). I want to use Rectified Linear Units at each of the hidden layers, but at the outermost layer I want to apply Softmax on the logits. I want to use the DNNClassifier. I have read the official documentation of the TensorFlow where for setting value of the parameter activation_fn they say:

activation_fn: Activation function applied to each layer. If None, will use tf.nn.relu.

I know I can always write my own model and use any arbitrary combination of the activation functions. But as the DNNClassifier is more concrete, I want to resort to that. So far I have:

classifier = tf.contrib.learn.DNNClassifier(
  feature_columns=features_columns,
  hidden_units=[10,20,10],
  n_classes=3
  # , activation_fn:::: I want something like below
  # activation_fn = [relu,relu,relu,softmax]
)

1条回答
我命由我不由天
2楼-- · 2019-09-18 10:54

Sorry to say, but this is not possible using only one DNNClassifier. As you show in your example, you can supply an activation_fn

Activation function applied to each layer. If None, will use tf.nn.relu.

But not a seperate one for each layer. To solve your problem, you have to chain this classifier to another layer that does have the tanh actication function.

查看更多
登录 后发表回答