Search
Close this search box.

Generate AI image locally on MacBook M1 Pro in 5 minutes

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 <<EOF >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

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow me on LinkedIn
Share the Post:

Enjoy Free Useful Amazing Content

Related Posts