Closed matsutaku44 closed 12 months ago
Hello. Thanks for great project.
I faced with an error "TypeError: issubclass() arg 1 must be a class" when I use "python main.py --image_src [image_path] --out_image_name [out_file_name]".
I don't know how to solve it. Please give me an advice.
I used these commands for making an environment.
full error code here. ↓
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/main.py:2 in │ │ │ │ 1 import argparse │ │ ❱ 2 from models.image_text_transformation import ImageTextTransformation │ │ 3 from utils.util import display_images_and_text │ │ 4 │ │ 5 if name == 'main': │ │ │ │ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/models/image_text_transformation.py:5 in │ │ │ │ │ │ 2 from models.grit_model import DenseCaptioning │ │ 3 from models.gpt_model import ImageToText │ │ 4 from models.controlnet_model import TextToImage │ │ ❱ 5 from models.region_semantic import RegionSemantic │ │ 6 from utils.util import read_image_width_height, display_images_and_text, resize_long_edg │ │ 7 import argparse │ │ 8 from PIL import Image │ │ │ │ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/models/region_semantic.py:2 in │ │ │ │ 1 from models.segment_models.semgent_anything_model import SegmentAnything │ │ ❱ 2 from models.segment_models.semantic_segment_anything_model import SemanticSegment │ │ 3 from models.segment_models.edit_anything_model import EditAnything │ │ 4 │ │ 5 │ │ │ │ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/models/segment_models/semantic_segment_a │ │ nything_model.py:16 in │ │ │ │ 13 from utils.util import resize_long_edge, resize_long_edge_cv2 │ │ 14 # from mmdet.core.visualization.image import imshow_det_bboxes # comment this line if yo │ │ 15 │ │ ❱ 16 nlp = spacy.load('en_core_web_sm') │ │ 17 │ │ 18 class SemanticSegment(): │ │ 19 │ def init(self, device): │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/init.py:50 in load │ │ │ │ 47 │ │ keyed by section values in dot notation. │ │ 48 │ RETURNS (Language): The loaded nlp object. │ │ 49 │ """ │ │ ❱ 50 │ return util.load_model( │ │ 51 │ │ name, vocab=vocab, disable=disable, exclude=exclude, config=config │ │ 52 │ ) │ │ 53 │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:324 in │ │ load_model │ │ │ │ 321 │ │ if name.startswith("blank:"): # shortcut for blank model │ │ 322 │ │ │ return get_lang_class(name.replace("blank:", ""))() │ │ 323 │ │ if is_package(name): # installed as package │ │ ❱ 324 │ │ │ return load_model_from_package(name, kwargs) │ │ 325 │ │ if Path(name).exists(): # path to model data directory │ │ 326 │ │ │ return load_model_from_path(Path(name), kwargs) │ │ 327 │ elif hasattr(name, "exists"): # Path or Path-like to model data │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:357 in │ │ load_model_from_package │ │ │ │ 354 │ RETURNS (Language): The loaded nlp object. │ │ 355 │ """ │ │ 356 │ cls = importlib.import_module(name) │ │ ❱ 357 │ return cls.load(vocab=vocab, disable=disable, exclude=exclude, config=config) │ │ 358 │ │ 359 │ │ 360 def load_model_from_path( │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/en_core_web_sm/init.py:10 │ │ in load │ │ │ │ 7 │ │ 8 │ │ 9 def load(overrides): │ │ ❱ 10 │ return load_model_from_init_py(file, overrides) │ │ 11 │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:517 in │ │ load_model_from_init_py │ │ │ │ 514 │ data_path = model_path / data_dir │ │ 515 │ if not model_path.exists(): │ │ 516 │ │ raise IOError(Errors.E052.format(path=data_path)) │ │ ❱ 517 │ return load_model_from_path( │ │ 518 │ │ data_path, │ │ 519 │ │ vocab=vocab, │ │ 520 │ │ meta=meta, │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:392 in │ │ load_model_from_path │ │ │ │ 389 │ config_path = model_path / "config.cfg" │ │ 390 │ overrides = dict_to_dot(config) │ │ 391 │ config = load_config(config_path, overrides=overrides) │ │ ❱ 392 │ nlp = load_model_from_config(config, vocab=vocab, disable=disable, exclude=exclude) │ │ 393 │ return nlp.from_disk(model_path, exclude=exclude, overrides=overrides) │ │ 394 │ │ 395 │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:429 in │ │ load_model_from_config │ │ │ │ 426 │ # This will automatically handle all codes registered via the languages │ │ 427 │ # registry, including custom subclasses provided via entry points │ │ 428 │ lang_cls = get_lang_class(nlp_config["lang"]) │ │ ❱ 429 │ nlp = lang_cls.from_config( │ │ 430 │ │ config, │ │ 431 │ │ vocab=vocab, │ │ 432 │ │ disable=disable, │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/language.py:1672 in │ │ from_config │ │ │ │ 1669 │ │ │ │ │ factory = pipe_cfg.pop("factory") │ │ 1670 │ │ │ │ │ # The pipe name (key in the config) here is the unique name │ │ 1671 │ │ │ │ │ # of the component, not necessarily the factory │ │ ❱ 1672 │ │ │ │ │ nlp.add_pipe( │ │ 1673 │ │ │ │ │ │ factory, │ │ 1674 │ │ │ │ │ │ name=pipe_name, │ │ 1675 │ │ │ │ │ │ config=pipe_cfg, │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/language.py:774 in │ │ add_pipe │ │ │ │ 771 │ │ │ │ │ lang=util.get_object_name(self), │ │ 772 │ │ │ │ │ lang_code=self.lang, │ │ 773 │ │ │ │ ) │ │ ❱ 774 │ │ │ pipe_component = self.create_pipe( │ │ 775 │ │ │ │ factory_name, │ │ 776 │ │ │ │ name=name, │ │ 777 │ │ │ │ config=config, │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/language.py:660 in │ │ create_pipe │ │ │ │ 657 │ │ cfg = {factory_name: config} │ │ 658 │ │ # We're calling the internal _fill here to avoid constructing the │ │ 659 │ │ # registered functions twice │ │ ❱ 660 │ │ resolved = registry.resolve(cfg, validate=validate) │ │ 661 │ │ filled = registry.fill({"cfg": cfg[factory_name]}, validate=validate)["cfg"] │ │ 662 │ │ filled = Config(filled) │ │ 663 │ │ filled["factory"] = factoryname │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:746 in │ │ resolve │ │ │ │ 743 │ │ overrides: Dict[str, Any] = {}, │ │ 744 │ │ validate: bool = True, │ │ 745 │ ) -> Dict[str, Any]: │ │ ❱ 746 │ │ resolved, = cls._make( │ │ 747 │ │ │ config, schema=schema, overrides=overrides, validate=validate, resolve=True │ │ 748 │ │ ) │ │ 749 │ │ return resolved │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:795 in _make │ │ │ │ 792 │ │ orig_config = config │ │ 793 │ │ if not is_interpolated: │ │ 794 │ │ │ config = Config(origconfig).interpolate() │ │ ❱ 795 │ │ filled, , resolved = cls._fill( │ │ 796 │ │ │ config, schema, validate=validate, overrides=overrides, resolve=resolve │ │ 797 │ │ ) │ │ 798 │ │ filled = Config(filled, section_order=section_order) │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:850 in _fill │ │ │ │ 847 │ │ │ │ │ field = schema.fields[key] │ │ 848 │ │ │ │ │ schema.fields[key] = copy_model_field(field, Any) │ │ 849 │ │ │ │ promise_schema = cls.make_promise_schema(value, resolve=resolve) │ │ ❱ 850 │ │ │ │ filled[key], validation[v_key], final[key] = cls._fill( │ │ 851 │ │ │ │ │ value, │ │ 852 │ │ │ │ │ promise_schema, │ │ 853 │ │ │ │ │ validate=validate, │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:849 in _fill │ │ │ │ 846 │ │ │ │ │ # validation if it doesn't receive the function return value │ │ 847 │ │ │ │ │ field = schema.fields[key] │ │ 848 │ │ │ │ │ schema.fields[key] = copy_model_field(field, Any) │ │ ❱ 849 │ │ │ │ promise_schema = cls.make_promise_schema(value, resolve=resolve) │ │ 850 │ │ │ │ filled[key], validation[v_key], final[key] = cls._fill( │ │ 851 │ │ │ │ │ value, │ │ 852 │ │ │ │ │ promise_schema, │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:1057 in │ │ make_promise_schema │ │ │ │ 1054 │ │ │ │ name = RESERVED_FIELDS.get(param.name, param.name) │ │ 1055 │ │ │ │ sig_args[name] = (annotation, default) │ │ 1056 │ │ sig_args["config"] = _PromiseSchemaConfig │ │ ❱ 1057 │ │ return create_model("ArgModel", **sig_args) │ │ 1058 │ │ 1059 │ │ 1060 all = ["Config", "registry", "ConfigValidationError"] │ │ │ │ in pydantic.main.create_model:990 │ │ │ │ in pydantic.main.ModelMetaclass.new:299 │ │ │ │ in pydantic.fields.ModelField.infer:411 │ │ │ │ in pydantic.fields.ModelField.init:342 │ │ │ │ in pydantic.fields.ModelField.prepare:451 │ │ │ │ in pydantic.fields.ModelField._type_analysis:550 │ │ │ │ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/typing.py:774 in subclasscheck │ │ │ │ 771 │ def subclasscheck(self, cls): │ │ 772 │ │ if self._special: │ │ 773 │ │ │ if not isinstance(cls, _GenericAlias): │ │ ❱ 774 │ │ │ │ return issubclass(cls, self.origin) │ │ 775 │ │ │ if cls._special: │ │ 776 │ │ │ │ return issubclass(cls.origin, self.origin) │ │ 777 │ │ raise TypeError("Subscripted generics cannot be used with" │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: issubclass() arg 1 must be a class
pip install pydantic==1.7.4
@1ChachA Thank you very much! I apologize for my delayed gratitude.
Hello. Thanks for great project.
I faced with an error "TypeError: issubclass() arg 1 must be a class" when I use "python main.py --image_src [image_path] --out_image_name [out_file_name]".
I don't know how to solve it. Please give me an advice.
I used these commands for making an environment.
full error code here. ↓
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/main.py:2 in │
│ │
│ 1 import argparse │
│ ❱ 2 from models.image_text_transformation import ImageTextTransformation │
│ 3 from utils.util import display_images_and_text │
│ 4 │
│ 5 if name == 'main': │
│ │
│ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/models/image_text_transformation.py:5 in │
│ │
│ │
│ 2 from models.grit_model import DenseCaptioning │
│ 3 from models.gpt_model import ImageToText │
│ 4 from models.controlnet_model import TextToImage │
│ ❱ 5 from models.region_semantic import RegionSemantic │
│ 6 from utils.util import read_image_width_height, display_images_and_text, resize_long_edg │
│ 7 import argparse │
│ 8 from PIL import Image │
│ │
│ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/models/region_semantic.py:2 in │
│ │
│ 1 from models.segment_models.semgent_anything_model import SegmentAnything │
│ ❱ 2 from models.segment_models.semantic_segment_anything_model import SemanticSegment │
│ 3 from models.segment_models.edit_anything_model import EditAnything │
│ 4 │
│ 5 │
│ │
│ /home/matsuzaki.takumi/workspace/nissan/Image2Paragraph/models/segment_models/semantic_segment_a │
│ nything_model.py:16 in │
│ │
│ 13 from utils.util import resize_long_edge, resize_long_edge_cv2 │
│ 14 # from mmdet.core.visualization.image import imshow_det_bboxes # comment this line if yo │
│ 15 │
│ ❱ 16 nlp = spacy.load('en_core_web_sm') │
│ 17 │
│ 18 class SemanticSegment(): │
│ 19 │ def init(self, device): │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/init.py:50 in load │
│ │
│ 47 │ │ keyed by section values in dot notation. │
│ 48 │ RETURNS (Language): The loaded nlp object. │
│ 49 │ """ │
│ ❱ 50 │ return util.load_model( │
│ 51 │ │ name, vocab=vocab, disable=disable, exclude=exclude, config=config │
│ 52 │ ) │
│ 53 │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:324 in │
│ load_model │
│ │
│ 321 │ │ if name.startswith("blank:"): # shortcut for blank model │
│ 322 │ │ │ return get_lang_class(name.replace("blank:", ""))() │
│ 323 │ │ if is_package(name): # installed as package │
│ ❱ 324 │ │ │ return load_model_from_package(name, kwargs) │
│ 325 │ │ if Path(name).exists(): # path to model data directory │
│ 326 │ │ │ return load_model_from_path(Path(name), kwargs) │
│ 327 │ elif hasattr(name, "exists"): # Path or Path-like to model data │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:357 in │
│ load_model_from_package │
│ │
│ 354 │ RETURNS (Language): The loaded nlp object. │
│ 355 │ """ │
│ 356 │ cls = importlib.import_module(name) │
│ ❱ 357 │ return cls.load(vocab=vocab, disable=disable, exclude=exclude, config=config) │
│ 358 │
│ 359 │
│ 360 def load_model_from_path( │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/en_core_web_sm/init.py:10 │
│ in load │
│ │
│ 7 │
│ 8 │
│ 9 def load(overrides): │
│ ❱ 10 │ return load_model_from_init_py(file, overrides) │
│ 11 │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:517 in │
│ load_model_from_init_py │
│ │
│ 514 │ data_path = model_path / data_dir │
│ 515 │ if not model_path.exists(): │
│ 516 │ │ raise IOError(Errors.E052.format(path=data_path)) │
│ ❱ 517 │ return load_model_from_path( │
│ 518 │ │ data_path, │
│ 519 │ │ vocab=vocab, │
│ 520 │ │ meta=meta, │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:392 in │
│ load_model_from_path │
│ │
│ 389 │ config_path = model_path / "config.cfg" │
│ 390 │ overrides = dict_to_dot(config) │
│ 391 │ config = load_config(config_path, overrides=overrides) │
│ ❱ 392 │ nlp = load_model_from_config(config, vocab=vocab, disable=disable, exclude=exclude) │
│ 393 │ return nlp.from_disk(model_path, exclude=exclude, overrides=overrides) │
│ 394 │
│ 395 │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/util.py:429 in │
│ load_model_from_config │
│ │
│ 426 │ # This will automatically handle all codes registered via the languages │
│ 427 │ # registry, including custom subclasses provided via entry points │
│ 428 │ lang_cls = get_lang_class(nlp_config["lang"]) │
│ ❱ 429 │ nlp = lang_cls.from_config( │
│ 430 │ │ config, │
│ 431 │ │ vocab=vocab, │
│ 432 │ │ disable=disable, │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/language.py:1672 in │
│ from_config │
│ │
│ 1669 │ │ │ │ │ factory = pipe_cfg.pop("factory") │
│ 1670 │ │ │ │ │ # The pipe name (key in the config) here is the unique name │
│ 1671 │ │ │ │ │ # of the component, not necessarily the factory │
│ ❱ 1672 │ │ │ │ │ nlp.add_pipe( │
│ 1673 │ │ │ │ │ │ factory, │
│ 1674 │ │ │ │ │ │ name=pipe_name, │
│ 1675 │ │ │ │ │ │ config=pipe_cfg, │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/language.py:774 in │
│ add_pipe │
│ │
│ 771 │ │ │ │ │ lang=util.get_object_name(self), │
│ 772 │ │ │ │ │ lang_code=self.lang, │
│ 773 │ │ │ │ ) │
│ ❱ 774 │ │ │ pipe_component = self.create_pipe( │
│ 775 │ │ │ │ factory_name, │
│ 776 │ │ │ │ name=name, │
│ 777 │ │ │ │ config=config, │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/spacy/language.py:660 in │
│ create_pipe │
│ │
│ 657 │ │ cfg = {factory_name: config} │
│ 658 │ │ # We're calling the internal _fill here to avoid constructing the │
│ 659 │ │ # registered functions twice │
│ ❱ 660 │ │ resolved = registry.resolve(cfg, validate=validate) │
│ 661 │ │ filled = registry.fill({"cfg": cfg[factory_name]}, validate=validate)["cfg"] │
│ 662 │ │ filled = Config(filled) │
│ 663 │ │ filled["factory"] = factoryname │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:746 in │
│ resolve │
│ │
│ 743 │ │ overrides: Dict[str, Any] = {}, │
│ 744 │ │ validate: bool = True, │
│ 745 │ ) -> Dict[str, Any]: │
│ ❱ 746 │ │ resolved, = cls._make( │
│ 747 │ │ │ config, schema=schema, overrides=overrides, validate=validate, resolve=True │
│ 748 │ │ ) │
│ 749 │ │ return resolved │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:795 in _make │
│ │
│ 792 │ │ orig_config = config │
│ 793 │ │ if not is_interpolated: │
│ 794 │ │ │ config = Config(origconfig).interpolate() │
│ ❱ 795 │ │ filled, , resolved = cls._fill( │
│ 796 │ │ │ config, schema, validate=validate, overrides=overrides, resolve=resolve │
│ 797 │ │ ) │
│ 798 │ │ filled = Config(filled, section_order=section_order) │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:850 in _fill │
│ │
│ 847 │ │ │ │ │ field = schema.fields[key] │
│ 848 │ │ │ │ │ schema.fields[key] = copy_model_field(field, Any) │
│ 849 │ │ │ │ promise_schema = cls.make_promise_schema(value, resolve=resolve) │
│ ❱ 850 │ │ │ │ filled[key], validation[v_key], final[key] = cls._fill( │
│ 851 │ │ │ │ │ value, │
│ 852 │ │ │ │ │ promise_schema, │
│ 853 │ │ │ │ │ validate=validate, │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:849 in _fill │
│ │
│ 846 │ │ │ │ │ # validation if it doesn't receive the function return value │
│ 847 │ │ │ │ │ field = schema.fields[key] │
│ 848 │ │ │ │ │ schema.fields[key] = copy_model_field(field, Any) │
│ ❱ 849 │ │ │ │ promise_schema = cls.make_promise_schema(value, resolve=resolve) │
│ 850 │ │ │ │ filled[key], validation[v_key], final[key] = cls._fill( │
│ 851 │ │ │ │ │ value, │
│ 852 │ │ │ │ │ promise_schema, │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/site-packages/thinc/config.py:1057 in │
│ make_promise_schema │
│ │
│ 1054 │ │ │ │ name = RESERVED_FIELDS.get(param.name, param.name) │
│ 1055 │ │ │ │ sig_args[name] = (annotation, default) │
│ 1056 │ │ sig_args["config"] = _PromiseSchemaConfig │
│ ❱ 1057 │ │ return create_model("ArgModel", **sig_args) │
│ 1058 │
│ 1059 │
│ 1060 all = ["Config", "registry", "ConfigValidationError"] │
│ │
│ in pydantic.main.create_model:990 │
│ │
│ in pydantic.main.ModelMetaclass.new:299 │
│ │
│ in pydantic.fields.ModelField.infer:411 │
│ │
│ in pydantic.fields.ModelField.init:342 │
│ │
│ in pydantic.fields.ModelField.prepare:451 │
│ │
│ in pydantic.fields.ModelField._type_analysis:550 │
│ │
│ /home/matsuzaki.takumi/.conda/envs/i2p/lib/python3.8/typing.py:774 in subclasscheck │
│ │
│ 771 │ def subclasscheck(self, cls): │
│ 772 │ │ if self._special: │
│ 773 │ │ │ if not isinstance(cls, _GenericAlias): │
│ ❱ 774 │ │ │ │ return issubclass(cls, self.origin) │
│ 775 │ │ │ if cls._special: │
│ 776 │ │ │ │ return issubclass(cls.origin, self.origin) │
│ 777 │ │ raise TypeError("Subscripted generics cannot be used with" │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: issubclass() arg 1 must be a class