python 缩进错误(tensorflow)
python indentation error (tensorflow)
我所有的代码都是用 sublime text 写在 Ubuntu
我目前正在学习机器学习并且一直在关注一个视频...
我的代码与 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,所以我现在还不习惯处理缩进问题。
谢谢
确保只使用空格或制表符进行缩进。 Sublime text has a "convert tabs to spaces" 对此很有用的功能。
我所有的代码都是用 sublime text 写在 Ubuntu
我目前正在学习机器学习并且一直在关注一个视频... 我的代码与 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,所以我现在还不习惯处理缩进问题。
谢谢
确保只使用空格或制表符进行缩进。 Sublime text has a "convert tabs to spaces" 对此很有用的功能。