ThRi commited on
Commit
1250ac1
·
1 Parent(s): 154d7a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -6
app.py CHANGED
@@ -1,8 +1,67 @@
1
- import os
2
- import sys
 
 
 
 
 
 
 
3
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- def greet(name):
6
- return "Hello " + name + "!!" + sys.version
7
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
8
- iface.launch()
 
1
+ os.system("pip install torch torchvision")
2
+ os.system("git clone https://github.com/IDEA-Research/detrex.git")
3
+ os.system("python3.10.13 -m pip install git+https://github.com/facebookresearch/detectron2.git@v0.6#egg=detectron2")
4
+ os.system("python3.10.13 -m pip install git+https://github.com/IDEA-Research/detrex.git@v0.5.0#egg=detrex")
5
+ os.system("git submodule sync")
6
+ os.system("git submodule update --init")
7
+ os.system("pip install Pillow==9.5.0")
8
+ os.system("pip install fairscale")
9
+
10
  import gradio as gr
11
+ from tqdm.notebook import tqdm as notebook_tqdm
12
+ from detectron2.config import LazyConfig, instantiate
13
+ from detectron2.checkpoint import DetectionCheckpointer
14
+ from demo.demo import VisualizationDemo, get_parser
15
+ import numpy as np
16
+ from detectron2.data.detection_utils import read_image
17
+ import matplotlib.pyplot as plt
18
+ import cv2
19
+
20
+ import warnings
21
+ warnings.filterwarnings("ignore")
22
+
23
+ config_file = './utils/odor3_fn_l_lrf_384_fl4_5scale_50ep.py'
24
+ ckpt_pth = './utils/focaldino_ep18.pth'
25
+
26
+ try:
27
+ cfg = LazyConfig.load(config_file)
28
+ except AssertionError as e:
29
+ if str(e).startswith('Dataset '):
30
+ pass
31
+ else:
32
+ raise e
33
+ model = instantiate(cfg.model)
34
+ model.to(cfg.train.device)
35
+ checkpointer = DetectionCheckpointer(model)
36
+ checkpointer.load(ckpt_pth)
37
+ model.eval()
38
+ demo = VisualizationDemo(
39
+ model=model,
40
+ min_size_test=800,
41
+ max_size_test=1333,
42
+ img_format='RGB',
43
+ metadata_dataset='odor_test')
44
+
45
+ def treat_grayscale(img):
46
+ if len(img.shape) == 2:
47
+ return np.stack((img,)*3, axis=-1)
48
+ else:
49
+ return img
50
+
51
+ #link = 'https://upload.wikimedia.org/wikipedia/commons/6/62/Gaspar_Peeter_Verbruggen_d.%C3%86._-_Blomsterkrans_med_Johannes_D%C3%B8beren_-_KMSsp332_-_Statens_Museum_for_Kunst.jpg'
52
+ #link = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Josefa_d%27ayala_%28detta_di_%C3%B3bidos%29%2C_natura_morta_con_cocomero_e_pere%2C_1670_ca.jpg/800px-Josefa_d%27ayala_%28detta_di_%C3%B3bidos%29%2C_natura_morta_con_cocomero_e_pere%2C_1670_ca.jpg'
53
+ link = 'https://puam-loris.aws.princeton.edu/loris/INV33883.jp2/full/full/0/default.jpg'
54
+
55
+ img = read_image(link)
56
+ print(img.shape)
57
+ img = treat_grayscale(img)
58
+ print(img.shape)
59
+ predictions, visualized_output = demo.run_on_image(img, 0.05)
60
+ print(predictions)
61
+ plt.figure(figsize=(20,20))
62
+ plt.imshow(visualized_output.get_image()[:,:,::-1])
63
 
64
+ #def greet(name):
65
+ # return "Hello " + name + "!!"
66
+ #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
67
+ #iface.launch()