1

I defined a placeholder during graph construction time like this,

input_ = tf.placeholder(tf.float32, shape=(batch_size,  None, 3,1)) 

and then I want operation like this

shape = input_.get_shape().as_list()
stride_1 = np.floor(float(shape[1] / 5)).astype(np.int32)

But it is showing

TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

giser_yugang
  • 6,058
  • 4
  • 21
  • 44
Mahesh
  • 11
  • 1
  • 1
    Not sure what you expected. You have defined your 2nd dimension as `None` and you cannot divide `None` by 5 (as you do in the third line). It needs to be an integer – thushv89 Dec 27 '19 at 07:01
  • Yes, i know we cannot do this but i want to know is there some other way? – Mahesh Dec 27 '19 at 07:57
  • I didn't understand, what you are trying? ```Input_Shape``` is tuple of integers and the arguments are ```[Batch_Size, Image_Height, Image_Width, Channels]``` in case of ```Conv2D```. The first value (i.e ```[0]```) can be ```None``` when you havn't specify batch_size else this value will be repalced with the value of Batch_size. Second value (i.e ```[1]```) never be a ```None```. – bsquare Apr 24 '20 at 14:01
  • Use `tf.shape` instead of `get_shape`. You can check out more here : https://stackoverflow.com/questions/36966316/how-to-get-the-dimensions-of-a-tensor-in-tensorflow-at-graph-construction-time – vipulnj Dec 11 '21 at 21:52

0 Answers0