作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了这个模型
num_items = 1250
num_users = 1453
emb_size = 64
input_userID = Input(shape=[1], name='user_ID')
input_itemID = Input(shape=[1], name='item_ID')
user_emb_GMF = Embedding(num_users, emb_size, name='user_emb_GMF')(input_userID)
item_emb_GMF = Embedding(num_items, emb_size, name='item_emb_GMF')(input_itemID)
interraction_map = tf.expand_dims(Dot(axes=1)([user_emb_GMF,item_emb_GMF]), -1)
print(interraction_map)
conv = Conv2D(32, 2, strides=2, activation='relu', padding="SAME", input_shape=interraction_map.shape[1:], name='conv1')(interraction_map)
for i in range(2,7):#les autres conv layer
conv = Conv2D(32, 2, strides=2, activation='relu', padding="SAME",name='conv%d'%(i))(conv)
reshaped_conv = Flatten()(conv)
# c'est la que je doit agir et ajouter creer la prédiction
out = Dense(1, name='output' )(reshaped_conv)
#out = Dense(1,activation='sigmoid',name='output')(layer)
oncf_model = Model([input_userID, input_itemID], out)
tf.keras.utils.plot_model(oncf_model, show_shapes=True)
我希望输出层是这个操作的结果:
output_layer = tf.matmul(reshaped_conv, W) + b
with W is tensor of shape(32,1)(weights) and b is tensor of shape(1) (bias).
我想知道在这种特殊情况下,使用 matmul 完成的操作是否等同于 Dense 层所做的操作
out = Dense(1, name='output' )(reshaped_conv)
最佳答案
是的,它们是一样的......你可以自己测试
X = np.random.uniform(0,1, (32,10)).astype('float32')
x = Dense(1)
pred = x(X)
W, b = x.get_weights()
(pred == (tf.matmul(X, W) + b)).numpy().all() # TRUE
关于python - 在某些情况下,tf.matmul 是否等同于 Dense 层在 tensorflow 中进行的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63684800/
判断这2个相似的Uris实际上相同的标准方法是什么? var a = new Uri("http://sample.com/sample/"); var b = new Uri("http://sam
这个问题在这里已经有了答案: Why does "true" == true show false in JavaScript? (5 个答案) 关闭 5 年前。 可能我很困惑,但我无法理解这个愚蠢
我是一名优秀的程序员,十分优秀!