Run this model with HF Jobs
Run litert-community/resnet18 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/litert-community/resnet18. 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/litert-community/resnet18 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 litert-community/resnet18 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/resnet18 with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Upload GPU-compatible LiteRT artifacts
Browse filesFiles changed (3)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142---library_name: litertpipeline_tag: image-classificationtags:- vision- image-classification- computer-visiondatasets:- imagenet-1kmodel-index:- name: litert-community/resnet18results:- task:type: image-classificationname: Image Classificationdataset:name: ImageNet-1ktype: imagenet-1kconfig: defaultsplit: validationmetrics:- name: Top 1 Accuracy (Full Precision)type: accuracyvalue: 0.6977- name: Top 5 Accuracy (Full Precision)type: accuracyvalue: 0.8913- name: Top 1 Accuracy (Dynamic Quantized wi8 afp32)type: accuracyvalue: 0.6967- name: Top 5 Accuracy (Dynamic Quantized wi8 afp32)type: accuracyvalue: 0.8901---# ResNet 18The ResNet-18 architecture is a convolutional neural network pre-trained on the ImageNet-1k dataset. Originally introduced by He et al. in the landmark paper, [**Deep Residual Learning for Image Recognition**](https://arxiv.org/pdf/1512.03385), this model utilizes residual mapping to overcome the vanishing gradient problem, enabling the training of substantially deeper networks.## Model descriptionThe model was converted from a checkpoint from PyTorch Vision.The original model has:acc@1 (on ImageNet-1K): 69.758%acc@5 (on ImageNet-1K): 89.078%num_params: 11,689,512## Intended uses & limitationsThe model files were converted from pretrained weights from PyTorch Vision. The models may have their own licenses or terms and conditions derived from PyTorch Vision and the dataset used for training. It is your responsibility to determine whether you have permission to use the models for your use case.## How to Use**1. Install Dependencies** Ensure your Python environment is set up with the required libraries. Run the following command in your terminal:```bashpip install numpy Pillow huggingface_hub ai-edge-litert```**2. Prepare Your Image** The script expects an image file to analyze. Make sure you have an image (e.g., cat.jpg or car.png) saved in the same working directory as your script.**3. Save the Script** Create a new file named `classify.py`, paste the script below into it, and save the file:```python#!/usr/bin/env python3import argparse, jsonimport numpy as npfrom PIL import Imagefrom huggingface_hub import hf_hub_downloadfrom ai_edge_litert.compiled_model import CompiledModeldef preprocess(img: Image.Image) -> np.ndarray:img = img.convert("RGB")w, h = img.sizes = 256if w < h:img = img.resize((s, int(round(h * s / w))), Image.BILINEAR)else:img = img.resize((int(round(w * s / h)), s), Image.BILINEAR)left = (img.size[0] - 224) // 2top = (img.size[1] - 224) // 2img = img.crop((left, top, left + 224, top + 224))x = np.asarray(img, dtype=np.float32) / 255.0x = (x - np.array([0.485, 0.456, 0.406], dtype=np.float32)) / np.array([0.229, 0.224, 0.225], dtype=np.float32)return np.transpose(x, (2, 0, 1))def main():ap = argparse.ArgumentParser()ap.add_argument("--image", required=True)args = ap.parse_args()model_path = hf_hub_download("litert-community/resnet18", "resnet18.tflite")labels_path = hf_hub_download("huggingface/label-files", "imagenet-1k-id2label.json", repo_type="dataset")with open(labels_path, "r", encoding="utf-8") as f:id2label = {int(k): v for k, v in json.load(f).items()}img = Image.open(args.image)x = preprocess(img)model = CompiledModel.from_file(model_path)inp = model.create_input_buffers(0)out = model.create_output_buffers(0)inp[0].write(x)model.run_by_index(0, inp, out)req = model.get_output_buffer_requirements(0, 0)y = out[0].read(req["buffer_size"] // np.dtype(np.float32).itemsize, np.float32)pred = int(np.argmax(y))label = id2label.get(pred, f"class_{pred}")print(f"Top-1 class index: {pred}")print(f"Top-1 label: {label}")if __name__ == "__main__":main()```**4. Execute the Python Script** Run the below command:```bashpython classify.py --image cat.jpg```### BibTeX entry and citation info```bibtex@inproceedings{he2016deep,title={Deep residual learning for image recognition},author={He, Kaiming and Zhang, Xiangyu and Ren, Shaoqing and Sun, Jian},booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition}, pages={770--778},year={2016}}```1234567891011121314151617181920212223---library_name: literttags:- litert- tflite- vision- image-classificationdatasets:- imagenet-1k---# resnet18LiteRT TFLite conversion of the TorchVision `resnet18` model.## Files- `resnet18.tflite`- `resnet18_dynamic_wi8_afp32.tflite`## NotesThese artifacts were compiled with the LiteRT GPU compatibility profile and validated with LiteRT Python GPU execution.
123version https://git-lfs.github.com/spec/v1oid sha256:cf6a25c8ddaa1ce3457bdbd8a9fd3e1a327b334990efdaa8620ec97839e4163dsize 46776012123version https://git-lfs.github.com/spec/v1oid sha256:068bd4bd67a18c0dcc55f91b73fb035317c26cccf94328528d6dd1788bc4a0f6size 46750944
123version https://git-lfs.github.com/spec/v1oid sha256:9c3c5127eb486028d374b09b33c946bb36d3aff597e36f6df54e95b301ea0d34size 11809384123version https://git-lfs.github.com/spec/v1oid sha256:a4c5ef4b7fc01e24508bd59ad32084a616dbe9a16b4c910c81a16808ac7b0b29size 11784928
README.md+9-128
resnet18.tflite+2-2
resnet18_dynamic_wi8_afp32.tflite+2-2