Python错误:__call__() got an unexpected keyword argument ‘partition_info‘

1151 篇文章 ¥299.90 ¥399.90
当调用Python函数时遇到'call() got an unexpected keyword argument 'partition_info''错误,通常是因为传递了不被支持的参数。检查代码中函数调用的参数,确保正确传递,或查阅函数文档确认参数名称。

Python错误:call() got an unexpected keyword argument ‘partition_info’

当你在使用Python编写代码时,有时可能会遇到各种各样的错误信息。其中一个常见的错误就是“call() got an unexpected keyword argument ‘partition_info’”。

这个错误通常是由于在调用函数时传递了不正确的参数,特别是关键词参数。

具体来说,这个错误通常是由于尝试使用partition_info参数来调用一个不支持该参数的函数造成的。在这种情况下,Python会引发上述错误来告诉你发生了什么。

为了解决这个问题,你可以检查你的代码以找出调用函数的位置,并检查是否正确地传递了参数。如果你确定你传递了正确的参数,那么你可能需要查找一下该函数的文档,以确保你正在使用正确的参数名称。

以下是一个示例代码,展示了如何在调用函数时出现“call() got an unexpected keyword argument ‘partition_info’”错误:

def some_function(arg1, arg2):
    # do something with arguments
    pass

some_function(arg1=1, arg2=2, partition_info=True)

在这个例子中,我们向some_function()函数传递了一个名为partition_info的关键词参数,但是该函数不支持该参数,并且因此引发了“call() got an unexpected keyword argument ‘partition_info’”错误。

--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[2], line 1 ----> 1 elements = partition_pdf( 2 filename="2024发注方针企划书(移动互联)10.31.pdf", 3 # strategy="hi_res", 4 extract_images_in_pdf=True, 5 # extract_image_block_types=["Image", "Table"], 6 infer_table_strategy=True, 7 hi_res_model_name='yolox', 8 languages=['chi_sim'] 9 ) File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/documents/elements.py:585, in process_metadata.<locals>.decorator.<locals>.wrapper(*args, **kwargs) 583 @functools.wraps(func) 584 def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> list[Element]: --> 585 elements = func(*args, **kwargs) 586 call_args = get_call_args_applying_defaults(func, *args, **kwargs) 588 unique_element_ids: bool = call_args.get("unique_element_ids", False) File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/file_utils/filetype.py:811, in add_filetype.<locals>.decorator.<locals>.wrapper(*args, **kwargs) 809 @functools.wraps(func) 810 def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> list[Element]: --> 811 elements = func(*args, **kwargs) 813 for element in elements: 814 # NOTE(robinson) - Attached files have already run through this logic 815 # in their own partitioning function 816 if element.metadata.attached_to_filename is None: File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/file_utils/filetype.py:769, in add_metadata.<locals>.wrapper(*args, **kwargs) 767 @functools.wraps(func) 768 def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> list[Element]: --> 769 elements = func(*args, **kwargs) 770 call_args = get_call_args_applying_defaults(func, *args, **kwargs) 772 if call_args.get("metadata_filename"): File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/chunking/dispatch.py:74, in add_chunking_strategy.<locals>.wrapper(*args, **kwargs) 71 """The decorated function is replaced with this one.""" 73 # -- call the partitioning function to get the elements -- ---> 74 elements = func(*args, **kwargs) 76 # -- look for a chunking-strategy argument -- 77 call_args = get_call_args_applying_defaults(func, *args, **kwargs) File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/partition/pdf.py:228, in partition_pdf(filename, file, include_page_breaks, strategy, infer_table_structure, ocr_languages, languages, metadata_filename, metadata_last_modified, chunking_strategy, hi_res_model_name, extract_images_in_pdf, extract_image_block_types, extract_image_block_output_dir, extract_image_block_to_payload, starting_page_number, extract_forms, form_extraction_skip_tables, password, pdfminer_line_margin, pdfminer_char_margin, pdfminer_line_overlap, pdfminer_word_margin, **kwargs) 225 exactly_one(filename=filename, file=file) 227 languages = check_language_args(languages or [], ocr_languages) --> 228 return partition_pdf_or_image( 229 filename=filename, 230 file=file, 231 include_page_breaks=include_page_breaks, 232 strategy=strategy, 233 infer_table_structure=infer_table_structure, 234 languages=languages, 235 metadata_last_modified=metadata_last_modified, 236 hi_res_model_name=hi_res_model_name, 237 extract_images_in_pdf=extract_images_in_pdf, 238 extract_image_block_types=extract_image_block_types, 239 extract_image_block_output_dir=extract_image_block_output_dir, 240 extract_image_block_to_payload=extract_image_block_to_payload, 241 starting_page_number=starting_page_number, 242 extract_forms=extract_forms, 243 form_extraction_skip_tables=form_extraction_skip_tables, 244 password=password, 245 pdfminer_line_margin=pdfminer_line_margin, 246 pdfminer_char_margin=pdfminer_char_margin, 247 pdfminer_line_overlap=pdfminer_line_overlap, 248 pdfminer_word_margin=pdfminer_word_margin, 249 **kwargs, 250 ) File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/partition/pdf.py:341, in partition_pdf_or_image(filename, file, is_image, include_page_breaks, strategy, infer_table_structure, languages, metadata_last_modified, hi_res_model_name, extract_images_in_pdf, extract_image_block_types, extract_image_block_output_dir, extract_image_block_to_payload, starting_page_number, extract_forms, form_extraction_skip_tables, password, pdfminer_line_margin, pdfminer_char_margin, pdfminer_line_overlap, pdfminer_word_margin, ocr_agent, table_ocr_agent, **kwargs) 339 with warnings.catch_warnings(): 340 warnings.simplefilter("ignore") --> 341 elements = _partition_pdf_or_image_local( 342 filename=filename, 343 file=spooled_to_bytes_io_if_needed(file), 344 is_image=is_image, 345 infer_table_structure=infer_table_structure, 346 include_page_breaks=include_page_breaks, 347 languages=languages, 348 ocr_languages=ocr_languages, 349 metadata_last_modified=metadata_last_modified or last_modified, 350 hi_res_model_name=hi_res_model_name, 351 pdf_text_extractable=pdf_text_extractable, 352 extract_images_in_pdf=extract_images_in_pdf, 353 extract_image_block_types=extract_image_block_types, 354 extract_image_block_output_dir=extract_image_block_output_dir, 355 extract_image_block_to_payload=extract_image_block_to_payload, 356 starting_page_number=starting_page_number, 357 extract_forms=extract_forms, 358 form_extraction_skip_tables=form_extraction_skip_tables, 359 password=password, 360 pdfminer_config=pdfminer_config, 361 ocr_agent=ocr_agent, 362 table_ocr_agent=table_ocr_agent, 363 **kwargs, 364 ) 365 # NOTE(crag): do not call _process_uncategorized_text_elements here, because 366 # extracted elements (which are text blocks outside of OD-determined blocks) 367 # are likely not Titles and should not be identified as such. 368 return elements File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/utils.py:216, in requires_dependencies.<locals>.decorator.<locals>.wrapper(*args, **kwargs) 213 @wraps(func) 214 def wrapper(*args: _P.args, **kwargs: _P.kwargs): 215 run_check() --> 216 return func(*args, **kwargs) File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured/partition/pdf.py:649, in _partition_pdf_or_image_local(filename, file, is_image, infer_table_structure, include_page_breaks, languages, ocr_languages, ocr_mode, model_name, hi_res_model_name, pdf_image_dpi, metadata_last_modified, pdf_text_extractable, extract_images_in_pdf, extract_image_block_types, extract_image_block_output_dir, extract_image_block_to_payload, analysis, analyzed_image_output_dir_path, starting_page_number, extract_forms, form_extraction_skip_tables, pdf_hi_res_max_pages, password, pdfminer_config, ocr_agent, table_ocr_agent, **kwargs) 646 skip_analysis_dump = env_config.ANALYSIS_DUMP_OD_SKIP 648 if file is None: --> 649 inferred_document_layout = process_file_with_model( 650 filename, 651 is_image=is_image, 652 model_name=hi_res_model_name, 653 pdf_image_dpi=pdf_image_dpi, 654 password=password, 655 ) 657 extracted_layout, layouts_links = ( 658 process_file_with_pdfminer( 659 filename=filename, (...) 665 else ([], []) 666 ) 668 if analysis: File ~/anaconda3/envs/py3-11-7/lib/python3.11/site-packages/unstructured_inference/inference/layout.py:386, in process_file_with_model(filename, model_name, is_image, fixed_layouts, extract_tables, pdf_image_dpi, **kwargs) 374 def process_file_with_model( 375 filename: str, 376 model_name: Optional[str], (...) 381 **kwargs, 382 ) -> DocumentLayout: 383 """Processes pdf file with name filename into a DocumentLayout by using a model identified by 384 model_name.""" --> 386 model = get_model(model_name, **kwargs) 387 if isinstance(model, UnstructuredObjectDetectionModel): 388 detection_model = model TypeError: get_model() got an unexpected keyword argument 'password'
07-11
<think>好的,我现在遇到了一个Python错误:TypeError: __call__() got an unexpected keyword argument 'epoch'。需要解决这个问题。首先,我要理解这个错误的原因。 根据用户提供的引用,比如引用[3]和[5],之前的类似错误是因为参数名过时,比如nb_epoch被替换成了epochs。可能这里的'epoch'参数也是类似的情况,可能在新版本中参数名被修改或者移除了。 接下来,我需要检查出现这个错误的代码位置。例如,是否在调用某个方法时传入了'epoch'这个关键字参数?比如在模型训练时,可能有一个调用类似于model.fit(epoch=10)或者其他函数调用中包含epoch参数。但根据错误信息,是__call__方法收到了意外的'epoch'参数,这可能发生在使用某些库的API时,比如Keras、TensorFlow或者PyTorch Lightning等。 需要查看具体的代码行,比如是否有类似这样的代码: ```python model(epoch=10) ``` 或者是在回调函数中使用epoch参数。比如自定义的回调函数或者训练循环中错误地传递了epoch参数。 根据引用中的例子,比如fit()函数参数的变化,可能某些库更新后参数名称发生了变化,或者某些方法的参数列表不再支持'epoch'这个关键字。例如,可能在某个版本的更新中,将'epoch'参数重命名为'epochs',或者该参数被移除了,需要改用其他方式传递。 可能的解决步骤包括: 1. 检查触发错误的代码行,确认哪里调用了包含'epoch'参数的方法。 2. 查阅该方法的官方文档,确认参数的正确名称和用法。 3. 根据文档修改参数名,例如将'epoch'改为'epochs',或者删除该参数,如果它已经被弃用。 4. 检查是否有第三方库的版本问题,可能需要升级或降级库版本以兼容参数名称。 比如,假设在Keras中,用户可能在自定义训练循环中错误地传递了'epoch'参数,而正确的参数名可能是'epochs'。或者在使用某个回调函数时,错误地添加了'epoch'参数,而该回调函数并不接受这个参数。 另外,参考引用[4]中的情况,另一个库Ignite在版本更新后移除了某个参数,可能需要查找当前使用的库的文档,确认参数是否仍然有效。例如,用户可能在调用某个类的__init__方法或__call__方法时,传入了已被移除的参数。 可能的解决方案: - 将参数名从'epoch'改为正确的名称,比如'epochs'。 - 如果该参数不再需要,直接删除该参数。 - 更新库到兼容的版本,或者根据文档调整代码。 例如,如果错误发生在使用Keras的model.fit()时,正确参数应为'epochs',而不是'epoch'。或者在使用某个自定义函数时,参数名拼写错误,需要修正。 总结,解决步骤: 1. 定位到具体报错的代码行,确定哪个函数调用传入了'epoch'参数。 2. 检查该函数的官方文档,确认参数的正确名称和使用方式。 3. 修改代码中的参数名或删除不必要的参数。 4. 确保使用的库版本与代码兼容,必要时调整版本。</think>要解决`TypeError: __call__() got an unexpected keyword argument 'epoch'`错误,请按照以下步骤操作: ### 错误原因分析 该错误通常是由于以下原因导致的: 1. **参数名过时或拼写错误**:某些库在版本更新后修改了参数名称(例如从`nb_epoch`改为`epochs`)[^3][^5]。 2. **API接口变更**:调用的方法(如`__call__`)不再支持`epoch`参数,可能已被移除或重命名[^4]。 3. **第三方库版本不兼容**:代码使用的参数与当前安装的库版本不匹配。 --- ### 解决步骤 1. **定位错误代码行** 找到报错代码中调用`__call__()`方法并传递`epoch`参数的位置。例如: ```python model(epoch=10) # 错误示例 ``` 2. **核对API文档** 查阅当前使用的库(如TensorFlow/Keras/PyTorch)的官方文档,确认参数名称是否变更。例如: - Keras的`fit()`方法中,参数名为`epochs`而非`epoch`[^3]。 - 某些自定义函数或类的`__call__`方法可能不支持`epoch`参数。 3. **修改参数名称或删除参数** - **场景1:参数名拼写错误** 将`epoch`改为正确的参数名(如`epochs`): ```python model(epochs=10) # 修正后 ``` - **场景2:参数已弃用** 直接删除`epoch`参数(若已无需传递): ```python model() # 修正后 ``` 4. **检查库版本兼容性** - 升级或降级第三方库至兼容版本。例如: ```bash pip install tensorflow==2.6.0 # 指定版本 ``` - 查看库的更新日志,确认参数变更历史。 --- ### 示例修正 假设错误出现在自定义训练循环中: ```python # 错误代码 trainer.__call__(data, epoch=5) ``` 修正为: ```python # 正确代码(假设参数名应为num_epochs) trainer.__call__(data, num_epochs=5) ``` --- ### 相关问题 1. **如何查看Python函数的参数列表?** 使用`help(func_name)`或`inspect`模块检查函数定义。 2. **如何避免API变更导致的错误?** 定期查阅库的官方文档,并在升级版本前阅读更新说明。 3. **TypeError的其他常见原因有哪些?** 包括参数类型不匹配、参数数量错误等,需结合具体报错信息分析。 --- 通过上述步骤,可针对性解决因参数名变更或API调整导致的`TypeError`问题。若仍存在疑问,建议提供具体代码段以便进一步分析。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值