模仿CNN提取堆叠的一维特征向量的特征,其中,堆叠个数看作channel
import numpy as np
import scipy.sparse as sp
import tensorflow as tf
import numpy as np
all_embeddings = []
embeddings = []
a = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]] # (6*4)
all_embeddings += [a]
b = [[4,3,2,1],[4,3,2,1],[4,3,2,1],[4,3,2,1],[4,3,2,1],[4,3,2,1]] # (6*4)
all_embeddings += [b]
# (6,4) + (6,4) = (6,8)
"""
B,C,W,H
(6,4) + (6,4) = (6,1,4) + (6,1,4) =
a = [[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8]] + b = [[4,3,2,1],[8,7,6,5],[4,3,2,1],[8,7,6,5],[4,3,2,1],[8,7,6,5]]
-->[[[1,2,3,4],[4,3,2,1]],[[5,6,7,8],[8,7,6,5]],[[1,2,3,4],[4,3,2,1]],[[5,6,7,8],[8,7,6,5]],[[1,2,3,4],[4,3,2,1]],[[5,6,7,8],[8,7,6,5]]]
"""
all_embeddings = tf.concat(all_embeddings, 1) # (6,8)
# print(all_embeddings)
# # 在index=1处扩展一个维度 # (6, 1, 8)
# all_embeddings = tf.expand_dims(all_embeddings,1)
# print(all_embeddings)
# # 在index=1处扩展一个维度 # (6, 1, 1, 8)
# all_embeddings = tf.expand_dims(all_embeddings,1)
# reshape NCWH
all_embeddings = tf.reshape(all_embeddings,[6, 2, 1, 4])
print(all_embeddings)
# reshape NWHC
all_embeddings = tf.transpose(all_embeddings, perm=[0, 2, 3, 1])
print(all_embeddings) # 6, 1, 4, 2
with tf.Session() as sess_test:
init = tf.global_variables_initializer()
sess_test.run(init)
a = sess_test.run(all_embeddings)
print(a)
sess_test.close()
# 思考如何将a的第一行 与 b的第一行组合成一个新的list
"""
a = [[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8]] + b = [[4,3,2,1],[8,7,6,5],[4,3,2,1],[8,7,6,5],[4,3,2,1],[8,7,6,5]]
-->[[[1,2,3,4],[4,3,2,1]],[[5,6,7,8],[8,7,6,5]],[[1,2,3,4],[4,3,2,1]],[[5,6,7,8],[8,7,6,5]],[[1,2,3,4],[4,3,2,1]],[[5,6,7,8],[8,7,6,5]]]
去学习numpy的切片!!!模仿卷积如何放图片,通道。多张图片。
ECNN B C W H
(125599*64), (125599*64)-->(125599*64)-->(125599*128)-->reshape-->(125599*2*1*64) = (125599*(i-2)*1*64)
and then, 与卷积核为(i-2)*1*2*、(i-2)*1*3卷积,得到125599*(i-2)*1*63、125599*(i-2)*1*62 --> padding 125599*(i-2)*1*64、125599*(i-2)*1*64 --> max pooling,strides=2 --> 125599*1*32、125599*1*32
--> 缩维度 --> 125599*32、125599*32 --> concate --> 125599*64
MLP
(125599*64)、(125599*64) --> concate --> 125599*128 --> XW+b, W=(129*64) --> 125599*64
"""