运行logistic regression时相关函数
1.tf.placeholder( )
x = tf.placeholder("float",[None,784])
注:
tf.placeholder( dtype, shape=None, name=None)
参数:
dtype:数据类型。常用的是tf.float32,tf.float64等数值类型
shape:数据形状。默认是None,就是一维值,也可以是多维(比如[2,3], [None, 3]表示列是3,行不定)
name:名称
2.tf.zeros()
tf.zeros( shape, dtype=tf.float32, name=None)
shape代表形状,也就是1纬的还是2纬的还是n纬的数组。
b = tf.Variable(tf.zeros([10])) #因为做10分类,所以初始化b为10,表示1维数组里有10个值
3.tf.argmax()
tf.argmax(input,axis)
intput表示数组输入,axis可为0,1。axis=0,表示取输入数组每列中最大数的行号;axis=1,表示取输入数组每行中最大数的行号。
test = np.array([[1, 2, 3], [2, 3, 4], [5, 4, 3], [8, 7, 2]])
np.argmax(test, 0) #输出:array([3, 3, 1]
np.argmax(test, 1) #输出:array([2, 2, 0, 0])
4.运行simple Netural Network时,出错:
ValueError: Only call softmax_cross_entropy_with_logits with named arguments (labels=…, logits=…, …)
调用tf.nn.softmax_cross_entropy_with_logits(logits, tf_train_labels)出现上述错误。
解决办法:错误提示中已经给出,只能使用命名参数的方式来调用。调用函数改为:tf.nn.softmax_cross_entropy_with_logits(labels=tf_train_labels, logits=logits)即可。
原:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))
改1:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=pred, logits=y))
报错
ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables ["", "", "", "", "", ""] and loss Tensor("Mean:0", shape=(), dtype=float32).
解决办法:
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))
运行成功
5.唐宇迪 VGG学习博客:
https://blog.csdn.net/f290131665/article/details/80455301
6.运行VGG时报错:
(1)AttributeError: module ‘scipy.misc’ has no attribute ‘imread’
解决:https://blog.csdn.net/qq_20545303/article/details/80092339
安装pillow即可。
运行出现:
2019-03-12 11:30:41.033011: W tensorflow/core/framework/allocator.cc:113] Allocation of 1118699520 exceeds 10% of system memory.
同时有conv_1和relu_1处理后的特征图出现
百度原因:显存不够,考虑减少batchsize或者crop_size。例如:train_crop_size=513。
https://blog.csdn.net/u011974639/article/details/80574306
7.运行RNN时
(1)报错TypeError: Input ‘split_dim’ of ‘Split’ Op has type float32 that does not match expected type of int32.
百度解决:
https://blog.csdn.net/wang2008start/article/details/71516198
This is because in Tensorflow versions < 0.12.0 the split function takes the arguments as:
x = tf.split(0, n_steps, x) # tf.split(axis, num_or_size_splits, value)
The tutorial you are working from was written for versions > 0.12.0, which has been changed to be consistent with Numpy’s split syntax:
x = tf.split(x, n_steps, 0) # tf.split(value, num_or_size_splits, axis)
(2)之后错误二:AttributeError: module ‘tensorflow.nn’ has no attribute ‘rnn’
百度:
https://blog.csdn.net/yutingzhaomeng/article/details/78926071
S:将tf.nn.rnn_cell替换为tf.contrib.rnn
仍没有解决