1. init = tf.global_variables_initializer() 一定要放在构建所有Variable之后,因为该语句就初始化已经构建过的Variable
2. tf.matmul(a,b),matmul在运行时不提供吗强制类型转换,所以a和b必须类型一致,可以使用tf.cast,比如
tf.cast(a, tf.float32)
3. tf中最常见的就是维度方面的错误,常见的解决方法是在代码中假如打印 print(tensor)
4. tf.get_variable如果要使用已有的数据结构初始化,最好使用 np.ndarray,使用list往往会出现错误
5. tf.shape(a) 显示 (3,) 表示 a是有3个维度的tensor,而非是在一个维度上有3个元素!
6. 在定义loss之前,需要手动给loss赋一个初值,比如:
def add_loss_op(self, preds):
# 这里必须要加上
self.loss = 0.0
self.loss = tf.reduce_mean(
tf.nn.softmax_cross_entropy_with_logits( logits = preds,
labels = self.labels_placeholder )
)
return self.loss
7. 在电脑上运行tf代码有时候会出现:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
解决方案(和TF的安装方法相关,时间关系,暂时没有试过,以后再看):How to compile Tensorflow with SSE4.2 and AVX instructions?