Problem: Missing dependencies when trying to run Moderators.
Solution:
- Install the package:
pip install moderators - Let auto-install run (ensure
MODERATORS_DISABLE_AUTO_INSTALLis unset) - For manual control:
pip install "moderators[transformers]"
Problem: Model configuration or files not found.
Solution:
- Check your model ID or local folder path
- Ensure
config.jsonis present in the model directory - For Hugging Face models, verify the model ID is correct
- Try downloading the model first to verify it exists:
from transformers import AutoConfig AutoConfig.from_pretrained("your-model-id")
Problem: Network errors or authentication failures when downloading models.
Solution:
- Verify internet connectivity
- For private models, ensure you're authenticated:
huggingface-cli login
- Use offline mode if the model is already cached:
moderators model-id input.jpg --local-files-only
Problem: Model running on CPU despite having a GPU available.
Solution:
- Ensure your framework is installed with CUDA support
- For PyTorch, reinstall with CUDA:
pip install torch --index-url https://download.pytorch.org/whl/cu118
- Verify CUDA availability:
import torch print(torch.cuda.is_available())
Problem: Inference taking longer than expected.
Suggestions:
- Use GPU acceleration (see "GPU not used" above)
- Try smaller models (e.g.,
nsfw-detection-2-nanoinstead of larger variants) - Consider batch processing for multiple inputs
- Check if auto-installation is downloading dependencies (first run only)
Problem: Results don't match expected format.
Solution:
- Check the API documentation for the correct output schema
- Use
asdict()to convert Python results to dictionaries:from dataclasses import asdict json_ready = [asdict(r) for r in result]
- Verify you're using the correct input type (image path vs text string)
If you're still experiencing issues:
- Check the GitHub Issues
- Review the examples in the
examples/folder - Open a new issue with details about your environment and error messages