Просто используйте Activation
, что является более стандартной и обычной практикой.
from tensorflow.keras.layers import *
from tensorflow.keras.models import Model, Sequential
import tensorflow as tf
def create_keras_model_embedding():
l = tf.keras.layers
a = l.Input(shape=(784,))
embedded_lookup_feature = tf.feature_column.numeric_column('x', shape=(784))
dense_features = l.DenseFeatures(embedded_lookup_feature)({'x': a})#{'x': a}
dense = l.Dense(784)(dense_features)
dense_2 = l.Dense(10, kernel_initializer='zeros')(dense)
output = l.Activation('softmax')(dense_2)
return tf.keras.Model(inputs=a, outputs=output)
model = create_keras_model_embedding()
model.summary()
Model: "model_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_3 (InputLayer) [(None, 784)] 0
_________________________________________________________________
dense_features_2 (DenseFeatu (None, 784) 0
_________________________________________________________________
dense_4 (Dense) (None, 784) 615440
_________________________________________________________________
dense_5 (Dense) (None, 10) 7850
_________________________________________________________________
activation_1 (Activation) (None, 10) 0
=================================================================
Total params: 623,290
Trainable params: 623,290
Non-trainable params: 0
_________________________
Если вы хотите использовать softmax, используйте axis=-1
.
from tensorflow.keras.layers import *
from tensorflow.keras.models import Model, Sequential
import tensorflow as tf
def create_keras_model_embedding():
l = tf.keras.layers
a = l.Input(shape=(784,))
embedded_lookup_feature = tf.feature_column.numeric_column('x', shape=(784))
dense_features = l.DenseFeatures(embedded_lookup_feature)({'x': a})#{'x': a}
dense = l.Dense(784)(dense_features)
dense_2 = l.Dense(10, kernel_initializer='zeros')(dense)
output = l.Softmax(axis=-1)(dense_2)
return tf.keras.Model(inputs=a, outputs=output)
model = create_keras_model_embedding()
model.summary()
Model: "model_2"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_4 (InputLayer) [(None, 784)] 0
_________________________________________________________________
dense_features_3 (DenseFeatu (None, 784) 0
_________________________________________________________________
dense_6 (Dense) (None, 784) 615440
_________________________________________________________________
dense_7 (Dense) (None, 10) 7850
_________________________________________________________________
softmax_1 (Softmax) (None, 10) 0
=================================================================
Total params: 623,290
Trainable params: 623,290
Non-trainable params: 0