Spaces:
Runtime error
Runtime error
Johannes Kolbe
commited on
Commit
Β·
6c8e36c
1
Parent(s):
4a63c6e
add code for space
Browse files- README.md +3 -3
- app.py +39 -0
- examples/cat.jpg +0 -0
- examples/ship.jpeg +0 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Supervised Contrastive Learning
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
app_file: app.py
|
8 |
pinned: false
|
@@ -12,7 +12,7 @@ license: apache-2.0
|
|
12 |
# Configuration
|
13 |
|
14 |
`title`: _string_
|
15 |
-
|
16 |
|
17 |
`emoji`: _string_
|
18 |
Space emoji (emoji-only character allowed)
|
|
|
1 |
---
|
2 |
title: Supervised Contrastive Learning
|
3 |
+
emoji: π¨
|
4 |
colorFrom: yellow
|
5 |
+
colorTo: orange
|
6 |
sdk: gradio
|
7 |
app_file: app.py
|
8 |
pinned: false
|
|
|
12 |
# Configuration
|
13 |
|
14 |
`title`: _string_
|
15 |
+
Supervised Contrastive Learning
|
16 |
|
17 |
`emoji`: _string_
|
18 |
Space emoji (emoji-only character allowed)
|
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from huggingface_hub import from_pretrained_keras
|
4 |
+
|
5 |
+
model = from_pretrained_keras("keras-io/supervised-contrastive-learning-cifar10")
|
6 |
+
|
7 |
+
labels = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]
|
8 |
+
|
9 |
+
|
10 |
+
def infer(test_image):
|
11 |
+
image = tf.constant(test_image)
|
12 |
+
image = tf.reshape(image, [-1, 32, 32, 3])
|
13 |
+
pred = model.predict(image)
|
14 |
+
pred_list = pred[0, :]
|
15 |
+
return {labels[i]: float(pred_list[i]) for i in range(10)}
|
16 |
+
|
17 |
+
|
18 |
+
image = gr.inputs.Image(shape=(32, 32))
|
19 |
+
label = gr.outputs.Label(num_top_classes=3)
|
20 |
+
|
21 |
+
|
22 |
+
article = """<center>
|
23 |
+
Authors: <a href='https://twitter.com/johko990' target='_blank'>Johannes Kolbe</a> after an example by Khalid Salama at
|
24 |
+
<a href='https://keras.io/examples/vision/supervised-contrastive-learning/' target='_blank'>keras.io</a> <br>
|
25 |
+
<a href='https://arxiv.org/abs/2004.11362' target='_blank'>Original paper</a> by Prannay Khosla et al."""
|
26 |
+
|
27 |
+
|
28 |
+
description = """Classification with a model trained via Supervised Contrastive Learning """
|
29 |
+
|
30 |
+
|
31 |
+
Iface = gr.Interface(
|
32 |
+
fn=infer,
|
33 |
+
inputs=image,
|
34 |
+
outputs=label,
|
35 |
+
examples=[["examples/cat.jpg"], ["examples/ship.jpeg"]],
|
36 |
+
title="Supervised Contrastive Learning Classification",
|
37 |
+
article=article,
|
38 |
+
description=description,
|
39 |
+
).launch()
|
examples/cat.jpg
ADDED
examples/ship.jpeg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow >=2.6.0
|
2 |
+
gradio
|
3 |
+
huggingface_hub
|