gauthamk commited on
Commit
56b9061
1 Parent(s): 598fffb
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ *.pth
2
+ flagged
3
+ __pycache__
README.md CHANGED
@@ -7,6 +7,4 @@ sdk: gradio
7
  sdk_version: 3.23.0
8
  app_file: app.py
9
  pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
7
  sdk_version: 3.23.0
8
  app_file: app.py
9
  pinned: false
10
+ ---
 
 
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from functions import *
4
+
5
+ examples_dir = 'examples'
6
+ title = "CvT: Substructure Prediction"
7
+
8
+ examples = []
9
+ for root, dirs, files in os.walk(examples_dir):
10
+ for file in files:
11
+ if file.endswith(".jpg"):
12
+ examples.append([os.path.join(root, file), os.path.join(root, file)])
13
+
14
+ interface = gr.Interface(fn=predict, inputs=gr.Image(type= 'pil', shape=(256, 256), image_mode= 'L'),
15
+ outputs= gr.Label(num_top_classes=2), cache_examples= False,
16
+ examples= examples, title= title, css= '.gr-box {background-color: rgb(230 230 230);}')
17
+
18
+ interface.launch()
examples/no_sub/image_113100812705960939083539114742377658.jpg ADDED
examples/no_sub/image_200533611763828138246415366213930791.jpg ADDED
examples/no_sub/image_303474718164016996691673988260974055.jpg ADDED
examples/no_sub/image_92238821981785317465591207428674334.jpg ADDED
examples/sub/image_17503960508484307014646191947110028.jpg ADDED
examples/sub/image_1758439101523665464372407954393797.jpg ADDED
examples/sub/image_189448974206662542797032450204033033.jpg ADDED
examples/sub/image_256325939571492478660412119490914543.jpg ADDED
functions.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2
3
+ import onnxruntime as rt
4
+ from PIL import Image
5
+
6
+ onnx_path = 'model/model.onnx'
7
+
8
+ def predict(img):
9
+ session = rt.InferenceSession(onnx_path)
10
+ input_name = session.get_inputs()[0].name
11
+ output_name = session.get_outputs()[0].name
12
+
13
+ img = np.array(img).astype(np.float32)
14
+ img = img.reshape(1, 1, 256, 256)
15
+ img = img / 255.0
16
+ pred = session.run([output_name], {input_name: img})[0]
17
+ pred = np.exp(pred) / np.sum(np.exp(pred), axis=1, keepdims=True)
18
+
19
+ class_probs = {'No Substructure': str(pred[0][0]), 'Substructure': str(pred[0][1])}
20
+ return class_probs
model/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf0384da75ea8db84808deef7fc139c1648569baa7db78105f870b63498692ea
3
+ size 93167130
notebooks/onnx-testing.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
notebooks/test-5-cvt.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
notebooks/torch-to-onnx.ipynb ADDED
The diff for this file is too large to render. See raw diff