lombardata
commited on
Commit
•
eb85cd6
1
Parent(s):
ce4d57a
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
3 |
-
# teo
|
4 |
import torch
|
5 |
from transformers import Dinov2Config, Dinov2Model, Dinov2ForImageClassification, AutoImageProcessor
|
6 |
import torch.nn as nn
|
@@ -27,6 +26,7 @@ class NewheadDinov2ForImageClassification(Dinov2ForImageClassification):
|
|
27 |
|
28 |
# Classifier head
|
29 |
self.classifier = create_head(config.hidden_size * 2, config.num_labels)
|
|
|
30 |
# IMPORT CLASSIFICATION MODEL
|
31 |
checkpoint_name = "lombardata/dino-base-2023_11_27-with_custom_head"
|
32 |
# import labels
|
@@ -63,12 +63,20 @@ def predict(input_image):
|
|
63 |
i += 1
|
64 |
result = {key: result[key] for key in result if result[key] > 0.5}
|
65 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
gr.Interface(
|
68 |
fn=predict,
|
69 |
inputs=gr.Image(shape=(224, 224)),
|
70 |
#outputs=gr.Label(num_top_classes=5),
|
71 |
-
outputs="label"
|
|
|
|
|
72 |
|
73 |
|
74 |
#examples=["GOPR0106.JPG",
|
|
|
1 |
import numpy as np
|
2 |
import gradio as gr
|
|
|
3 |
import torch
|
4 |
from transformers import Dinov2Config, Dinov2Model, Dinov2ForImageClassification, AutoImageProcessor
|
5 |
import torch.nn as nn
|
|
|
26 |
|
27 |
# Classifier head
|
28 |
self.classifier = create_head(config.hidden_size * 2, config.num_labels)
|
29 |
+
|
30 |
# IMPORT CLASSIFICATION MODEL
|
31 |
checkpoint_name = "lombardata/dino-base-2023_11_27-with_custom_head"
|
32 |
# import labels
|
|
|
63 |
i += 1
|
64 |
result = {key: result[key] for key in result if result[key] > 0.5}
|
65 |
return result
|
66 |
+
|
67 |
+
# Define style
|
68 |
+
title = "DinoVd'eau image classification"
|
69 |
+
description = f"This is a prototype application that demonstrates how artificial intelligence-based systems can recognize what object(s)
|
70 |
+
is present in an underwater image. To use it, simply upload your image, or click one of the example images to load them. For predictions,
|
71 |
+
we use the open-source model {checkpoint_name}"
|
72 |
|
73 |
gr.Interface(
|
74 |
fn=predict,
|
75 |
inputs=gr.Image(shape=(224, 224)),
|
76 |
#outputs=gr.Label(num_top_classes=5),
|
77 |
+
outputs="label",
|
78 |
+
title=title,
|
79 |
+
description=description).launch()
|
80 |
|
81 |
|
82 |
#examples=["GOPR0106.JPG",
|