Tensorflow, get static shapes of tensors

Viewed 116

I am trying to use the Unet model output in other neural network, the problem is, I need to get the real shape without None instead of dimensions, could you please tell me how I can do it? unet_model.summary() shows the real shape, but when I try to get the output tensor, its shape is None

unet_model =  Unet(input_shape=(256,256,3),backbone_name='resnet50',encoder_weights='imagenet', decoder_block_type='transpose')
f_i = Input(shape=(256,256,3))
unet_model.call(f_i)
unet_model.layers[-1].output

link to the screenshot with the output

# unet_model.summary()
....
sigmoid (Activation)            (None, 256, 256, 1)  0           final_conv[0][0]    

# unet_model.call(f_i)
<tf.Tensor 'sigmoid_5/Sigmoid:0' shape=(?, ?, ?, 1) dtype=float32>

# unet_model.layers[-1].output   
<tf.Tensor 'sigmoid_5/Sigmoid:0' shape=(?, ?, ?, 1) dtype=float32>

I expect to receive a tensor with the shape = (None, 256, 256, 1)

I use tensorflow==1.14.0, keras==2.3.1

1 Answers

You can get the layer shape of the model using below lines.

for layer in unet_model.layers:
    print(layer.output_shape)
Related