open-mmlab / mmocr

OpenMMLab Text Detection, Recognition and Understanding Toolbox
https://mmocr.readthedocs.io/en/dev-1.x/
Apache License 2.0
4.27k stars 743 forks source link

RuntimeError when loading FCENet model #232

Closed dev-99 closed 3 years ago

dev-99 commented 3 years ago

Thank you for the good work with mmocr!

I'm trying out the tutorial for text detection(demo/MMOCR_Tutorial.ipynb) using the Dockerfile.

The default PANet model is working. However, when I try switching to other models, I get this error:

from argparse import ArgumentParser

import mmcv
from mmdet.apis import init_detector
from mmocr.apis.inference import model_inference
from mmocr.datasets import build_dataset  # noqa: F401
from mmocr.models import build_detector  # noqa: F401

config = "configs/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500.py"
checkpoint = "https://download.openmmlab.com/mmocr/textdet/fcenetfcenet_r50dcnv2_fpn_1500e_ctw1500-05d740bb.pth"

model = init_detector(config, checkpoint, device='cpu')
if model.cfg.data.test['type'] == 'ConcatDataset':
    model.cfg.data.test.pipeline = model.cfg.data.test['datasets'][
        0].pipeline
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-2a869a5a5391> in <module>
      2 input_image = "demo/demo_text_det.jpg"
      3 
----> 4 model = init_detector(config, checkpoint, device='cpu')
      5 if model.cfg.data.test['type'] == 'ConcatDataset':
      6     model.cfg.data.test.pipeline = model.cfg.data.test['datasets'][

/opt/conda/lib/python3.7/site-packages/mmdet/apis/inference.py in init_detector(config, checkpoint, device, cfg_options)
     40     if checkpoint is not None:
     41         map_loc = 'cpu' if device == 'cpu' else None
---> 42         checkpoint = load_checkpoint(model, checkpoint, map_location=map_loc)
     43         if 'CLASSES' in checkpoint.get('meta', {}):
     44             model.CLASSES = checkpoint['meta']['CLASSES']

/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py in load_checkpoint(model, filename, map_location, strict, logger, revise_keys)
    511         dict or OrderedDict: The loaded checkpoint.
    512     """
--> 513     checkpoint = _load_checkpoint(filename, map_location, logger)
    514     # OrderedDict is a subclass of dict
    515     if not isinstance(checkpoint, dict):

/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py in _load_checkpoint(filename, map_location, logger)
    449            information, which depends on the checkpoint.
    450     """
--> 451     return CheckpointLoader.load_checkpoint(filename, map_location, logger)
    452 
    453 

/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py in load_checkpoint(cls, filename, map_location, logger)
    242         class_name = checkpoint_loader.__name__
    243         mmcv.print_log(f'Use {class_name} loader', logger)
--> 244         return checkpoint_loader(filename, map_location)
    245 
    246 

/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py in load_from_http(filename, map_location, model_dir)
    282     if rank == 0:
    283         checkpoint = model_zoo.load_url(
--> 284             filename, model_dir=model_dir, map_location=map_location)
    285     if world_size > 1:
    286         torch.distributed.barrier()

/opt/conda/lib/python3.7/site-packages/torch/hub.py in load_state_dict_from_url(url, model_dir, map_location, progress, check_hash)
    502             members = cached_zipfile.infolist()
    503             if len(members) != 1:
--> 504                 raise RuntimeError('Only one file(not dir) is allowed in the zipfile')
    505             cached_zipfile.extractall(model_dir)
    506             extraced_name = members[0].filename

RuntimeError: Only one file(not dir) is allowed in the zipfile

Is there anything that I miss here? 🤔

cuhk-hbsun commented 3 years ago

@dev-99 Thanks for your feedback. I have checked and everything is ok. And the error is that you missed / after fcenet in checkpoint path https://download.openmmlab.com/mmocr/textdet/fcenetfcenet_r50dcnv2_fpn_1500e_ctw1500-05d740bb.pth.

Correct ckpt path is https://download.openmmlab.com/mmocr/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500-05d740bb.pth

cuhk-hbsun commented 3 years ago

fixed