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

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)

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值