【发布时间】:2018-05-23 01:50:34
【问题描述】:
我所有的代码都是在 Ubuntu 中用 sublime text 编写的
我目前正在学习机器学习,并且一直在关注视频... 我的代码与 Youtuber 的代码相同,但我一直得到一个
File "deep-net.py", line 31
hidden_3_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])),'biases':tf.Variable(tf.random_normal([n_nodes_hl3]))}
IndentationError: unindent does not match any outer indentation level
此错误消息在第 31 行末尾有一个小插入符号指向最后的结束“}”。
这是我的一段上下文代码:
def neural_network_model(data):
# (input_data + weights) + biases
hidden_1_layer = {'weights':tf.Variable(tf.random_normal([784, n_nodes_hl1])),'biases':tf.Variable(tf.random_normal([n_nodes_hl1]))}
hidden_2_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])),'biases':tf.Variable(tf.random_normal([n_nodes_hl3]))}
hidden_3_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])),'biases':tf.Variable(tf.random_normal([n_nodes_hl3]))} #this is line 31
output_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl3, n_classes])),'biases':tf.Variable(tf.random_normal([n_classes]))}
#blah blah more code
return output
最初,我没有将所有代码放在一行,因为我不喜欢爬出屏幕的代码。这是我原来的缩进:
def neural_network_model(data):
# (input_data + weights) + biases
hidden_1_layer = {'weights':tf.Variable(tf.random_normal([784, n_nodes_hl1])),
'biases':tf.Variable(tf.random_normal([n_nodes_hl1]))}
hidden_2_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])),
'biases':tf.Variable(tf.random_normal([n_nodes_hl3]))}
hidden_3_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])),
'biases':tf.Variable(tf.random_normal([n_nodes_hl3]))}
output_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl3, n_classes])),
'biases':tf.Variable(tf.random_normal([n_classes]))}
我得到了同样的错误,除了错误在第 35 行:
hidden_3_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])),
插入符号指向结尾的“,”
我决定将每个变量定义放在一行中,而不是将其分成两行,看看缩进错误是否会消失,但它没有。
任何帮助将不胜感激。我是一名学生,大部分时间都在编写 Java 代码,所以我现在还不习惯处理缩进问题。
谢谢
【问题讨论】:
标签: python tensorflow indentation