Commit
·
df14637
1
Parent(s):
235075d
Add guide for finding FastAI-compatible colorization models - Document how to find models with .pkl files - Add instructions for setting MODEL_ID - Note current model limitation
Browse files- FASTAI_MODEL_GUIDE.md +74 -0
- app/config.py +3 -0
FASTAI_MODEL_GUIDE.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FastAI-Compatible Colorization Models Guide
|
| 2 |
+
|
| 3 |
+
## Current Issue
|
| 4 |
+
|
| 5 |
+
The model `Hammad712/GAN-Colorization-Model` contains a PyTorch model (`generator.pt`), not a FastAI model. FastAI models must be `.pkl` files created with FastAI's `export()` function.
|
| 6 |
+
|
| 7 |
+
## How to Find FastAI-Compatible Models
|
| 8 |
+
|
| 9 |
+
### Option 1: Search Hugging Face
|
| 10 |
+
|
| 11 |
+
1. Go to https://huggingface.co/models
|
| 12 |
+
2. Search for: `fastai colorization` or `fastai image colorization`
|
| 13 |
+
3. Look for models that have `.pkl` files in their repository
|
| 14 |
+
4. Check the model's README to confirm it's a FastAI Learner
|
| 15 |
+
|
| 16 |
+
### Option 2: Use FastAI's Official Examples
|
| 17 |
+
|
| 18 |
+
FastAI course examples often have colorization models. Look for:
|
| 19 |
+
- FastAI course lesson notebooks on image colorization
|
| 20 |
+
- Models exported using `learn.export('model.pkl')`
|
| 21 |
+
|
| 22 |
+
### Option 3: Train Your Own
|
| 23 |
+
|
| 24 |
+
If you have a FastAI colorization model:
|
| 25 |
+
```python
|
| 26 |
+
from fastai.vision.all import *
|
| 27 |
+
learn = ... # your trained model
|
| 28 |
+
learn.export('model.pkl')
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
Then upload `model.pkl` to Hugging Face.
|
| 32 |
+
|
| 33 |
+
## Setting a New Model
|
| 34 |
+
|
| 35 |
+
### Via Environment Variable (Recommended)
|
| 36 |
+
|
| 37 |
+
In your Hugging Face Space settings, add:
|
| 38 |
+
```
|
| 39 |
+
MODEL_ID=your-username/your-fastai-colorization-model
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### Via Code
|
| 43 |
+
|
| 44 |
+
Update `app/config.py`:
|
| 45 |
+
```python
|
| 46 |
+
MODEL_ID: str = os.getenv("MODEL_ID", "your-username/your-fastai-colorization-model")
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## Model Requirements
|
| 50 |
+
|
| 51 |
+
The model must:
|
| 52 |
+
1. ✅ Be a FastAI Learner exported as `.pkl` file
|
| 53 |
+
2. ✅ Accept PIL Images as input
|
| 54 |
+
3. ✅ Return colorized images (PIL Image or tensor)
|
| 55 |
+
4. ✅ Be uploaded to Hugging Face Hub
|
| 56 |
+
|
| 57 |
+
## Testing a Model
|
| 58 |
+
|
| 59 |
+
Before switching, you can test locally:
|
| 60 |
+
```python
|
| 61 |
+
from huggingface_hub import from_pretrained_fastai
|
| 62 |
+
from PIL import Image
|
| 63 |
+
|
| 64 |
+
learn = from_pretrained_fastai("your-model-id")
|
| 65 |
+
img = Image.open("test.jpg")
|
| 66 |
+
result = learn.predict(img)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
If this works, the model is compatible!
|
| 70 |
+
|
| 71 |
+
## Alternative: Switch Back to SDXL+ControlNet
|
| 72 |
+
|
| 73 |
+
If you can't find a FastAI model, you can switch back to the SDXL+ControlNet approach which was working before. Update `MODEL_BACKEND` to `"diffusers"` and use a ControlNet colorization model.
|
| 74 |
+
|
app/config.py
CHANGED
|
@@ -18,6 +18,9 @@ class Settings(BaseSettings):
|
|
| 18 |
BASE_URL: str = os.getenv("BASE_URL", "http://localhost:8000")
|
| 19 |
|
| 20 |
# Model / inference settings
|
|
|
|
|
|
|
|
|
|
| 21 |
MODEL_ID: str = os.getenv("MODEL_ID", "Hammad712/GAN-Colorization-Model")
|
| 22 |
MODEL_BACKEND: str = os.getenv("MODEL_BACKEND", "fastai")
|
| 23 |
BASE_MODEL_ID: str = os.getenv("BASE_MODEL_ID", "stabilityai/stable-diffusion-xl-base-1.0")
|
|
|
|
| 18 |
BASE_URL: str = os.getenv("BASE_URL", "http://localhost:8000")
|
| 19 |
|
| 20 |
# Model / inference settings
|
| 21 |
+
# Note: MODEL_ID must point to a FastAI model (.pkl file), not PyTorch (.pt file)
|
| 22 |
+
# To find FastAI-compatible colorization models, search Hugging Face for models with .pkl files
|
| 23 |
+
# Example: Look for models tagged with "fastai" and "colorization"
|
| 24 |
MODEL_ID: str = os.getenv("MODEL_ID", "Hammad712/GAN-Colorization-Model")
|
| 25 |
MODEL_BACKEND: str = os.getenv("MODEL_BACKEND", "fastai")
|
| 26 |
BASE_MODEL_ID: str = os.getenv("BASE_MODEL_ID", "stabilityai/stable-diffusion-xl-base-1.0")
|