Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
AttributeError: 'module' object has no attribute 'main' for tf.app.run()

I am trying to test a short program, which is pretty simple, shown as follows

import numpy as np
import tensorflow as tf    
flags = tf.app.flags
FLAGS = flags.FLAGS    
import tensorvision.train as train
import tensorvision.utils as utils    
flags.DEFINE_string('name', None,
                    'Append a name Tag to run.')

flags.DEFINE_string('hypes', 'hypes/medseg.json',
                    'File storing model parameters.')    
if __name__ == '__main__':
    tf.app.run()

However, running the program gives the following error message,

Traceback (most recent call last):
File "train.py", line 43, in <module>
  tf.app.run()
File "/devl/tensorflow/tf_0.12/lib/python3.4/site-  packages/tensorflow/python/platform/app.py", line 39, in run
main = main or sys.modules['__main__'].main
AttributeError: 'module' object has no attribute 'main'
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You either need a "def main(args)" function in your file:

import numpy as np
import tensorflow as tf    
flags = tf.app.flags
FLAGS = flags.FLAGS    
import tensorvision.train as train
import tensorvision.utils as utils    

def main(args):
    flags.DEFINE_string('name', None,
                        'Append a name Tag to run.')

    flags.DEFINE_string('hypes', 'hypes/medseg.json',
                        'File storing model parameters.')    
if __name__ == '__main__':
    tf.app.run()

or tf.app.run() can call an external function

tf.app.run(my_func)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!