我正在使用本教程“ https://github.com/emrecdem/exploface/blob/master/TUTORIALS/tutorial1.ipynb”之后的“ exploface”,除了“ 4.使用Exploface编写Elan文件”这一点没有问题。
此内容在本教程中提供:
dataframe_timestamp = exploface.write_elan_file(feature_detections,
video_path=video_file,
output_path="video.eaf",
)
我正在尝试的是:
dataframe_timestamp = exploface.write_elan_file('frame',
'timestamp', 'confidence',
video_path=video_file,
output_path="C:\\Users\\fullname\\Desktop",
)
也尝试过:
dataframe_timestamp = exploface.write_elan_file('frame',
'timestamp', 'confidence',
video_path=video_file,
output_path="C:\\Users\\fullname\\Desktop\\output.eaf",
)
而且我也试图将其指向原始视频
dataframe_timestamp = exploface.write_elan_file('frame',
'timestamp', 'confidence',
video_path="C:\\Users\\fullname\\Desktop\\originalvideo.mp4",
output_path="C:\\Users\\fullname\\Desktop\\output.eaf",
)
应该创建elan文件,但给出此错误消息:
File "<stdin>", line 3, in <module>
TypeError: write_elan_file() got multiple values for argument
'video_path'
感谢您的支持,对我的无礼表示歉意。...
我已经检查了Exploface仓库并且功能write_elan_file
定义如下。
# exploface/__init__.py
def write_elan_file(detections,
output_path=None,
video_path=None,
#column_selection = None,
):
"""
Generates an Elan file for the detections
"""
elanwriter.write_elan_file(detections, video_path, output_path,
feature_col_name = _FEAT_NAME_ID)
产生您的问题的错误是因为您将太多参数传递给仅接受3的函数。
错误是关于您的代码,而不是您输入到函数中的数据,因此从这个角度来看,后三个示例都是相同的。
问题是,video_path="whatever"
试图传递一些值作为称为video_path
的参数,但positional参数之一却做同样的事情:
dataframe_timestamp = exploface.write_elan_file(
'frame', # from the tutorial we know that this is NOT the `video_path` argument
'timestamp', # the second positional argument may be called `video_path`
'confidence', # the third positional argument may be called `video_path`
video_path=video_file,
...
)
因此,根据错误消息,三个positional参数之一被称为video_path
,但是您使用的是与video_path=video_file
相同的参数作为关键字参数。因此,同一个参数'timestamp'
有多个值('confidence'
和video_file
之一以及video_path
)。
要解决此问题,请在文档中或使用help(exploface.write_elan_file)
查找此函数的签名,并查看该函数期望什么样的参数并记录其位置。
以下是具有相同问题的更简单的代码:
传递为相同的参数>>> def hello(name): ... print(f"Hello, {name}!") ... >>> hello("Skyandlow") Hello, Skyandlow! >>> hello("Skyandlow", name="ForceBru") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: hello() got multiple values for argument 'name' >>>
调用
hello("Skyandlow", name="ForceBru")
尝试将"Skyandlow"
作为第一个参数(从函数的定义中可以看到,称为name
)和"ForceBru"
作为参数name
传递。这没有任何意义,因为我们因此将两个值
name
。