D-Ogi / WatermarkRemover-AI

AI-Powered Watermark Remover using Florence-2 and LaMA Models: A Python application leveraging state-of-the-art deep learning models to effectively remove watermarks from images with a user-friendly PyQt6 interface.
22 stars 6 forks source link

TypeError: Object of type Florence2LanguageConfig is not JSON serializable #2

Open wetoo-cando opened 1 month ago

wetoo-cando commented 1 month ago

After I select the I/O dirs, and press "Start batch processing", I get TypeError: Object of type Florence2LanguageConfig is not JSON serializable

What could be causing this?

Traceback (most recent call last):
  File "XYZ/src/WatermarkRemover-AI/remwm.py", line 100, in start_batch_processing
    self.worker = WatermarkRemoverThread(self.input_dir, self.output_dir, self.max_size_input.text(), self.skip_existing_combo.currentText())
  File "XYZ/src/WatermarkRemover-AI/remwm.py", line 167, in __init__
    self.florence_model = AutoModelForCausalLM.from_pretrained('microsoft/Florence-2-large', trust_remote_code=True).to(self.device).eval()
  File "XYZ/src/WatermarkRemover-AI/venv_watermarkremover_ai/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 441, in from_pretrained
    config, kwargs = AutoConfig.from_pretrained(
  File "XYZ/src/WatermarkRemover-AI/venv_watermarkremover_ai/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py", line 915, in from_pretrained
    return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
  File "XYZ/src/WatermarkRemover-AI/venv_watermarkremover_ai/lib/python3.10/site-packages/transformers/configuration_utils.py", line 553, in from_pretrained
    return cls.from_dict(config_dict, **kwargs)
  File "XYZ/src/WatermarkRemover-AI/venv_watermarkremover_ai/lib/python3.10/site-packages/transformers/configuration_utils.py", line 720, in from_dict
    logger.info(f"Model config {config}")
  File "XYZ/src/WatermarkRemover-AI/venv_watermarkremover_ai/lib/python3.10/site-packages/transformers/configuration_utils.py", line 752, in __repr__
    return f"{self.__class__.__name__} {self.to_json_string()}"
  File "XYZ/src/WatermarkRemover-AI/venv_watermarkremover_ai/lib/python3.10/site-packages/transformers/configuration_utils.py", line 824, in to_json_string
    return json.dumps(config_dict, indent=2, sort_keys=True) + "\n"
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.10/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.10/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Florence2LanguageConfig is not JSON serializable
wetoo-cando commented 1 month ago

Apparently caused because I downgraded transformers

https://huggingface.co/microsoft/Florence-2-large/discussions/28

However, when I use the original requirements.txt from this repo, I now have: The user requested transformers>=4.44.0 lama-cleaner 1.2.5 depends on transformers==4.27.4

wetoo-cando commented 1 month ago

The requirements.txt as given by this repo did not work for me directly.

Had to comment out the transformers line in requirements.txt and let lama-cleaner install whatever transformers it needed. Then updated transformers to 4.44.1 on top, and now it works.

D-Ogi commented 1 week ago

@wetoo-cando Thanks for pointing that out! I agree that the requirements.txt file can be improved to avoid these compatibility issues. I’ll work on refining to correct handling the dependency versions. In the meantime, your solution of commenting out the transformers line and upgrading manually should help others who encounter the same problem.