Instructions to use hadilq/dragon-notdragon with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use hadilq/dragon-notdragon 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://hadilq/dragon-notdragon") - Notebooks
- Google Colab
- Kaggle
Download pipeline.py from hadilq/dragon-notdragon: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/hadilq/dragon-notdragon/resolve/main/pipeline.py
- Command line
-
hf download hf://hadilq/dragon-notdragon/pipeline.py
-
curl -L -o pipeline.py https://huggingface.co/hadilq/dragon-notdragon/resolve/main/pipeline.py
1.3 kB
| from typing import Dict | |
| from PIL import Image | |
| import numpy as np | |
| import os | |
| import json | |
| import tensorflow as tf | |
| from tensorflow import keras | |
| class PreTrainedPipeline(): | |
| def __init__(self, path=""): | |
| self.model = keras.saving.load_model("./") | |
| with open(os.path.join(path, "config.json")) as config: | |
| config = json.load(config) | |
| self.id2label = config["id2label"] | |
| def __call__(self, inputs: "Image.Image")-> Dict[str, str]: | |
| """ | |
| Args: | |
| inputs (:obj:`PIL.Image`): | |
| The raw image representation as PIL. | |
| No transformation made whatsoever from the input. Make all necessary transformations here. | |
| Return: | |
| A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82} | |
| It is preferred if the returned list is in decreasing `score` order | |
| """ | |
| img = keras.preprocessing.image.load_img(input, target_size=(224, 224)) | |
| x = keras.preprocessing.image.img_to_array(img) | |
| x = np.expand_dims(x, axis=0) | |
| x = keras.applications.vgg16.preprocess_input(x) | |
| prediction = self.model.predict(x) | |
| return { 'label': "detected", 'score': "dragon" if prediction[0][0] >= 0.99 else "not-dragon" } | |