代码用法链接

£神魔★判官ぃ 2023-01-02 04:21 335阅读 0赞

keras用法

models.
搭建模型 ——— 配置训练方法 ——— 执行训练过程 ——— 统计参数数目
Sequential() compile(). fit() summary()


tf 的 shape
在这里插入图片描述

  1. aaa = tf.random_uniform([2,3],minval=-0.1,maxval = 0.1)
  2. print(aaa.shape) # --- 1
  3. with tf.Session() as sess:
  4. print(aaa.get_shape()) # --- 2
  5. 输出:
  6. (2, 3) # --- 1
  7. (2, 3) # --- 2

numpy 的shape:
在这里插入图片描述


nn.embedding()


tf.placeholder()

  1. a=tf.placeholder(tf.int32, shape=[2,2])
  2. with tf.Session() as sess:
  3. print(sess.run(a,feed_dict={
  4. a:[[2,4],[3,3]]}))
  5. 输出:
  6. [[2 4]
  7. [3 3]]
  8. bb = tf.placeholder(tf.int32, shape=[2, ])
  9. cc = tf.placeholder(tf.int32, shape=[2])
  10. with tf.Session() as sess:
  11. print(sess.run(b, feed_dict={
  12. b: [2,2] }))
  13. print(sess.run(c, feed_dict={
  14. c: [2, 2] }))
  15. 输出:
  16. bb = [2 2]
  17. cc = [2 2]
  18. b = tf.placeholder(tf.int32, shape=[None, None])
  19. c = tf.placeholder(tf.int32, shape=[2,])
  20. d = tf.placeholder(tf.float32, shape=[None,1])
  21. e = tf.placeholder(tf.float32, shape=[1, None])
  22. print(b.shape) # (?, ?)
  23. print(c.shape) # (2,)
  24. print(d.shape) # (?, 1)
  25. print(e.shape) # (1, ?)
  26. with tf.Session() as sess:
  27. print(sess.run(b,feed_dict={
  28. b:[[4,4,2],[3,5,6],[5,6,7]]}))
  29. print(sess.run(c,feed_dict={
  30. c:[42,33] }))
  31. print(sess.run(d,feed_dict={
  32. d:[[42],[4],[6]] }))
  33. print(sess.run(e, feed_dict={
  34. e:[[42,4,5,6]] }))
  35. 输出:
  36. b = [[4 4 2]
  37. [3 5 6]
  38. [5 6 7]]
  39. c = [42 33]
  40. d = [[42.]
  41. [ 4.]
  42. [ 6.]]
  43. e = [[42. 4. 5. 6.]]

矩阵None的用法:对应维度加一维
在 ndarray 和 tensor 类型使用,list 不适用(会报错)

  1. b=np.array([[3,4,5,6],[7,8,9,10],[11,2,3,33]])
  2. print(b) # --- 1
  3. print(b[:,]) # --- 1
  4. print(b[:,None]) # --- 2
  5. print(b.shape) # (3, 4)
  6. print(b[:,None].shape) # (3, 1, 4)
  7. print(b[None,:].shape) # (1, 3, 4)
  8. 输出:
  9. # b 和 b[:,] # --- 1
  10. [[ 3 4 5 6]
  11. [ 7 8 9 10]
  12. [11 2 3 33]]
  13. # b[:,None] # --- 2
  14. [[[ 3 4 5 6]]
  15. [[ 7 8 9 10]]
  16. [[11 2 3 33]]]

发表评论

表情:
评论列表 (有 0 条评论,335人围观)

还没有评论,来说两句吧...

相关阅读