tensorflow2报错AttributeError: module ‘tensorflow‘ has no attribute ‘truncated_normal‘

淡淡的烟草味﹌ 2023-02-28 04:28 113阅读 0赞

tensorflow2报错AttributeError: module ‘tensorflow’ has no attribute ‘truncated_normal’

代码

  1. tn = tf.truncated_normal([prev_num_nodes, num_nodes], stddev=w_stddev)

报错信息

  1. ---------------------------------------------------------------------------
  2. AttributeError Traceback (most recent call last)
  3. <ipython-input-14-05dbe3f468af> in <module>()
  4. 5
  5. 6 # new_alex = TransferedAlexNet(old_alex_graph, num_tgt_classes=2)
  6. ----> 7 new_alex = TransferedAlexNet(old_alex_graph)
  7. 8 print(new_alex)
  8. 9 inputs = old_alex_graph.get_tensor_by_name('inputs/images:0')
  9. <ipython-input-12-d49ea2971fb0> in __init__(s, init_graph)
  10. 21 with tf.name_scope('new_top_layer'):
  11. 22 # the old fc8 (which we are replacing) had 1000 nodes for 1000 classes
  12. ---> 23 s.logits = helpers_07.fully_connected_xavier_relu_layer(orig_fc7)
  13. 24 print( s.logits)
  14. 25
  15. in fully_connected_xavier_relu_layer(incoming_layer, num_nodes, b_val, keep_prob, name)
  16. 84 activation_fn = tf.nn.relu,
  17. 85 keep_prob=keep_prob,
  18. ---> 86 name=name)
  19. 87
  20. 88 if __name__ == "__main__":
  21. in fully_connected_layer(incoming_layer, num_nodes, w_stddev, b_val, activation_fn, keep_prob, name)
  22. 56 # FIXME: consider stddev=np.sqrt(2.0 / prev_num_nodes)
  23. 57 # [fancy initialization]
  24. ---> 58 tn = tf.truncated_normal([prev_num_nodes, num_nodes], stddev=w_stddev)
  25. 59 W = tf.Variable(tn, name='W')
  26. 60 const = tf.constant(b_val, shape=[num_nodes])
  27. AttributeError: module 'tensorflow' has no attribute 'truncated_normal'

解决方法

  1. tf.random.truncated_normal([prev_num_nodes, num_nodes], stddev=w_stddev)

发表评论

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

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

相关阅读