import tensorflow as tf
def main():
print('hello')
if __name__ == '__main__':
tf.app.run()
会报错 TypeError: main() takes 0 positional arguments but 1 was given
def main(_)
这样就不会报错,_的用法和具体原因后续补上,目前还没弄明白,占位符?
本文探讨了使用TensorFlow框架时遇到的TypeError错误:main()方法参数数量不匹配的问题。通过调整main函数定义,从原本不带参数修改为带有单一占位符参数 (_) 的形式解决了这一问题。文中虽未深入解释 _ 的具体作用,但指出其作为占位符的存在对于tf.app.run()的正确执行至关重要。
import tensorflow as tf
def main():
print('hello')
if __name__ == '__main__':
tf.app.run()
会报错 TypeError: main() takes 0 positional arguments but 1 was given
def main(_)
这样就不会报错,_的用法和具体原因后续补上,目前还没弄明白,占位符?
您可能感兴趣的与本文相关的镜像
TensorFlow-v2.15
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
1371
980
5398
5378

被折叠的 条评论
为什么被折叠?