Downloads · 30 days
4
6% of all-time downloads
arkrajkundu/knitGPT_v1.0
knitGPT_v1.0 is a machine learning model from arkrajkundu. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft.
Inputs an image (of a sweater or something that you wanna knit), and provides instructions on how to do the knitting/crochery.
Downloads · 30 days
4
6% of all-time downloads
All-time downloads
63
Public
Repo size
47.6 MB
Likes
3
Public
Click a slice to open those files.
.safetensors47.6 MB · 100%
From the Hugging Face model README
Inputs an image (of a sweater or something that you wanna knit), and provides instructions on how to do the knitting/crochery.
This model takes an image input — typically of a sweater, garment, or knitted/crocheted item — and generates step-by-step knitting or crochet instructions to help recreate the item. It is designed to assist knitting enthusiasts, hobbyists, and designers by translating visual patterns into written guidance, making it easier to reproduce complex or visually striking designs. The model leverages the google/paligemma2-3b-pt-224 architecture, fine-tuned on the arkrajkundu/knitting_patterns dataset, and integrates with the PEFT (Parameter-Efficient Fine-Tuning) library to deliver efficient and accessible knitting pattern generation.
To get started with the KnitGPT model, follow these steps to perform inference:
Install Required Libraries Before using the model, make sure to install the necessary libraries. You can do so by running: [pip install torch transformers peft Pillow]
import json
import torch
from PIL import Image
from transformers import PaliGemmaProcessor, PaliGemmaForConditionalGeneration
from peft import PeftModel
base_model_id = "google/paligemma2-3b-pt-224"
adapter_repo_id = "arkrajkundu/knitGPT_v1.0"
image_resize = (128, 128)
max_new_tokens = 256
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
processor = PaliGemmaProcessor.from_pretrained(base_model_id)
model = PaliGemmaForConditionalGeneration.from_pretrained(base_model_id)
model = PeftModel.from_pretrained(model, adapter_repo_id)
model.to(device)
model.eval()
image_path = "/"
try:
image = Image.open(image_path).convert("RGB").resize(image_resize)
except Exception as e:
print(f"Failed to load image {image_path}: {e}")
exit()
prompt = "How to knit this pattern?"
inputs = processor(
text=prompt,
images=image,
return_tensors="pt"
)
for k, v in inputs.items():
inputs[k] = v.to(device)
with torch.no_grad():
generated_ids = model.generate(**inputs, max_new_tokens=max_new_tokens)
output = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print("\nInference complete!")
print(f"Model Output: {output}")
Training Data The training data for the KnitGPT model comes from the arkrajkundu/knitting_patterns dataset. This dataset includes a variety of knitting patterns that have been used to fine-tune the model, enabling it to understand visual patterns and generate corresponding textual knitting instructions.
Dataset Source: [https://huggingface.co/datasets/arkrajkundu/knitting_patterns]
[The data was preprocessed by converting knitting images and their corresponding instructions into a format suitable for the model. Each input image was resized and normalized to facilitate consistent model performance.]