This script generates images using Stable Diffusion 3.5 based on prompts from a CSV file. It's designed to help evaluate cultural representation in AI image generation.
You can run this script either on your local machine or on a remote server. Choose the appropriate guide below based on your setup.
If you have a GPU on your local machine, follow these steps:
-
Set up Conda Environment
# Create and activate environment conda create -n sd35 python=3.10 conda activate sd35 # Install dependencies from requirements.txt pip install -r requirements.txt # Or install packages manually if needed: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 pip install diffusers transformers safetensors pandas accelerate protobuf sentencepiece
-
Login to Hugging Face
pip install huggingface_hub huggingface-cli login
-
Access the model on Hugging Face
- Go to the https://huggingface.co/stabilityai/stable-diffusion-3.5-medium, accept the license to access the models.
-
Download Model
# Create directory and download mkdir -p ~/stable-diffusion-models/stable-diffusion-3.5-medium python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='stabilityai/stable-diffusion-3.5-medium', local_dir='~/stable-diffusion-models/stable-diffusion-3.5-medium')"
-
Prepare Script and Prompts
- Modify paths in
general_culture_SD3.py
- Create
prompts.csv
with your prompts
- Modify paths in
-
Generate Images
python general_culture_SD3.py
-
View Results
- Check the
output
directory (or your specified output directory) - Images will be saved as PNG files with names based on the prompts
- Check the
If you're running on a remote server, follow these steps:
-
Connect to Server
ssh username@server-address # Example: ssh [email protected]
-
Set up Environment on Server
# Activate conda environment conda activate sd35
-
Transfer Files to Server
# Upload script and prompts to server scp general_culture_SD3.py username@server-address:/path/to/destination/ scp prompts.csv username@server-address:/path/to/destination/ # Example: scp general_culture_SD3.py [email protected]:/home/chans/worldccub/
-
Run Script on Server
python general_culture_SD3.py
-
Download Generated Images
# Option 1: Download entire output directory scp -r username@server-address:/path/to/output ./local_output # Option 2: Zip and download # On server: zip -r output.zip output # Then download: scp username@server-address:/path/to/output.zip ~/Downloads/ # Example: scp [email protected]:/scratch/chans/sd-data/output.zip ~/Downloads/
Create a file named prompts.csv
with your desired prompts:
prompt
"Show me traditional Nigerian clothing Fullbody"
"Show me traditional Nigerian celebration"
"Show me traditional Nigerian food"
"Show me traditional Nigerian architecture"
"Show me traditional Nigerian art"
--model_path
: Path to Stable Diffusion model--prompts_csv
: Path to CSV file with prompts (default: "prompts.csv")--output_dir
: Directory to save generated images--steps
: Number of inference steps (default: 30)--guidance_scale
: Guidance scale for generation (default: 7.5)
- CUDA errors: If you have GPU memory issues, try reducing the
--steps
value - Model loading failure: Verify model path and Hugging Face login
- CSV file errors: Check that your CSV file has "prompt" header
- Server connection issues: Verify your SSH key and server address
- Permission denied: Check file permissions (use
chmod +x
if needed)