DD144 2025-03-09 20:47 采纳率: 0%
浏览 4

Table-Master代码训练报错

报错信息:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.HalfTensor [8, 256, 40, 40]], which is output 0 of ReluBackward0, is at version 1; expected version 0 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!
运行table-maste时,运行指令 sh ./table_recognition/expr/table_text_line_detection_dist_train.sh 报错,请问怎么解决啊

  • 写回答

3条回答 默认 最新

  • 道友老李 JWE233286一种基于机器视觉的水表指针读数识别及修正的方法 专利发明者 2025-03-09 20:47
    关注
    让【道友老李】来帮你解答,本回答参考gpt编写,并整理提供,如果还有疑问可以点击头像关注私信或评论。
    如果答案让您满意,请采纳、关注,非常感谢!
    这个报错是由于在计算梯度时,某个变量被inplace操作修改了版本号导致的。解决方法是避免使用inplace操作,例如使用`clone()`来创建一个新的变量而不是在原变量上进行操作。 在PyTorch中,常见的inplace操作包括`tensor1 += tensor2`、`tensor1 *= 2`等,这些操作会改变原始tensor的值,可能会导致梯度计算出错。可以尝试修改代码避免使用这些inplace操作。 以下是一个可能的实现代码:
    import torch
    # 示例代码,可能不完全符合实际情况,具体根据实际代码修改
    # 原始代码中的inplace操作
    # tensor1 += tensor2
    # 修改为非inplace操作
    # tensor1 = tensor1 + tensor2
    # 或者使用clone方法
    # tensor1 = tensor1.clone()
    # tensor1 += tensor2
    

    通过修改代码中的inplace操作,可以避免出现RuntimeError的报错信息。希望能帮到你解决问题。

    评论

报告相同问题?

问题事件

  • 创建了问题 3月9日