Johannes Kolbe commited on
Commit
bfb7033
·
1 Parent(s): e7adc27

add running code

Browse files
README copy.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Semi-Supervised Contrastive Learning with SimCLR
3
+ emoji: 👨‍🏫
4
+ colorFrom: red
5
+ colorTo: green
6
+ sdk: gradio
7
+ app_file: app.py
8
+ pinned: false
9
+ license: apache-2.0
10
+ ---
11
+
12
+ # Configuration
13
+
14
+ `title`: _string_
15
+ Supervised Contrastive Learning
16
+
17
+ `emoji`: _string_
18
+ Space emoji (emoji-only character allowed)
19
+
20
+ `colorFrom`: _string_
21
+ Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
22
+
23
+ `colorTo`: _string_
24
+ Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
25
+
26
+ `sdk`: _string_
27
+ Can be either `gradio`, `streamlit`, or `static`
28
+
29
+ `sdk_version` : _string_
30
+ Only applicable for `streamlit` SDK.
31
+ See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
32
+
33
+ `app_file`: _string_
34
+ Path to your main application file (which contains either `gradio` or `streamlit` Python code, or `static` html code).
35
+ Path is relative to the root of the repository.
36
+
37
+ `models`: _List[string]_
38
+ HF model IDs (like "gpt2" or "deepset/roberta-base-squad2") used in the Space.
39
+ Will be parsed automatically from your code if not specified here.
40
+
41
+ `datasets`: _List[string]_
42
+ HF dataset IDs (like "common_voice" or "oscar-corpus/OSCAR-2109") used in the Space.
43
+ Will be parsed automatically from your code if not specified here.
44
+
45
+ `pinned`: _boolean_
46
+ Whether the Space stays on top of your list.
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from huggingface_hub import from_pretrained_keras
4
+ import numpy as np
5
+
6
+ model = from_pretrained_keras("keras-io/semi-supervised-classification-simclr")
7
+
8
+ labels = ["airplane", "bird", "car", "cat", "deer", "dog", "horse", "monkey", "ship", "truck"]
9
+
10
+
11
+ def infer(test_image):
12
+ image = tf.constant(test_image)
13
+ image = tf.reshape(image, [-1, 96, 96, 3])
14
+ pred = model.predict(image)
15
+ pred_list = pred[0, :]
16
+ pred_softmax = np.exp(pred_list)/np.sum(np.exp(pred_list))
17
+ softmax_list = pred_softmax.tolist()
18
+ return {labels[i]: softmax_list[i] for i in range(10)}
19
+
20
+
21
+ image = gr.inputs.Image(shape=(96, 96))
22
+ label = gr.outputs.Label(num_top_classes=3)
23
+
24
+
25
+ article = """<center>
26
+ Authors: <a href='https://twitter.com/johko990' target='_blank'>Johannes Kolbe</a> after an example by András Béres at
27
+ <a href='https://keras.io/examples/vision/semisupervised_simclr/' target='_blank'>keras.io</a>"""
28
+
29
+
30
+ description = """Image classification with a model trained via Semi-supervised Contrastive Learning """
31
+
32
+
33
+ Iface = gr.Interface(
34
+ fn=infer,
35
+ inputs=image,
36
+ outputs=label,
37
+ examples=[["examples/monkey.jpeg"], ["examples/titanic.jpg"], ["examples/truck.jpg"]],
38
+ title="Semi-Supervised Contrastive Learning Classification",
39
+ article=article,
40
+ description=description,
41
+ ).launch()
examples/monkey.jpeg ADDED
examples/titanic.jpg ADDED
examples/truck.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow >=2.6.0
2
+ gradio
3
+ huggingface_hub
4
+ jinja2