高级深度学习最佳实践:Keras 函数式 API 深入解析
1. 多输出模型
在深度学习中,有时需要一个模型同时预测多个不同的属性,这就需要构建多输出模型。例如,根据一个匿名用户的社交媒体帖子来预测其年龄、性别和收入水平。
以下是使用 Keras 函数式 API 实现一个三输出模型的代码:
from keras import layers
from keras import Input
from keras.models import Model
vocabulary_size = 50000
num_income_groups = 10
posts_input = Input(shape=(None,), dtype='int32', name='posts')
embedded_posts = layers.Embedding(256, vocabulary_size)(posts_input)
x = layers.Conv1D(128, 5, activation='relu')(embedded_posts)
x = layers.MaxPooling1D(5)(x)
x = layers.Conv1D(256, 5, activation='relu')(x)
x = layers.Conv1D(256, 5, activation='relu')(x)
x = layers.MaxPooling1D(5)(x)
x = layers.Conv1D(256, 5, activation='relu')(x)
x = layers.Conv1D(256, 5, activation='relu')(x)
x = l
超级会员免费看
订阅专栏 解锁全文

14

被折叠的 条评论
为什么被折叠?



