ImportError: cannot import name 'SafetyChecker' from 'transformers'

#44
by Wok - opened
from transformers import SafetyChecker

model = SafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
ImportError                               Traceback (most recent call last)

<ipython-input-20-02ea5e6a81ae> in <cell line: 1>()
----> 1 from transformers import SafetyChecker
      2 
      3 model = SafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")

ImportError: cannot import name 'SafetyChecker' from 'transformers' (/usr/local/lib/python3.10/dist-packages/transformers/__init__.py)

Fixed with the following piece of code, as suggested at GitHub.

!pip install --upgrade diffusers
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker

model = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
osanseviero changed discussion status to closed

Sign up or log in to comment