问题描述:在使用TrOCR预训练模型(如trocr-base-stage1.pt,trocr-base-printed.pt等)时,遇到了一个错误。当运行以下脚本时,会出现以下错误:AssertionError: Could not infer model type from Namespace
。
错误发生在以下代码段中:
if __name__ == '__main__':
model_path = '/content/trocr-base-printed.pt'
jpg_path = "/content/pan4.jpeg"
beam = 5
model, cfg, task, generator, bpe, img_transform, device = init(model_path, beam)
sample = preprocess(jpg_path, img_transform)
text = get_text(cfg, generator, model, sample, bpe)
print(text)
print('done')
=======================================================================
### | [label] load dictionary: 50265 types
错误原因:在初始化模型时,无法从Namespace中推断出模型类型。
2条答案
按热度按时间t1rydlwq1#
"trocr-base-printed"在我这边运行正常,"trocr-base-stage1"的错误已经修复,请再次尝试。
如果"trocr-base-printed"仍然出现错误,能否向我展示完整的错误信息?谢谢~:)
ldioqlga2#
你好,
我正在面临与"trocr-large-printed"相同的问题。有任何解决方案吗?
谢谢!