Spaces:
Sleeping
Sleeping
Add local image classifier model
Browse files- .ipynb_checkpoints/app-checkpoint.py +14 -0
- app.py +26 -0
- model/config.json +51 -0
- model/model.safetensors +3 -0
- model/preprocessor_config.json +22 -0
- model/training_args.bin +3 -0
- requirements.txt +4 -0
.ipynb_checkpoints/app-checkpoint.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
zero = torch.Tensor([0]).cuda()
|
| 6 |
+
print(zero.device) # <-- 'cpu' 🤔
|
| 7 |
+
|
| 8 |
+
@spaces.GPU
|
| 9 |
+
def greet(n):
|
| 10 |
+
print(zero.device) # <-- 'cuda:0' 🤗
|
| 11 |
+
return f"Hello {zero + n} Tensor"
|
| 12 |
+
|
| 13 |
+
demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
|
| 14 |
+
demo.launch()
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
classifier = pipeline(
|
| 6 |
+
task="image-classification",
|
| 7 |
+
model="model",
|
| 8 |
+
image_processor="model",
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def predict(image):
|
| 13 |
+
results = classifier(image, top_k=3)
|
| 14 |
+
return {item["label"]: item["score"] for item in results}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=predict,
|
| 19 |
+
inputs=gr.Image(type="pil", label="Upload image"),
|
| 20 |
+
outputs=gr.Label(num_top_classes=3, label="Prediction"),
|
| 21 |
+
title="Ball Sport Classifier",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|
model/config.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"ResNetForImageClassification"
|
| 4 |
+
],
|
| 5 |
+
"depths": [
|
| 6 |
+
3,
|
| 7 |
+
4,
|
| 8 |
+
6,
|
| 9 |
+
3
|
| 10 |
+
],
|
| 11 |
+
"downsample_in_bottleneck": false,
|
| 12 |
+
"downsample_in_first_stage": false,
|
| 13 |
+
"dtype": "float32",
|
| 14 |
+
"embedding_size": 64,
|
| 15 |
+
"hidden_act": "relu",
|
| 16 |
+
"hidden_sizes": [
|
| 17 |
+
256,
|
| 18 |
+
512,
|
| 19 |
+
1024,
|
| 20 |
+
2048
|
| 21 |
+
],
|
| 22 |
+
"id2label": {
|
| 23 |
+
"0": "badminton",
|
| 24 |
+
"1": "pickleball",
|
| 25 |
+
"2": "tennis"
|
| 26 |
+
},
|
| 27 |
+
"label2id": {
|
| 28 |
+
"badminton": 0,
|
| 29 |
+
"pickleball": 1,
|
| 30 |
+
"tennis": 2
|
| 31 |
+
},
|
| 32 |
+
"layer_type": "bottleneck",
|
| 33 |
+
"model_type": "resnet",
|
| 34 |
+
"num_channels": 3,
|
| 35 |
+
"out_features": [
|
| 36 |
+
"stage4"
|
| 37 |
+
],
|
| 38 |
+
"out_indices": [
|
| 39 |
+
4
|
| 40 |
+
],
|
| 41 |
+
"problem_type": "single_label_classification",
|
| 42 |
+
"stage_names": [
|
| 43 |
+
"stem",
|
| 44 |
+
"stage1",
|
| 45 |
+
"stage2",
|
| 46 |
+
"stage3",
|
| 47 |
+
"stage4"
|
| 48 |
+
],
|
| 49 |
+
"transformers_version": "5.13.0",
|
| 50 |
+
"use_cache": false
|
| 51 |
+
}
|
model/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1291f97f4bcc6a53ca253b102c61442290a56432e66b48ba7ff7d27f56422567
|
| 3 |
+
size 94311148
|
model/preprocessor_config.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"crop_pct": 0.875,
|
| 3 |
+
"do_normalize": true,
|
| 4 |
+
"do_rescale": true,
|
| 5 |
+
"do_resize": true,
|
| 6 |
+
"image_mean": [
|
| 7 |
+
0.485,
|
| 8 |
+
0.456,
|
| 9 |
+
0.406
|
| 10 |
+
],
|
| 11 |
+
"image_processor_type": "ConvNextImageProcessor",
|
| 12 |
+
"image_std": [
|
| 13 |
+
0.229,
|
| 14 |
+
0.224,
|
| 15 |
+
0.225
|
| 16 |
+
],
|
| 17 |
+
"resample": 3,
|
| 18 |
+
"rescale_factor": 0.00392156862745098,
|
| 19 |
+
"size": {
|
| 20 |
+
"shortest_edge": 224
|
| 21 |
+
}
|
| 22 |
+
}
|
model/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7440d81eff1081b6992c725d3d12fb81c83e834772e0b32b775e2a4745c22af2
|
| 3 |
+
size 5137
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
torch
|
| 3 |
+
transformers
|
| 4 |
+
safetensors
|