Instructions to use KristofGaming39/Zer0Shot-image-RobloxCharacters with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use KristofGaming39/Zer0Shot-image-RobloxCharacters with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://KristofGaming39/Zer0Shot-image-RobloxCharacters") - Notebooks
- Google Colab
- Kaggle
File size: 905 Bytes
eebb924 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import torch
import torchvision
from torchvision.transforms import transforms
from PIL import Image
model = torchvision.models.resnet50(pretrained=False)
model.fc = torch.nn.Linear(in_features=2048, out_features=1)
model.load_state_dict(torch.load('/content/zero_shot_classification_model.pth'))
model.eval()
test_transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
test_image_path = '/content/test_img.png' # Replace with your own test image path!
test_image = Image.open(test_image_path).convert('RGB')
test_image = test_transform(test_image)
test_image = test_image.unsqueeze(0)
with torch.no_grad():
prediction = model(test_image)
probability = torch.sigmoid(prediction).item()
print(f"The probability of the image being a Roblox character is: {probability*100}%") |