我试图在Colab笔记本中使用Tensorflow来训练结构相同的神经网络,从MNIST数据集中随机选择不同大小的训练示例。我以前已经成功地用类似的方式训练神经网络好几次了,但这次我收到了一个无效的语法错误,我无法纠正。以下代码行出现错误:
mnist_classifier = tf.estimator.Estimator(model_fn=cnn_model_fn)
我已经在另一个笔记本上成功地使用了这一行代码,但是我无法识别语法上的任何问题(它来自于Tensorflow文档:https://www.tensorflow.org/tutorials/layers)
我试图执行的代码可以在下面找到(但为了简洁起见,我省略了cnn_model_fn的定义)。在
#Initialize list to hold all of the accuracy data
all_accuracies = []
#For each training set group
for group_number in range(len(train_set_sizes)):
#For each ANN in training set group
for i in range(num_ANNs):
#Initialize group_accuracies list
group_accuracies = []
#--------------Generate a training set--------------------------------
#Initialize train_set lists
train_set_examples = []
train_set_labels = []
#randomly select indices to pull train set examples
example_select_indices = np.random.randint(0,55000,size=train_set_sizes[group_number])
#For number of images in the appropriate training set group
for j in range(train_set_sizes[group_number]):
random_index = example_select_indices[j]
train_set_examples = np.asarray(train_set_examples.append(train_images[random_index]))
train_set_labels = np.asarray(train_set_labels.append(train_labels[random_index])
# Create the MNIST Estimator
mnist_classifier = tf.estimator.Estimator(model_fn=cnn_model_fn)
# Train the CNN model
mnist_classifier.train(input_fn=train_input_fn,steps=train_steps)
# Evaluate the models and print results
eval_result = mnist_classifier.evaluate(input_fn=eval_input_fn)
print("Group Number ",group_number+1,", ANN #",i+1," Accuracy: ",eval_result," %")
#Record ANN accuracy
group_accuracies.append(eval_result)
#record group accuracies in all_accuracies
all_accuracies.append(group_accuracies)
有人对为什么会发生这种错误有什么建议吗?在
谢谢你!在
目前没有回答
相关问题 更多 >
编程相关推荐