Spaces:
Running
Running
Tharan-J
commited on
Commit
·
40ada70
1
Parent(s):
a1acb28
Add finetuned model and app
Browse files- convnext_base_finetuned.pth +3 -0
- model.py +29 -0
- requirements.txt +3 -0
convnext_base_finetuned.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c8dadf0c017fd3749a0dc291a1d9249bdba618c6351964d1fe65a85c07a578b
|
3 |
+
size 350500802
|
model.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import ConvNextForImageClassification, AutoImageProcessor
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Load model configuration and weights manually
|
7 |
+
model = ConvNextForImageClassification.from_pretrained("facebook/convnext-base-224") # Load the base model
|
8 |
+
model.load_state_dict(torch.load("convnext_base_finetuned.pth", map_location="cpu")) # Load your finetuned weights
|
9 |
+
model.eval()
|
10 |
+
|
11 |
+
# Load the processor
|
12 |
+
processor = AutoImageProcessor.from_pretrained("facebook/convnext-base-224")
|
13 |
+
|
14 |
+
# Define a function to predict the class from an image
|
15 |
+
def predict(image):
|
16 |
+
# Preprocess the image
|
17 |
+
inputs = processor(images=image, return_tensors="pt")
|
18 |
+
|
19 |
+
# Perform inference
|
20 |
+
with torch.no_grad():
|
21 |
+
outputs = model(**inputs)
|
22 |
+
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
23 |
+
|
24 |
+
return predicted_class
|
25 |
+
|
26 |
+
# Create Gradio interface for user input
|
27 |
+
iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Textbox())
|
28 |
+
|
29 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch==1.13.1
|
2 |
+
transformers==4.27.0
|
3 |
+
gradio==3.0.1
|