1.下面keras代码,先TimeDistributed, 再 Dense, 依据https://keras.io/zh/layers/core/ Dense节, dense自动flatten输入来计算,那么这个TimeDistributed,是不是没用?
x = Permute((2, 1, 3), name='permute')(x)
x = TimeDistributed(Flatten(), name='flatten')(x)
#x = tf.Print(x, [x], "x")
y_pred = Dense(nclass, name='out'+str(nclass), activation='softmax')(x)
答:这个文档里面结束的Dense层计算方式是错误的,应该按照最新版https://keras.io/api/layers/core_layers/dense/ 为依据,Dense层只对最后一维做dense操作,其它维度是复用关系。
也参考https://stackoverflow.com/a/47309453/5002686
2. 上面的代码中,如果如下方式,效果是否等同?
x = Permute((2, 1, 3), name='permute')(x)
x = TimeDistributed(Dense(nclass, name='out'+str(nclass), activation='softmax')(Flatten()), name='flatten')(x)
答:等同