Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print ("successfully converted {}-labels from mat to pascal-xml").format(directory) AttributeError: 'NoneType' object has no attribute 'format' #1

Open
monajalal opened this issue Jun 26, 2018 · 2 comments

Comments

@monajalal
Copy link

Hey when I ran mat_to_xml.py I got this error:

mona@Mona:~/code/handpose/deeptraining_hands$ python mat_to_xml.py 
successfully converted {}-labels from mat to pascal-xml
Traceback (most recent call last):
  File "mat_to_xml.py", line 213, in <module>
    main()
  File "mat_to_xml.py", line 209, in main
    print ("successfully converted {}-labels from mat to pascal-xml").format(directory)
AttributeError: 'NoneType' object has no attribute 'format'

how should this be fixed?

@gustavz
Copy link
Owner

gustavz commented Jun 28, 2018

There really should no issue on the call of format(directory) as this is the string the loop iterates over.
as the code in main() is:

def main():
    # Read a .mat file and convert it to a pascal format
    for directory in ['train','eval']:

        if not os.path.exists('data/{}/annotations/xml'.format(directory)):
            os.makedirs('data/{}/annotations/xml'.format(directory))

        MAT_FILES_PATH = os.path.join(os.getcwd(), 'data/{}/annotations/mat'.format(directory))
        XML_FILES_PATH = os.path.join(os.getcwd(), 'data/{}/annotations/xml'.format(directory))
        IMG_FILES_PATH = os.path.join(os.getcwd(), 'data/{}/images'.format(directory))

        # List all files in the MAT_FILES_PATH and ignore hidden files (.DS_STORE for Macs)
        mat_files = [[join(MAT_FILES_PATH, x), x] for x in os.listdir(MAT_FILES_PATH) if isfile(join(MAT_FILES_PATH, x)) and x[0] is not '.']
        mat_files.sort()
	
        # Iterate through all files and convert them to XML
        for mat_file in mat_files:
            #print(mat_file)
            read_mat_file(mat_file[0], mat_file[1],IMG_FILES_PATH, XML_FILES_PATH)
            #break
        print ("successfully converted {}-labels from mat to pascal-xml").format(directory)
    cv2.destroyAllWindows()

My questions:

  1. Did you change my code?
  2. Did you successfully run the dataset setup scripts?
  3. Which python version are you using?

@Divyanshupy
Copy link

@monajalal you are facing this issue because in the last print the syntax is wrong for python 3.
It is written like this
print ("successfully converted {}-labels from mat to pascal-xml").format(directory)
but should actually be
print ("successfully converted {}-labels from mat to pascal-xml".format(directory))
I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants