0

I'm distinguish the keras.layer about Droupout and SpatialDropout1D, however, I call K.eval() and find the two result is different.

It's running in tensorflow1.12.1

x = np.arange(2*4*3).reshape((2, 4, 3))
inputs = K.variable(x) # generate a variable
dropout_1 = K.eval(SpatialDropout1D(0.5)(inputs))
print(dropout_1)
noise_shape=(2, 4, 1) 
dropout_2 = K.eval(K.dropout(inputs, 0.5, noise_shape)) 
print(dropout_2)

dropout_1:

[[[ 0.  1.  2.]
  [ 3.  4.  5.]
  [ 6.  7.  8.]
  [ 9. 10. 11.]]

 [[12. 13. 14.]
  [15. 16. 17.]
  [18. 19. 20.]
  [21. 22. 23.]]]

dropout_2:

[[[ 0.  2.  4.]
  [ 6.  8. 10.]
  [ 0.  0.  0.]
  [ 0.  0.  0.]]

 [[24. 26. 28.]
  [30. 32. 34.]
  [36. 38. 40.]
  [ 0.  0.  0.]]]
skydm
  • 1
  • some element of dropout_1 should be zero, more, dropout_1 should equal to dropout_2 – skydm May 28 '19 at 10:24
  • Looks like `SpatialDropout` is running in inference mode where dropout just becomes a noop. Can you pass `training=True` to where you call spatial dropout on `inputs`? – xdurch0 May 28 '19 at 11:08
  • The answer in [this post](https://stackoverflow.com/questions/50393666/how-to-understand-spatialdropout1d-and-when-to-use-it) does a pretty good job of explaining. – TheLoneDeranger May 28 '19 at 15:46
  • Thanks for your reply! I ignore the param `training=True`, the right writing is `dropout_1 = K.eval(SpatialDropout1D(0.5)(inputs, training=True))`. I have another question. Why wrap with `keras.models.Model`, we can ignore the para `training`?About training and inference , what we should take notice? – skydm May 29 '19 at 01:42

0 Answers0