Closed
Description
@Oceania2018 Hi Haiping, I have learn Sequential API and Functional API via book "[TensorFlow.NET实战]".
In p.106 to 114, I am tring to build same model via Sequential API and Functional API and except there are equal.
public void SampleBuildModel()
{
//UseFunctionalAPI to create Model
Model model = null;
var inputs = keras.Input(new Tensorflow.Shape(784), name: "I0");
var outputs = layers.Dense(64, activation:keras.activations.Relu).Apply(inputs);
outputs = layers.Dense(10, activation: keras.activations.Relu).Apply(outputs);
model = keras.Model(inputs, outputs, name: "MyNN");
Console.WriteLine("===== Build Model via Functional API =====");
model.summary();
//UseSequentialAPI to create Model
var sModel = keras.Sequential();
sModel.add(keras.Input(new Tensorflow.Shape(784), name: "I0"));
sModel.add(keras.layers.Dense(64, activation: keras.activations.Relu));
sModel.add(keras.layers.Dense(10, activation: keras.activations.Relu));
Console.WriteLine("===== Build Model via Sequential API =====");
sModel.summary();
}
But when I run my program, I got result below:
===== Build Model via Functional API =====
Model: MyNN
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
I0 (InputLayer) (None, 784) 0
_________________________________________________________________
dense (Dense) (None, 64) 50240
_________________________________________________________________
dense_1 (Dense) (None, 10) 650
=================================================================
Total params: 50890
Trainable params: 50890
Non-trainable params: 0
_________________________________________________________________
===== Build Model via Sequential API =====
Model: sequential
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
I0 (InputLayer) (None, 784) 0
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
Dense layer is not add to model. Am I misunderstand or Sequential is error?
by the way, when I use SequentialAPI, load_weights() can't work correctly, FunctionalAPI can work right.
Thanks for your help! ^^