Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import numpy as np
  2.  
  3. from tensorflow.python.keras import models
  4. from tensorflow.python.keras import layers
  5. from tensorflow.python.keras import backend as K
  6.  
  7. inp = layers.Input(shape=(10, 20,))
  8. conv = layers.Conv1D(filters=10, kernel_size=2)(inp)
  9. pool = layers.GlobalMaxPool1D()(conv)
  10. output = layers.Dense(1, activation="sigmoid")(pool)
  11.  
  12. m = models.Model(inp, output)
  13.  
  14. m.summary()
  15.  
  16. m.compile(optimizer="adam", loss="binary_crossentropy")
  17.  
  18. m.fit(x=np.random.randn(100, 10, 20), y=np.random.randn(100))
  19.  
  20. loss = K.mean(m.output)
  21. grads = K.gradients(loss, m.input)[0]
  22. f = K.function([m.input], [grads])
  23. print(f([np.random.randn(10, 20)]))
  24.  
  25. import tensorflow as tf
  26. import sys
  27. from tensorflow.python import keras
  28.  
  29. print(tf.__version__)
  30. print(keras.__version__)
  31. print(sys.version)
  32.  
  33. 1.12.0
  34. 2.1.6-tf
  35. 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 14:01:38)
  36. [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
  37.  
  38. 2019-04-19 17:00:58.249788: F ./tensorflow/core/util/tensor_format.h:420] Check failed: index >= 0 && index < dimension_attributes.size() Invalid index from the dimension: 3, 0, C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement