Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between shape and int_shape in Keras

Tags:

keras

According to the Keras manual,

keras.backend.shape() returns the symbolic shape of a tensor or variable. keras.backend.int_shape() returns the shape of tensor or variable as a tuple of int or None entries.

These definitions are still unclear to me. I couldn't find any relevant material in Google, either. Can anyone help me understand the difference between the two?

like image 559
DSKim Avatar asked May 09 '18 17:05

DSKim


1 Answers

import keras.backend as K 
import numpy as np

x = K.variable(np.eye(2, 2)) 

print('shape:', K.shape(x))
print('int_shape:', K.int_shape(x))

gives

shape: Tensor("Shape_4:0", shape=(2,), dtype=int32)

int_shape: (2, 2)

As you can see, first one is a tensor (it contains two numbers of corresponding shape) whereas the second one is a tuple.

like image 102
Jakub Bartczuk Avatar answered Sep 26 '22 17:09

Jakub Bartczuk