cinemarob1 commited on
Commit
4610222
1 Parent(s): dee3078

Add images and everything except model

Files changed (6) hide show
  1. 1.jpg +0 -0
  2. 2.jpg +0 -0
  3. 3.jpg +0 -0
  4. app.py +56 -0
  5. packages.txt +1 -0
  6. requirements.txt +5 -0
1.jpg ADDED
2.jpg ADDED
3.jpg ADDED
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gradio.outputs import Label
2
+ from icevision.all import *
3
+ from icevision.models.checkpoint import *
4
+ import PIL
5
+ import gradio as gr
6
+ import os
7
+
8
+ detection_threshold = 0.7
9
+ checkpoint_path = "2022-10-03_resnet_slates_147.pth"
10
+ description = (
11
+ "A faster-rcnn model that detects film slates / clappers. "
12
+ "Upload an image or click an example below."
13
+ )
14
+
15
+ # Load model
16
+ checkpoint_and_model = model_from_checkpoint(checkpoint_path)
17
+ model = checkpoint_and_model["model"]
18
+ model_type = checkpoint_and_model["model_type"]
19
+ class_map = checkpoint_and_model["class_map"]
20
+
21
+ # Transforms
22
+ img_size = checkpoint_and_model["img_size"]
23
+ valid_tfms = tfms.A.Adapter(
24
+ [*tfms.A.resize_and_pad(img_size), tfms.A.Normalize()]
25
+ )
26
+
27
+ # Populate examples in Gradio interface
28
+ examples = [["1.jpg"], ["2.jpg"], ["3.jpg"]]
29
+
30
+
31
+ def show_preds(input_image):
32
+ img = PIL.Image.fromarray(input_image, "RGB")
33
+ pred_dict = model_type.end2end_detect(
34
+ img,
35
+ valid_tfms,
36
+ model,
37
+ class_map=class_map,
38
+ detection_threshold=detection_threshold,
39
+ display_label=False,
40
+ display_bbox=True,
41
+ return_img=True,
42
+ font_size=16,
43
+ label_color="#FF59D6",
44
+ )
45
+ return pred_dict["img"]
46
+
47
+
48
+ gr_interface = gr.Interface(
49
+ fn=show_preds,
50
+ inputs=["image"],
51
+ outputs=[gr.outputs.Image(type="pil", label="Inference")],
52
+ title="Film Slate Detector",
53
+ description=description,
54
+ examples=examples,
55
+ )
56
+ gr_interface.launch(inline=False, share=False, debug=True)
packages.txt ADDED
@@ -0,0 +1 @@
 
1
+ python3-opencv
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ --find-links https://download.openmmlab.com/mmcv/dist/cpu/torch1.10.0/index.html
2
+ mmcv-full==1.3.17
3
+ mmdet==2.17.0
4
+ gradio==2.7.5
5
+ icevision[all]==0.12.0