Table of Contents
1. Introduction
In era of growing, like mushrooms in warm rainy day, subscription based online platforms that offers you image generation for little fee I decided to make quick round for making simple image without involving any expensive hardware. Just MacBook and internet connection. Let’s start.
2. Package installation
2.1. Install anaconda
To make it simple I used anaconda package manager. Below commands to install required dependencies.
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
sh Miniconda3-latest-MacOSX-arm64.sh
I accepted default settings, entering everything.
2.2. Install pyTorch and tranformers
conda install pytorch::pytorch torchvision torchaudio -c pytorch
conda install -c conda-forge diffusers
conda install -c huggingface transformers
3. Run script and get image
I decided to cherry pick ‘stable-diffusion-v1-5′ model. Then quick script that use prompt “sheep with big teeth in open jaws looking with big eyes“
cat <test.py
from diffusers import DiffusionPipeline
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("mps")
# uncomment below for mac with with less than 64 GB of RAM
#pipe.enable_attention_slicing()
prompt = "sheep with big teeth in open jaws looking with big eyes"
image = pipe(prompt).images[0]
image.save("test.png")
EOF
Now run script to get image:
conda run python test.py
4. Display image
Use any image browser to display image. Here is my result