Tensorflow 更新到1.0后,函数变化

1.grammary系列函数修改

  • tf.histogram_summary() 和 tf.contrib.deprecated.histogram_summary() 修改为 tf.summary.histogram()

  • tf.scalar_summary() 和 tf.contrib.deprecated.scalar_summary() 修改为 tf.summary.scalar()

  • tf.image_summary() 修改为 tf.summary.image()

  • tf.merge_summary() 修改为 tf.summary.merge()

  • tf.merge_all_summaries() 修改为 tf.summary.merge_all()

  • tf.train.SummaryWriter 修改为 tf.summary.FileWriter()

2.计算函数修改

  • tf.sub() 修改为 tf.subtract()

  • tf.mul() 修改为 tf.multiply()

  • tf.div() 修改为 tf.divide()

  • tf.mod() 修改为 tf.truncatemod()

  • tf.inv() 修改为 tf.reciprocal()

    扫描二维码关注公众号,回复: 2966272 查看本文章
  • tf.list_diff() 修改为 tf.setdiff1d()

  • tf.listdiff() 修改为 tf.setdiff1d()

  • tf.neg() 修改为 tf.negative()

  • tf.select() 修改为 tf.where()

3.定义变量修改

  • tf.variables() 修改为 tf.gobal_variables()
  • tf.all_variables() 修改为 tf.global_variables()
  • tf.initialize_all_variables() 修改为 tf.global_variables_initializer()
  • tf.initialize_local_variables() 修改为 tf.local_variables_initializer()
  • tf.initialize_variables() 修改为 tf.variables_initializer()

4.函数的参数修改

  • tf.nn.softmax_cross_entropy_with_logits(labels, logits)

       修改为     tf.nn.softmax_cross_entropy_with_logits(logits=logits,labels=labels)

  • .loss(labels, logits) 修改为 .loss(logits=logits,labels=labels)

  • tf.concat(concat_dim, values, name='concat')参数:1.concat_dim:一个整数,表示在哪一位度进行连接;2.values:是两个或者一组待连接的tensor;改变后的函数为concat(values,axis,name='concat'),很显然是将前两个参数掉换了位置。(tf.concat(a,b) 修改为 tf.concat(b,a))

  • tf.split(dimension, num_split, input):dimension是切割维度,num_split是切割的数量,input是传入需要切割的tensor。改变后的函数为tf.split( value, num_or_size_splits, axis=0)value是传入需要切割的tensor,num_or_size_splits是切割的数量,axis是切割维度。 所以需要将原来split的参数1和参数3换位置。(tf.split(a,b,c)修改为 tf.split(c,b,a))

5.其他修改

  • tf.image.random_crop() 修改为 tf.random_crop()
  • tf.image.per_image_whitening() 修改为 tf.image.per_image_standardization()

6.TypeError: Using a `tf.Tensor` as a Python `bool` isnot allowed. Use `if t is not None:` instead of `if t:` to test if a tensor isdefined, and use TensorFlow ops such as tf.cond to execute subgraphsconditioned on the value of a tensor.

这里的原因是tensorflow的tensor不再是可以直接作为bool值来使用了,需要进行判断。

如:if grad: 改为  if grad is not None:

 参考博客:

https://www.cnblogs.com/cvtoEyes/p/8981994.html

https://blog.csdn.net/xxzhangx/article/details/58005846

https://blog.csdn.net/u010528012/article/details/70860977

https://blog.csdn.net/u010700335/article/details/70885689

https://www.cnblogs.com/Davirain/p/8940080.html

https://blog.csdn.net/SangrealLilith/article/details/80272346

猜你喜欢

转载自blog.csdn.net/qq_38834766/article/details/82154272