记录一下tf里面函数的细节变动

最近在用tensorflow写程序的时候,发现一些函数里的细小变动,导致新版本中未完全兼容旧代码,以此文记录,防止再次踩坑,长期更新……目前用的是Tensorflow gpu 1.4.0版本

图像预处理相关函数

tf.image.sample_distorted_bounding_box()

import tensorflow as tf
##old
bbox_begin,bbox_size,bbox_for_draw=tf.image.sample_distorted_bounding_box(tf.shape(image),bounding_boxes=bbox)
##new
bbox_begin,bbox_size,bbox_for_draw=tf.image.sample_distorted_bounding_box(tf.shape(image),bounding_boxes=bbox,min_object_covered=0.1)

坑点:这里我不加显式给min_object_covered就会报ValueError: Tried to convert ‘min_object_covered’ to a tensor and failed. Error: None values not supported. 的错误。

tf.image.resize_images()

import tensorflow as tf
##old
distorted_image=tf.image.resize_images(distorted_image,height,width,method=method)
##new
distorted_image = tf.image.resize_images(distorted_image, size=[height, width], method=method)

坑点:这里如果不将size写为size=[height,width]的形式就会报TypeError: resize_images() got multiple values for argument 'method’的错误。

tf.concat()

import tensorflow as tf
##old
t = tf.concat(1, tensor)
##new
t = tf.concat(tensor, 1) 

坑点:新版本中的tf.concat()函数表示tensor的变量应该放在数字前面,而旧版中表示tensor的变量是放在数字后面的,否则就会报TypeError: Expected int32, got list containing Tensors of type ‘_Message’ instead.的错误。

tf.split()

import tensorflow as tf
## old 这里我们展示新旧版本的API
tf.split(split_dim, num_split, value, name='split')
## new
tf.split(value, num_or_size_splits, axis=0, num=None, name='split')

坑点:新版本中的接口发生变化,如果直接从旧版迁移过来会报TypeError: Input ‘split_dim’ of ‘Split’ Op has type float32 that does not match expected type of int32.的错误。

tf.nn.seq2seq.sequence_loss_by_example 变为tf.contrib.legacy_seq2seq.sequence_loss_by_example

坑点:新版本的tensorflow将类似于tf.nn.seq2seq.sequence_loss_by_example之类的接口迁移到了tf.contrib.legacy_seq2seq底下。小伙伴们用的时候注意一点哈。

你可能感兴趣的:(机器学习)