keras 张量切片
生活随笔
收集整理的这篇文章主要介绍了
keras 张量切片
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
对张量切片的方式和numpy 一样,如下
out1=outs[:,:100] out2=outs[:,100:]下面是代码demo
import keras.backend as K from tensorflow.keras.layers import concatenate from tensorflow.keras import Sequential,Model from tensorflow.keras.layers import Dense ,Concatenate,Input,BatchNormalizationdense_inputs1 = Input(shape=(1024, )) dense_inputs2 = Input(shape=(512, ))d1 = Dense(256, activation='relu')(dense_inputs1) d2 = Dense(256, activation='relu')(dense_inputs2)merge_inputs = concatenate([d1,d2],axis=1)flow_dense = Dense(256, activation='relu')(merge_inputs) flow_dense = BatchNormalization()( flow_dense)outs = Dense(100+1, activation='softmax')(flow_dense) print(outs)原来的张量这是101维度的张量
Tensor("dense_11/Softmax:0", shape=(?, 101), dtype=float32)101维度的张量已经切割成100维和1维
out1=outs[:,:100] out2=outs[:,100:] print(out1) print(out2) Tensor("strided_slice_10:0", shape=(?, 100), dtype=float32) Tensor("strided_slice_11:0", shape=(?, 1), dtype=float32)总结
以上是生活随笔为你收集整理的keras 张量切片的全部内容,希望文章能够帮你解决所遇到的问题。