h5py.File(path) doesn't recognize folder path

前端 未结 2 570
逝去的感伤
逝去的感伤 2021-01-22 01:43

I am in my project folder call \"project\". I have two neural network h5 file, one in \"project/my_folder/my_model_1.h5\", I also copy it to folder \"project/my_model_2.h5\". So

相关标签:
2条回答
  • 2021-01-22 02:30

    So it looks like some hidden invalid character incidentally got copied when I simply copy and paste the file path from Mac folder system. Take a look at the code in the screen.

    The Line 92 is the path name I directly copy and paste from Mac folder.

    The Line 93 is the path I literally type with every single letter, then there is no error and .h5 file is loaded properly. It's a kinda of similar issue that has been spotted by someone at this link: Invalid character in identifier

    I simply copy the error code to Pycharm, and the unwelcome character got busted.

    So solution, for Mac user, be careful of of just simply copying the text from folder system, if something obviously weird, try type every letter into the text editor.

    0 讨论(0)
  • 2021-01-22 02:35

    Specifying the absolute path using the os worked in windows

    file_name = os.path.dirname(__file__) +'\\my_folder\\my_model_1.h5'
    f = h5py.File(file_name)
    

    dont forget to import os though

    0 讨论(0)
提交回复
热议问题