排除特定文件的模式
我正在尝试创建正则表达式,该正则将在某些目录中列出所有.jpg
,但少数文件(静态,而不是模式)。
因此,我已经写了这篇文章:(Python)
"^(?!358097_sat!823133_sat!140860_sat).*jpg$"
"^(?!358097_sat|823133_sat|140860_sat).*jpg$"
我想列出所有JPEG文件,除了:
- 358097_SAT
- 823133_SAT
- 140860_SAT
,但它给我一个错误,说没有找到与此模式相匹配的文件。
这是完整的。字符串和错误消息:
No files matched pattern: ../input/dataset/valid/^(?!358097_sat!823133_sat!140860_sat).*jpg$
我实际上将此正则态度传递给TF功能:
tf.data.Dataset.list_files(dataset_path + val_data + "^(?!358097_sat|823133_sat|140860_sat).*jpg$", seed=SEED)
# dataset_path = "../input/dataset/"
# val_data = "valid/"
完全错误:
*InvalidArgumentError:预期'tf.tensor(false,shape =(),dtype = bool)'为true。汇总数据:b'no文件匹配模式:../ input/dataset/valive/^(?!358097_SAT | 823133_SAT | 140860_SAT)。 jpg $'
这是功能参考:< “ https://www.tensorflow.org/api_docs/python/tf/data/dataset#list_files” rel =“ nofollow noreferrer”> https:///www.tensorflow.org.org/papi_org/api_docs/api_docs/pytyon/python/python/tff/datatap /ddatapat, list_files
I'm trying to create regex which will list all .jpg
in some directory except few files(static, not a pattern).
So, I've wrote this:(Python)
"^(?!358097_sat!823133_sat!140860_sat).*jpgquot;
"^(?!358097_sat|823133_sat|140860_sat).*jpgquot;
I want to list all JPEG files except for:
- 358097_sat
- 823133_sat
- 140860_sat
But it gives me an error saying that no file found matching this pattern.
Here is the complete string and error message:
No files matched pattern: ../input/dataset/valid/^(?!358097_sat!823133_sat!140860_sat).*jpg$
I'm actually passing this regex to a tf-function:
tf.data.Dataset.list_files(dataset_path + val_data + "^(?!358097_sat|823133_sat|140860_sat).*jpgquot;, seed=SEED)
# dataset_path = "../input/dataset/"
# val_data = "valid/"
Complete error:
*InvalidArgumentError: Expected 'tf.Tensor(False, shape=(), dtype=bool)' to be true. Summarized data: b'No files matched pattern: ../input/dataset/valid/^(?!358097_sat|823133_sat|140860_sat).jpg$'
Here is the function reference: https://www.tensorflow.org/api_docs/python/tf/data/Dataset#list_files
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
静态方法
list_files
期望包含,不是正则表达式。另请参见 filename匹配。
使用 globs 匹配的文件名匹配没有方法来否定匹配。因此,您将必须编写自定义功能才能做到这一点。
您可以使用eg
glob.glob()
生成JPEG文件列表,然后过滤符合符合您的字符串的文件。The static method
list_files
expects a string or list of strings containing globs, not regular expressions.See also filename matching.
Filename matching using globs does not have a way to negate a match. So you will have to write a custom function to do that.
You could use e.g.
glob.glob()
to generate a list of JPEG files, and then filter out the ones that match your strings.