tensorflow2报错AttributeError: module ‘tensorflow’ has no attribute ‘truncated_normal’
代码
tn = tf.truncated_normal([prev_num_nodes, num_nodes], stddev=w_stddev)
报错信息
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-05dbe3f468af> in <module>()
5
6 # new_alex = TransferedAlexNet(old_alex_graph, num_tgt_classes=2)
----> 7 new_alex = TransferedAlexNet(old_alex_graph)
8 print(new_alex)
9 inputs = old_alex_graph.get_tensor_by_name('inputs/images:0')
<ipython-input-12-d49ea2971fb0> in __init__(s, init_graph)
21 with tf.name_scope('new_top_layer'):
22 # the old fc8 (which we are replacing) had 1000 nodes for 1000 classes
---> 23 s.logits = helpers_07.fully_connected_xavier_relu_layer(orig_fc7)
24 print( s.logits)
25
in fully_connected_xavier_relu_layer(incoming_layer, num_nodes, b_val, keep_prob, name)
84 activation_fn = tf.nn.relu,
85 keep_prob=keep_prob,
---> 86 name=name)
87
88 if __name__ == "__main__":
in fully_connected_layer(incoming_layer, num_nodes, w_stddev, b_val, activation_fn, keep_prob, name)
56 # FIXME: consider stddev=np.sqrt(2.0 / prev_num_nodes)
57 # [fancy initialization]
---> 58 tn = tf.truncated_normal([prev_num_nodes, num_nodes], stddev=w_stddev)
59 W = tf.Variable(tn, name='W')
60 const = tf.constant(b_val, shape=[num_nodes])
AttributeError: module 'tensorflow' has no attribute 'truncated_normal'
解决方法
tf.random.truncated_normal([prev_num_nodes, num_nodes], stddev=w_stddev)
还没有评论,来说两句吧...