placeholder 和 sequential
来源:2-6 数据处理与模型图构建(2)

qq_慕沐932272
2020-03-07
老师请问 这两个作用是不是挺像的 像一个容器
写回答
1回答
-
正十七
2020-03-08
不一样。
placeholder是tensorflow1.* 版本中用来给输入用的占位符,而sequential是tf.keras里用来包装模型用的,tf.keras在1.13之后被引入,在tf2.0里被主推。
看一个sequential的样例代码,
model = keras.models.Sequential([ keras.layers.Flatten(input_shape=[28, 28]), keras.layers.Dense(300, activation='relu'), keras.layers.Dense(100, activation='relu'), keras.layers.Dense(10, activation='softmax') ]) # relu: y = max(0, x) # softmax: 将向量变成概率分布. x = [x1, x2, x3], # y = [e^x1/sum, e^x2/sum, e^x3/sum], sum = e^x1 + e^x2 + e^x3 # reason for sparse: y->index. y->one_hot->[] model.compile(loss="sparse_categorical_crossentropy", optimizer = keras.optimizers.SGD(0.001), metrics = ["accuracy"]) history = model.fit(x_train, y_train, epochs=10, validation_data=(x_valid, y_valid))
在我的另一门课《tensorflow2.0》中,有tensorflow 2.0使用的详细讲解,感兴趣可以关注一下:https://coding.imooc.com/class/344.html
00
相似问题