ArtifyAI v1.0: Text-to-Image Generation
ArtifyAI v1.0 is a project designed to generate images from text using the T5 model for text summarization and the Stable Diffusion model for image generation. This version also provides functionality to save model weights and load them for future use, making it easier to resume your work.
Overview
ArtifyAI v1.0 uses T5 for text processing, Stable Diffusion for image generation, and includes functionality for saving and loading the model's weights. You can easily store model weights in Google Drive and use them later without re-downloading everything.
Features
- Text Processing: Utilizes T5 for text summarization and generation.
- Image Generation: Uses Stable Diffusion for high-quality image generation based on textual descriptions.
- Model Saving: Allows you to save and reload model weights (e.g., UNet) to/from Google Drive.
Installation
Prerequisites
Ensure that you have the following to run this project:
- Python 3.7+
- CUDA-compatible GPU (for faster performance)
- Hugging Face Transformers
- Diffusers
- PyTorch with CUDA support
Step-by-Step Setup
Clone the Repository:
git clone https://github.com/your-username/ArtifyAI.git cd ArtifyAI
Install Dependencies:
pip install torch transformers diffusers
Download the Pretrained Models: Use the following code to load the models:
from transformers import T5Tokenizer, T5ForConditionalGeneration from diffusers import StableDiffusionPipeline import torch # Load models t5_tokenizer = T5Tokenizer.from_pretrained("t5-small") t5_model = T5ForConditionalGeneration.from_pretrained("t5-small") ArtifyAI_model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16) # Set model to GPU if available ArtifyAI_model = ArtifyAI_model.to("cuda" if torch.cuda.is_available() else "cpu")
Mount Google Drive for Model Saving: To save model weights in Google Drive, mount your drive and specify the save path:
from google.colab import drive drive.mount('/content/drive') save_path = '/content/drive/My Drive/models/unet_weights.pth' torch.save(ArtifyAI_model.unet.state_dict(), save_path)
Load Model Weights: Reload the model's weights later using:
ArtifyAI_model.unet.load_state_dict(torch.load('/content/drive/My Drive/models/unet_weights.pth'))
Usage
- Run the Jupyter Notebook: Open
ArtifyAI_v1_0.ipynb
in Jupyter to run the code and explore the pipeline. - Save/Load Model Weights: Use the provided code to store and retrieve model weights from Google Drive.
- Generate Custom Images: Modify the text input to generate unique images.
Example
Here's how you can save and reload model weights:
# Save the UNet model's weights
torch.save(ArtifyAI_model.unet.state_dict(), '/content/drive/My Drive/models/unet_weights.pth')
# Load the saved weights
ArtifyAI_model.unet.load_state_dict(torch.load('/content/drive/My Drive/models/unet_weights.pth'))
## For Non-Technical Users
If you're not familiar with coding or AI, follow these steps to use ArtifyAI:
1. **Install Python**: Download and install Python 3.7+ from the [official Python website](https://www.python.org/downloads/).
2. **Install Dependencies**: After installing Python, open a terminal and run:
```bash
pip install torch transformers diffusers
```
3. **Run the Project**: Use the code snippets provided in the notebook or above to generate images from text.
4. **Save Your Work**: If you are using Google Colab, remember to save your models to Google Drive to keep your work.