Run this model with HF Jobs

Run DJStomp/TestingSalvoNET 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/DJStomp/TestingSalvoNET. 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/DJStomp/TestingSalvoNET 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.
TestingSalvoNET / pipeline.py
DJStomp's picture
Create pipeline.py
6513aae
Raw History Blame Contribute Delete
1.25 kB
import torch
import nltk
import io
import base64
from torchvision import transforms
from pytorch_pretrained_biggan import BigGAN, one_hot_from_names, truncated_noise_sample
class PreTrainedPipeline():
def __init__(self, path=""):
"""
Initialize model
"""
nltk.download('wordnet')
self.model = BigGAN.from_pretrained(path)
self.truncation = 0.1
def __call__(self, inputs: str):
"""
Args:
inputs (:obj:`str`):
a string containing some text
Return:
A :obj:`PIL.Image` with the raw image representation as PIL.
"""
class_vector = one_hot_from_names([inputs], batch_size=1)
if type(class_vector) == type(None):
raise ValueError("Input is not in ImageNet")
noise_vector = truncated_noise_sample(truncation=self.truncation, batch_size=1)
noise_vector = torch.from_numpy(noise_vector)
class_vector = torch.from_numpy(class_vector)
with torch.no_grad():
output = self.model(noise_vector, class_vector, self.truncation)
# Scale image
img = output[0]
img = (img + 1) / 2.0
img = transforms.ToPILImage()(img)
return img