ariG23498 commited on
Commit
547271a
1 Parent(s): 7a44a44

add: app and examples

Browse files
Files changed (4) hide show
  1. app.py +44 -0
  2. examples/dalai_lama.jpeg +0 -0
  3. examples/lama.jpeg +0 -0
  4. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_keras
2
+ import tensorflow as tf
3
+ import gradio as gr
4
+
5
+ # download the model in the global context
6
+ vis_model = from_pretrained_keras("ariG23498/involution")
7
+
8
+ def infer(test_image):
9
+ # convert the image to a tensorflow tensor and resize the image
10
+ # to a constant 32x32
11
+ image = tf.constant(test_image)
12
+ image = tf.image.resize(image, (32, 32))
13
+
14
+ # Use the model and get the activation maps
15
+ (inv1_out, inv2_out, inv3_out) = vis_model.predict(image[None, ...])
16
+ _, inv1_kernel = inv1_out
17
+ _, inv2_kernel = inv2_out
18
+ _, inv3_kernel = inv3_out
19
+
20
+ inv1_kernel = tf.reduce_sum(inv1_kernel, axis=[-1, -2, -3])
21
+ inv2_kernel = tf.reduce_sum(inv2_kernel, axis=[-1, -2, -3])
22
+ inv3_kernel = tf.reduce_sum(inv3_kernel, axis=[-1, -2, -3])
23
+
24
+ return (
25
+ inv1_kernel[0, ..., None],
26
+ inv2_kernel[0, ..., None],
27
+ inv3_kernel[0, ..., None]
28
+ )
29
+
30
+ iface = gr.Interface(
31
+ fn=infer,
32
+ title = "Involutional Neural Networks",
33
+ description =
34
+ """Authors: [Aritra Roy Gosthipaty](https://twitter.com/ariG23498) and [Ritwik Raha](https://twitter.com/ritwik_raha)
35
+ Paper: [Involution: Inverting the Inherence of Convolution for Visual Recognition](https://arxiv.org/abs/2103.06255)
36
+ """,
37
+ inputs=gr.inputs.Image(label="Input Image"),
38
+ outputs=[
39
+ gr.outputs.Image(label="Activation from Kernel 1"),
40
+ gr.outputs.Image(label="Activation from Kernel 2"),
41
+ gr.outputs.Image(label="Activation from Kernel 3"),
42
+ ],
43
+ examples=[["examples/llama.jpeg"], ["examples/dalai-lamao.jpeg"]],
44
+ ).launch()
examples/dalai_lama.jpeg ADDED
examples/lama.jpeg ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tensorflow>2.6