开发者社区 > ModelScope模型即服务 > 正文

使用modelscope的数据集加载器出现输入类型异常

  1. 根据使用说明:https://www.modelscope.cn/docs/%E6%95%B0%E6%8D%AE%E9%9B%86%E4%BB%8B%E7%BB%8D
  2. 基于OCR模型:iic/cv_convnextTiny_ocr-recognition-general_damo整合数据集:damo/ICDAR13_HCTR_Dataset
  3. 在调用:trainer.train()方法进行训练时发生异常:
Traceback (most recent call last):
  File "C:\Users\user\.conda\envs\ocr\Lib\site-packages\torch\utils\data\dataloader.py", line 631, in __next__
    data = self._next_data()
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\user\.conda\envs\ocr\Lib\site-packages\torch\utils\data\dataloader.py", line 675, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\.conda\envs\ocr\Lib\site-packages\torch\utils\data\_utils\fetch.py", line 51, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\.conda\envs\ocr\Lib\site-packages\torch\utils\data\_utils\fetch.py", line 51, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
            ~~~~~~~~~~~~^^^^^
  File "C:\Users\user\.conda\envs\ocr\Lib\site-packages\modelscope\msdatasets\dataset_cls\custom_datasets\torch_custom_dataset.py", line 25, in __getitem__
    return self.preprocessor(
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\.conda\envs\ocr\Lib\site-packages\modelscope\models\cv\ocr_recognition\preprocessor.py", line 75, in __call__
    raise TypeError(
TypeError: inputs should be either (a list of) str, PIL.Image, np.array, but got <class 'dict'>

源代码如下:



model_dir = "R:/AI_models"
model_id = "iic/cv_convnextTiny_ocr-recognition-general_damo"
dataset_dir = "R:/dataset"
ICDAR_dataset_id = "damo/ICDAR13_HCTR_Dataset"
PEOPLE_dataset_id = "iic/people_daily_ner_1998_tiny"
FUNDAN_dataset_id = "modelscope/ocr_fudanvi_zh"

work_dir = "..//OCR//work"
def _cfg_modify_fn(cfg):
    cfg.train.max_epochs = 30
    return cfg
train_dataset = MsDataset.load(cache_dir=dataset_dir,
                               dataset_name=FUNDAN_dataset_id, subset_name='scene', split='train')
test_dataset = MsDataset.load(cache_dir=dataset_dir,
                              dataset_name=FUNDAN_dataset_id, subset_name='scene', split='test')

kwargs = dict(
    model=path_concat(model_dir, model_id),
    train_dataset=train_dataset,
    eval_dataset=test_dataset,
    work_dir=work_dir,
    cfg_modify_fn=_cfg_modify_fn)

trainer = build_trainer(name=Trainers.ocr_recognition, default_args=kwargs)
trainer.train()

展开
收起
游客q6dyhsoqysd74 2024-05-20 16:56:18 49 0
0 条回答
写回答
取消 提交回答

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!欢迎加入技术交流群:微信公众号:魔搭ModelScope社区,钉钉群号:44837352

热门讨论

热门文章

相关电子书

更多
视觉AI能力的开放现状及ModelScope实战 立即下载
ModelScope助力语音AI模型创新与应用 立即下载
低代码开发师(初级)实战教程 立即下载