获得某层tensor的输出维度
代码如下:
from keras import backend as K
@wraps(Conv2D)
def my_conv(*args,**kwargs):
new_kwargs={'kernel_regularizer':l2(5e-6)}
new_kwargs['padding']='valid' #'same'
new_kwargs['strides']=(2,2) if kwargs.get('strides')==(2,2) else (1,1)
# new_kwargs['kernel_initializer']=keras.initializers.glorot_uniform(seed=0)
new_kwargs.update(kwargs)
return Conv2D(*args,**new_kwargs)
def conv(x,**kwargs):
x=my_conv(**kwargs)(x)
x=BatchNormalization(axis=-1)(x)
x=LeakyReLU(alpha=0.05)(x)
return x
def inception_resnet_a(x_input):
x_short=x_input
s1=conv(x_input,filters=32,kernel_size=(1,1))
s2=conv(x_input,filters=32,kernel_size=(1,1))
s2=conv(s2,filters=32,kernel_size=(3,3),padding='same')
s3=conv(x_input,filters=32,kernel_size=(1,1))
s3=conv(s3,filters=48,kernel_size=(3,3),padding='same')
s3=conv(s3,filters=64,kernel_size=(3,3),padding='same')
x=keras.layers.concatenate([s1,s2,s3])
x=conv(x,filters=384,kernel_size=(1,1))
x=layers.Add()([x_short,x])
x=LeakyReLU(alpha=0.05)(x)
print(K.int_shape(x))
使用K.int_shape(tensor_name)即可得到对应tensor的维度