Run this model with HF Jobs
Run Hammad712/GAN-Colorization-Model on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Hammad712/GAN-Colorization-Model. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Hammad712/GAN-Colorization-Model on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Hammad712/GAN-Colorization-Model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- fastai
How to use Hammad712/GAN-Colorization-Model with fastai:
from huggingface_hub import from_pretrained_fastai learn = from_pretrained_fastai("Hammad712/GAN-Colorization-Model") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files5 unmodified lines6789101112131415161718192021222324252627282930313233343536373839404142434445464748495051521 unmodified line54555657585 unmodified lineslibrary_name: fastaipipeline_tag: image-to-image---Model Card: GAN Colorization ModelModel DescriptionThis GAN-based model performs image colorization, transforming grayscale images into color images. It leverages a generator network to predict the color channels and a discriminator network to improve the colorization quality through adversarial training.Model DetailsModel Name: GAN Colorization ModelModel Architecture: The model uses a ResNet-34 backbone as the encoder in the generator network and a PatchGAN discriminator network.Framework: PyTorchRepository: Hammad712/GAN-Colorization-ModelModel TrainingDatasetDataset Used: COCO 2017Training Size: 8000 imagesValidation Size: 2000 imagesImage Size: 256x256 pixelsTraining ConfigurationBatch Size: 16Number of Epochs: 5Optimizer for Generator: Adam (learning rate: 0.0004, betas: 0.5, 0.999)Optimizer for Discriminator: Adam (learning rate: 0.0004, betas: 0.5, 0.999)Loss Functions:GAN Loss: Binary Cross-Entropy Loss with LogitsL1 Loss: L1 Loss for pixel-wise comparison between generated and real color channelsUsageTo use the model for image colorization, ensure that the dependencies are installed and run the inference code provided. You will need to replace the image path with your own image for colorization.Model PerformanceQualitative ResultsThe model generates visually plausible colorizations for grayscale images. Here are some examples of colorized outputs:LimitationsThe model may not always produce accurate colors for objects with complex or unusual color distributions.Performance may degrade for images that significantly differ from the training dataset.CitationIf you use this model in your research, please cite the original repository:bibtexCopy code@misc{Hammad7122023GANColorization,title={GAN-Colorization-Model},author={Hammad712},1 unmodified linepublisher={Hugging Face},howpublished={\url{https://huggingface.co/Hammad712/GAN-Colorization-Model}},}ContactFor any issues or inquiries, please reach out to the model author through the Hugging Face repository.5 unmodified lines67891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151 unmodified line1171181191201215 unmodified lineslibrary_name: fastaipipeline_tag: image-to-image---# Model DescriptionThis GAN-based model performs image colorization, transforming grayscale images into color images. It leverages a generator network to predict the color channels and a discriminator network to improve the colorization quality through adversarial training.# Model DetailsModel Name: GAN Colorization ModelModel Architecture: The model uses a ResNet-34 backbone as the encoder in the generator network and a PatchGAN discriminator network.Framework: PyTorchRepository: Hammad712/GAN-Colorization-Model# Model Training## DatasetDataset Used: COCO 2017Training Size: 8000 imagesValidation Size: 2000 imagesImage Size: 256x256 pixels## Training ConfigurationBatch Size: 16Number of Epochs: 5Optimizer for Generator: Adam (learning rate: 0.0004, betas: 0.5, 0.999)Optimizer for Discriminator: Adam (learning rate: 0.0004, betas: 0.5, 0.999)## Loss Functions:GAN Loss: Binary Cross-Entropy Loss with LogitsL1 Loss: L1 Loss for pixel-wise comparison between generated and real color channels# Inference Codefrom huggingface_hub import hf_hub_downloadimport torchfrom PIL import Imagefrom torchvision import transformsfrom skimage.color import rgb2lab, lab2rgbimport numpy as npimport matplotlib.pyplot as plt#Download the model from Hugging Face Hubrepo_id = "Hammad712/GAN-Colorization-Model"model_filename = "generator.pt"model_path = hf_hub_download(repo_id=repo_id, filename=model_filename)#Define the generator model (same architecture as used during training)from fastai.vision.learner import create_bodyfrom torchvision.models import resnet34from fastai.vision.models.unet import DynamicUnetdef build_generator(n_input=1, n_output=2, size=256):device = torch.device("cuda" if torch.cuda.is_available() else "cpu")backbone = create_body(resnet34(), pretrained=True, n_in=n_input, cut=-2)G_net = DynamicUnet(backbone, n_output, (size, size)).to(device)return G_net#Initialize and load the modeldevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")G_net = build_generator(n_input=1, n_output=2, size=256)G_net.load_state_dict(torch.load(model_path, map_location=device))G_net.eval()#Preprocessing functiondef preprocess_image(img_path):img = Image.open(img_path).convert("RGB")img = transforms.Resize((256, 256), Image.BICUBIC)(img)img = np.array(img)img_to_lab = rgb2lab(img).astype("float32")img_to_lab = transforms.ToTensor()(img_to_lab)L = img_to_lab[[0], ...] / 50. - 1.return L.unsqueeze(0).to(device)#Inference functiondef colorize_image(img_path, model):L = preprocess_image(img_path)with torch.no_grad():ab = model(L)L = (L + 1.) * 50.ab = ab * 110.Lab = torch.cat([L, ab], dim=1).permute(0, 2, 3, 1).cpu().numpy()rgb_imgs = []for img in Lab:img_rgb = lab2rgb(img)rgb_imgs.append(img_rgb)return np.stack(rgb_imgs, axis=0)#Example image pathimg_path = "/path/to/your/image.jpg" # Replace with your image path#Perform inferencecolorized_images = colorize_image(img_path, G_net)#Display the resultplt.imshow(colorized_images[0])plt.axis("off")plt.show()# UsageTo use the model for image colorization, ensure that the dependencies are installed and run the inference code provided. You will need to replace the image path with your own image for colorization.# Model PerformanceQualitative ResultsThe model generates visually plausible colorizations for grayscale images. Here are some examples of colorized outputs:# LimitationsThe model may not always produce accurate colors for objects with complex or unusual color distributions.Performance may degrade for images that significantly differ from the training dataset.CitationIf you use this model in your research, please cite the original repository:# bibtex@misc{Hammad7122023GANColorization,title={GAN-Colorization-Model},author={Hammad712},1 unmodified linepublisher={Hugging Face},howpublished={\url{https://huggingface.co/Hammad712/GAN-Colorization-Model}},}# ContactFor any issues or inquiries, please reach out to the model author through the Hugging Face repository.
README.md+78-15