1

In using keras.model.load_weights, by the way, the weight file is saved in a hdf5 format, I come across some situations where the folder names that have initial r or t, cause the error: errno = 22, error message = 'invalid argument', flags = 0, o_flags = 0.

I want to know if there are some specified rules on the filenames which should be avoided and otherwise would lead to such reading error in python, or the situation I encountered is only specific to keras.

jwm
  • 4,832
  • 10
  • 46
  • 78
  • Unix and Python have no filename restrictions like this. There's certainly nothing special about filenames beginning with `r` and `t`. – Barmar Jan 22 '18 at 20:33
  • But when I change the name of the folder where the weight file is save, everything goes fine. That's why I wander if there are some unsupported characters. Presumably, that kind of error is due to the path joining involving backslash r or t associated with the folder name. – jwm Jan 22 '18 at 20:38
  • Yeah, sounds like a bug in Keras. – Barmar Jan 22 '18 at 20:45
  • But `\n` also has special meaning, so if it's something like that I'd expect more letters to cause problems. – Barmar Jan 22 '18 at 20:46
  • can you include an example of such filenames that give you trouble? Full path would help more. Also, did you save those models with `save_weights`? – DarkCygnus Jan 22 '18 at 22:37
  • 1
    Also the platform, I smell a Windows-specific problem. – Dr. Snoopy Jan 22 '18 at 23:11
  • @MatiasValdenegro yep, surely because Windows uses backslashes for paths, instead of just slashes `/` ... – DarkCygnus Jan 22 '18 at 23:14

1 Answers1

3

It would greatly help debug this if you include examples of such filenames that give you trouble. However, I have a good idea on what is probably happening here.

This problems seem to appear on folders that start with r or t on their names. Also, as they are folders, on their full path name they are preceded by a \ character (for example "\thisFolder", or similar). This is true in the case of a Windows environment, as they use \ for separating paths contrary to *nix systems that use the regular slash /.

Considering these things, seems that perhaps you are experiencing this as \r and \t are both special characters that mean Carriage Return and Tabulation, respectively. If this is the case many file openers will have trouble processing such file name.

Even more, I would not be surprised if you got the same errors on folders that begin with n or other letters that when concatenated to a backslash give special characters (\n is new line, \s is a white space, etc.).

To overcome this seems that you will need to escape your backslash character before passing it as a filename. In python, an escaped backslash is "\\" . In addition, you can also opt to pass a Raw string instead, by adding the r prefix to your string, something like r"\a\raw\string". More information on escaping and raw string can be found on this question and answers.

I want to know if there are some specified rules on the filenames which should be avoided and otherwise would lead to such reading error in python,

As mentioned, you should avoid this with characters that have a special meaning with a backslash. I suggest you check here to see the characters Python accepts like this, so you can refrain from using such characters (or well use raw strings and forget about this problem).

DarkCygnus
  • 7,420
  • 4
  • 36
  • 59